Mongo ghostsync and slaveDelay (Japanease)

50
MongoDB ghost sync & slaveDelay

Transcript of Mongo ghostsync and slaveDelay (Japanease)

Page 1: Mongo ghostsync and slaveDelay (Japanease)

MongoDBghost sync & slaveDelay

Page 2: Mongo ghostsync and slaveDelay (Japanease)

-2 -

こんなログ見たことある?“replica set ghost target no good”

Page 3: Mongo ghostsync and slaveDelay (Japanease)

What is GHOST ?

Page 4: Mongo ghostsync and slaveDelay (Japanease)

-4 -

replica set ghost target no good

Primary

Secondary

Secondary

Sync target

Sync target

Page 5: Mongo ghostsync and slaveDelay (Japanease)

-5 -

replica set ghost target no good

Primary

Secondary

Secondary

Sync fail

Sync target

Page 6: Mongo ghostsync and slaveDelay (Japanease)

-6 -

replica set ghost target no good

Primary

Secondary

Secondary

Sync target

Sync target

Page 7: Mongo ghostsync and slaveDelay (Japanease)

-7 -

replica set ghost target no good

Primary

Secondary

Secondary

Sync target

Sync target

Ghost slave

Ghost target

Page 8: Mongo ghostsync and slaveDelay (Japanease)

NO GOOD ?

Page 9: Mongo ghostsync and slaveDelay (Japanease)

-9 -

replica set ghost target no good

Primary

Secondary

Secondary

Sync target

Sync target

Page 10: Mongo ghostsync and slaveDelay (Japanease)

-10 -

replica set ghost target no good

Primary

Secondary

Secondary

Sync target

Sync fail

Page 11: Mongo ghostsync and slaveDelay (Japanease)

-11 -

replica set ghost target no good

Primary

Secondary

Secondary

Sync target

Sync target

Page 12: Mongo ghostsync and slaveDelay (Japanease)

-12 -

replica set ghost target no good

Primary

Secondary

Secondary

Sync target

Sync target

“replica set ghost target no good”

Page 13: Mongo ghostsync and slaveDelay (Japanease)

NO GOOD !!(2.0.X系 )

Page 14: Mongo ghostsync and slaveDelay (Japanease)

-14 -

replica set ghost target no good

■ Ghost sync● Replica-Setの可用性を向上する為のユニークな機能– ネットワーク部分障害時などに威力を発揮– primary oplog 溢れ対策に一部のsecondaryに巨大なoplogを用意し ピーク時間帯をやり過ごしたり

– 新規secondaryをjoinする際の大量同期に使ったり

● ただ2.0系には循環参照のバグあり!!– 2.2系を使うこと

Page 15: Mongo ghostsync and slaveDelay (Japanease)

Ghost sync on 2.3/2.4

Page 16: Mongo ghostsync and slaveDelay (Japanease)

-16 -

proper ghost sync

Primary

Secondary

Secondary

Sync fail

Sync target

Page 17: Mongo ghostsync and slaveDelay (Japanease)

-17 -

proper ghost sync

Primary

Secondary

Secondary

Sync target

Sync target

Page 18: Mongo ghostsync and slaveDelay (Japanease)

-18 -

proper ghost sync

Primary

Secondary

Secondary

Sync target

Sync target

Ghost slave

Ghost target

Page 19: Mongo ghostsync and slaveDelay (Japanease)

-19 -

proper ghost sync

Primary

Secondary

Secondary

Sync target

Sync target

経路が復旧すれば直ちに同期先が戻る

Page 20: Mongo ghostsync and slaveDelay (Japanease)

-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リスト(拒否リスト)に入っていない

Page 21: Mongo ghostsync and slaveDelay (Japanease)

What is slaveDelay ?

Page 22: Mongo ghostsync and slaveDelay (Japanease)

-22 -

slaveDelay

Primary

SecondaryslaveDelay=60

Secondary

Sync target

Page 23: Mongo ghostsync and slaveDelay (Japanease)

-23 -

slaveDelay

Primary

SecondaryslaveDelay=60

Secondary

A

Inset A

Page 24: Mongo ghostsync and slaveDelay (Japanease)

-24 -

slaveDelay

Primary

SecondaryslaveDelay=60

Secondary

ASync immediately

A

Page 25: Mongo ghostsync and slaveDelay (Japanease)

-25 -

slaveDelay

Primary

SecondaryslaveDelay=60

Secondary

A AB

Inset B

Page 26: Mongo ghostsync and slaveDelay (Japanease)

-26 -

slaveDelay

Primary

SecondaryslaveDelay=60

Secondary

ASync immediately

AB B

Page 27: Mongo ghostsync and slaveDelay (Japanease)

-27 -

slaveDelay

Primary

SecondaryslaveDelay=60

Secondary

A

Sync A after 60 secs from “Insert A”

A

A

B B

Page 28: Mongo ghostsync and slaveDelay (Japanease)

-28 -

slaveDelay

