More Related Content More from Hiroaki Kubota (10) Mongo ghostsync and slaveDelay (Japanease)4. replica set ghost target no good
Sync target
Primary Secondary
Sync target
Secondary
-4 -
5. replica set ghost target no good
Sync target
Primary Secondary
Sync fail
Secondary
-5 -
6. replica set ghost target no good
Sync target
Primary Secondary
Sync target
Secondary
-6 -
7. replica set ghost target no good
Sync target
Primary Secondary
Ghost slave
Sync target
Ghost target
Secondary
-7 -
9. replica set ghost target no good
Sync target
Primary Secondary
Sync target
Secondary
-9 -
10. replica set ghost target no good
Sync fail
Primary Secondary
Sync target
Secondary
-10 -
11. replica set ghost target no good
Primary Secondary
Sync target
Sync target
Secondary
-11 -
12. replica set ghost target no good
Primary Secondary
Sync target
Sync target
“replica set ghost target no good”
Secondary
-12 -
14. replica set ghost target no good
■ Ghost sync
● Replica-Setの可用性を向上する為のユニークな機能
– ネットワーク部分障害時などに威力を発揮
– primary oplog 溢れ対策に一部のsecondaryに巨大なoplogを用意し
ピーク時間帯をやり過ごしたり
– 新規secondaryをjoinする際の大量同期に使ったり
● ただ2.0系には循環参照のバグあり!!
– 2.2系を使うこと
-14 -
18. proper ghost sync
Sync target
Primary Secondary
Ghost slave
Sync target
Ghost target
Secondary
-18 -
19. proper ghost sync
Sync target
Primary Secondary
経路が復旧すれば
Sync target 直ちに同期先が戻る
Secondary
-19 -
20. Ghost sync on 2.3/2.4
■ Sync details
● “settings.chainingAllowed=false” (2.2系以上)の場合
常にPrimaryから同期する
– syncFrom()による指定はchainingAllowedより優先
– syncFrom()の設定は単にonメモリに保存され、クリアできない。(要再起動)
– syncForm()の設定は同期に失敗するとクリアされる。
● PrimaryのopTimeをチェックし
新鮮で近いノードを同期ターゲットとして選択する
– 新鮮:自ノードより新しくPrimaryから30秒以内の鮮度
– 近い:ping の応答時間
– slaveDelayやhiddenではない
– vetoリスト(拒否リスト)に入っていない
-20 -
23. slaveDelay
Inset A
A
Primary Secondary
Secondary
slaveDelay=60
-23 -
24. slaveDelay
Sync immediately
A A
Primary Secondary
Secondary
slaveDelay=60
-24 -
26. slaveDelay
Sync immediately
B A A B
Primary Secondary
Secondary
slaveDelay=60
-26 -
27. slaveDelay
B A A B
Primary Secondary
Sync A after 60 secs from “Insert A”
A
Secondary
slaveDelay=60
-27 -
28. slaveDelay
■ Replica-Set コンフィグで指定する
● slaveDelay=<seconds> を指定したノードはPRIMARYから
指定秒遅れたコピーを持つ様に動作する。
● priority=0 を同時に指定しなければならない。
– これはslaveDelayノードはPRIMARYに成れない事を意味する
● 殆どの場合hidden=true と併用した方が良い。
– 大抵、クライアント(アプリ)は最新のデータを読みたいはず。
● slaveDelayはヒューマンエラー対策として有用!
例えば、間違えて“db.dropDatabase()” を発行してしまった場合
通常、全てのsecondary達は直ちにデータファイルを削除してしまう。
よって、データは完全に失われてしまう。
しかしslaveDelayノードでは遅延期間内はまだ消えてない!
急いでslaveDelayノードを落とせ!!(同期を防ぐ)
-28 -
30. Ghost sync & slaveDelay
Sync target
Primary Secondary
Ghost slave
Sync target
Ghost target
Secondary
slaveDelay=60
-30 -
31. Ghost sync & slaveDelay
Inset A
A
Primary Secondary
Secondary
slaveDelay=60
-31 -
32. Ghost sync & slaveDelay
Sync immediately
A A
Primary Secondary
Secondary
slaveDelay=60
-32 -
33. Ghost sync & slaveDelay
Inset B
B A A
Primary Secondary
Secondary
slaveDelay=60
-33 -
34. Ghost sync & slaveDelay
Sync immediately
B A A B
Primary Secondary
Secondary
slaveDelay=60
-34 -
35. Ghost sync & slaveDelay
B A A B
Primary Secondary
Sync A after 60 secs from “Insert A”
A
Secondary
slaveDelay=60
-35 -
37. Ghost sync & slaveDelay
Primary Secondary
Secondary
slaveDelay=60
-37 -
38. Ghost sync & slaveDelay
Inset A
A
Primary Secondary
Secondary
slaveDelay=60
-38 -
39. Ghost sync & slaveDelay
Inset B
B A
Primary Secondary
Secondary
slaveDelay=60
-39 -
40. Ghost sync & slaveDelay
B A A
Primary Secondary
Sync immediately,
but delayed implicitly
Sync A after 60 secs from “Insert A”
A
Secondary
slaveDelay=60
-40 -
42. Ghost sync & slaveDelay
■ Ghost syncとslaveDelayは相性が悪い
slaveDelay ノードはPRIMARYノードから遅れているので同期元として
選ばれるべきでは無い。
slaveOkで動作しているクライアントはPrimaryのデータ更新しても
secondaryからはからは古いデータしか読めない状況になる!!
slaveDelayノードを同期元として選んでしまったノードは、クライアン
ト(アプリ)からリクエストを受けてはならない。
( MAINTAINANCE か HIDDENとして扱われるべき)
-42 -
45. Vote with ghost sync
Primary Secondary
Secondary Secondary Secondary
-45 -
46. Vote with ghost sync
Primary Secondary
Secondary Secondary Secondary
-46 -
47. Vote with ghost sync
Primary Secondary
Secondary Secondary Secondary
-47 -
48. Vote with ghost sync
Primary Secondary
Secondary Secondary Secondary
-48 -
49. Vote with ghost sync
Secondary Primary
Secondary Secondary Secondary
-49 -
50. Vote with ghost sync
Secondary Secondary
Secondary Primary Secondary
-50 -