跳到主內容

MongoDB教育訓練-20211223-02

  • 資料先寫入記憶體 ,
  • checkpoint => 一分鐘( or 資料到達大小) 髒數據寫入DB
  • journal log 60ms 寫入 db
  • db 最多錯失60 ms 資料
  • "OK - committed" => 寫到哪裡? write concerns 決定
  • 資料遺失的時候?我會知曉?
  • knowingly log => 已知的寫入失敗
  • unknowingly log => 未知的寫入失敗

 

image-1640237795605.png

 

 

image-1640238366642.png

image-1640238415549.png

image-1640238497608.png

 

當資訊不同步,server 必須 rollback 確保資訊一致 => { x: 100} (移除)

image-1640238562747.png

image-1640238622753.png

The case for Majority writes

in the previeous scenario:

date is writtten to the primary

primary acknowledges write to application

primary dies before secondary reads data

必須所以資料到達大多數節點(majoruty commit point),才能稱之為持久化image-1640238761360.png

 

image-1640238911776.png

寫的關注度Write Concern

  • OK, commitresd 意義
  • (w: 到達多少個節點)(j: 如何才算寫成功  0:記憶體, 1:硬碟)
  • w:0 不推薦
  • w:1, j:1 
  • w: "majority" (j: 1)
  • w:3 無意義(假設叢集有3節點,萬一1節點丟失,無法滿足)

image-1640239010111.png

var wc = { w: 0 }
totalrecs = 10000
batchsize = 1
nbatches = totalrecs / batchsize
var start = new Date()
for(x=0;x<nbatches;x++) {
	recs = []
	for(y=0;y<batchsize;y++) {recs.push({a:1,b:"hello"})}
	db.test.insertMany(recs,{writeConcern: wc})
}

var end=new Date()
print(`${end-start} milliseconds`)

image-1640239636788.png

讀的關注度 Read Concerns 

RDBS 隔離等級概念

Read local 主節點損毀才是髒讀

Read majority 讀舊一點的資料 

Read snapshot : 

Read Linearizable: 讀取時會確認資料是否到達大多數節點

image-1640240583240.png

image-1640239853753.png

 

讀取資料會從哪個節點讀?

  • Read from nearest Geographically (從最近的節點 ping 值,最小的)
  • Read from a specific set of servers (設定標記好的 tag server )

image-1640240657381.png

 

非必要不使用

image-1640240968077.png

image-1640241039739.png