■ Replica-Set コンフィグで指定する● slaveDelay=<seconds> を指定したノードはPRIMARYから 指定秒遅れたコピーを持つ様に動作する。

● priority=0 を同時に指定しなければならない。– これはslaveDelayノードはPRIMARYに成れない事を意味する

● 殆どの場合hidden=true と併用した方が良い。– 大抵、クライアント(アプリ)は最新のデータを読みたいはず。

● slaveDelayはヒューマンエラー対策として有用! 例えば、間違えて“db.dropDatabase()” を発行してしまった場合

通常、全てのsecondary達は直ちにデータファイルを削除してしまう。 よって、データは完全に失われてしまう。 しかしslaveDelayノードでは遅延期間内はまだ消えてない! 急いでslaveDelayノードを落とせ!!(同期を防ぐ)

Page 29: Mongo ghostsync and slaveDelay (Japanease)

Ghost sync & slaveDelay

Page 30: Mongo ghostsync and slaveDelay (Japanease)

-30 -

Ghost sync & slaveDelay

Primary Secondary

Sync target

Sync target

Ghost slave

Ghost target

SecondaryslaveDelay=60

Page 31: Mongo ghostsync and slaveDelay (Japanease)

-31 -

Ghost sync & slaveDelay

Primary

SecondaryslaveDelay=60

Secondary

A

Inset A

Page 32: Mongo ghostsync and slaveDelay (Japanease)

-32 -

Primary

SecondaryslaveDelay=60

Secondary

ASync immediately

A

Ghost sync & slaveDelay

Page 33: Mongo ghostsync and slaveDelay (Japanease)

-33 -

Primary

SecondaryslaveDelay=60

Secondary

A AB

Inset B

Ghost sync & slaveDelay

Page 34: Mongo ghostsync and slaveDelay (Japanease)

-34 -

Primary

SecondaryslaveDelay=60

Secondary

ASync immediately

AB B

Ghost sync & slaveDelay

Page 35: Mongo ghostsync and slaveDelay (Japanease)

-35 -

Primary

SecondaryslaveDelay=60

Secondary

A AB B

Sync A after 60 secs from “Insert A”

A

Ghost sync & slaveDelay

Page 36: Mongo ghostsync and slaveDelay (Japanease)

It's OK !!

Page 37: Mongo ghostsync and slaveDelay (Japanease)

-37 -

Primary Secondary

SecondaryslaveDelay=60

Ghost sync & slaveDelay

Page 38: Mongo ghostsync and slaveDelay (Japanease)

-38 -

Primary

SecondaryslaveDelay=60

Secondary

A

Inset A

Ghost sync & slaveDelay

Page 39: Mongo ghostsync and slaveDelay (Japanease)

-39 -

Primary

SecondaryslaveDelay=60

Secondary

AB

Inset B

Ghost sync & slaveDelay

Page 40: Mongo ghostsync and slaveDelay (Japanease)

-40 -

Primary

SecondaryslaveDelay=60

Secondary

A

Sync A after 60 secs from “Insert A”

A

B A

Sync immediately,but delayed implicitly

Ghost sync & slaveDelay

Page 41: Mongo ghostsync and slaveDelay (Japanease)

No good ...

Page 42: Mongo ghostsync and slaveDelay (Japanease)

-42 -

■ Ghost syncとslaveDelayは相性が悪い

slaveDelay ノードはPRIMARYノードから遅れているので同期元として選ばれるべきでは無い。

slaveOkで動作しているクライアントはPrimaryのデータ更新してもsecondaryからはからは古いデータしか読めない状況になる!!

slaveDelayノードを同期元として選んでしまったノードは、クライアント(アプリ)からリクエストを受けてはならない。( MAINTAINANCE か HIDDENとして扱われるべき)

Ghost sync & slaveDelay

Page 43: Mongo ghostsync and slaveDelay (Japanease)

[slaveDelay with Ghostsync] https://jira.mongodb.org/browse/SERVER-8476

対策よろ。。

Page 44: Mongo ghostsync and slaveDelay (Japanease)

補足.

Page 45: Mongo ghostsync and slaveDelay (Japanease)

-45 -

Primary Secondary

Vote with ghost sync

Secondary SecondarySecondary

Page 46: Mongo ghostsync and slaveDelay (Japanease)

-46 -

Primary Secondary

Vote with ghost sync

Secondary SecondarySecondary

Page 47: Mongo ghostsync and slaveDelay (Japanease)

-47 -

Primary Secondary

Vote with ghost sync

Secondary SecondarySecondary

Page 48: Mongo ghostsync and slaveDelay (Japanease)

-48 -

Primary Secondary

Vote with ghost sync

Secondary SecondarySecondary

Page 49: Mongo ghostsync and slaveDelay (Japanease)

-49 -

PrimarySecondary

Vote with ghost sync

Secondary SecondarySecondary

Page 50: Mongo ghostsync and slaveDelay (Japanease)

-50 -

Primary

Secondary

Vote with ghost sync

Secondary

SecondarySecondary