跳到主內容

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

  • 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