1、 4- 5.5 6 21 L 4 3 1 ?Error!503: Service Unavailable()Error!503: Service Unavailable()Error!503: Service Unavailable (Core)(Read Replica) () Raft/Core Bolt/Read Replica bookmarkRaft Raft https:/ y3 x4 zxLogLogx1 y3 x4 zxx1 y3 x4 zx (Byzantine)Raft 1. /Leader: (Leader) (Follower)2. Leader Leader3. Le
2、aderRaft : Leader : Leader : (Term) Leader: Leader : LeaderFollowerdiscoverhighertermnoheartbeat RequestVote RPCsLeaderCandidatewinelection AppendEntries RPCs: Leader/TermsTerm 1 Term 2Term 3Term 4Term 5 Leader Leader() () RPC Follower RPC? Raft - LeaderS1: 1S2: 1S3: 1LeaderFollowerCandidateRaft - L
3、eader()S1: 1S2: 1S3: 1T,2TTRaft - Leader()RequestVoteRequestS1: 1S2: 1S3: 1S1RequestVoteRequest RPCRaft - Leader() RequestVoteResposeS1: 1S2: 1S3: 1Raft - Leader()LeadercurrentTerm+, RequestVote RPCsLeaderRPCLeaderFollowerRaft S L 3 SL L2112a22b32cS1: 1 2S2: 1S3: 1Raft () S L 3 SL L2112a22b32c42d52e
4、62fS1: 2S2: 2S3: 212a22b12aRaft - () Leader Leader Leader AppendEntries RPCsFollower : Leader LeaderAppendEntries RPCsFollower Followers Followers? LeaderAppendEntries RPCs RPCRaft - 123456789101112233333s1s2s3s4s53Leaderx3 q8 j2 xq z5 y1 y3 qj x4 z61112233x3 q8 j2 xq z5 y1 y31112233333x3 q8 j2 xq z
5、5 y1 y3 qj x4 z6Follower11x3 q811122333x3 q8 j2 xq z5 y1 y3 qjRaft 1234567891011122333s1s2s3s4s5x3 q8 j2 xq z5 y1 y3 qj1112233x3 q8 j2 xq z5 y1 y31112233333 Leader x3 q8 j2 xq z5 y1 y3 qj x4Follower11x3 q8111222222x3 q8 j2 xq z5 y3 qj x8 x4Raft LeaderRaft : 123456789101112233333x3 q8 j2 xq z5 y1 y3
6、qj x4 z611122344x3 q8 j2 xq z5 y1 xz y7 Raft - AppendEntries AppendEntries RPCs Follower Leader12341234512345112311231123leader:x3 q8 xq y1x3 q8 xq y1x3 q8 xq y11121111111111follower before:follower after:x3 q8 xqx3 q8 j2 y6 axx3 q8 j2 y6 ax1111111231123x3 q8 j2 y6 y6x3 q8 xq y1x3 q8 xq y1Example #1
7、: successExample #2: mismatchExample #3: successRaft Leader LeaderLeader Leader:Term 4Leader?1 2 3 4 5 6 7 8 9 RequestVote RPCss11 1 1 2 2 3 3 3 1s2 1 1 2 2 3 3 1 1 1 s3 2 2 3 3 3 3 1 1 1s4 2 2 3 3 3 1 1 1 2 2 2 2 2 2s5Leader? () currentTerm LeaderLeader? ()( currentTermLeader? () currentTerm Leader
8、888driversbolt+routing:/database() ()()()Mission Impossible!http:/ need tologin in tocontinueyourpurchase!LoginRegisterYou need tologin in tocontinueyourUsername:Password:purchase!LoginRegisterCreate AccountYou need tologin in tocontinueyourUsername:yufanghuaPassword:purchase!*LoginRegisterCreate Ac
9、countYou need tologin in tocontinueyourUsername:Password:purchase!LoginRegisterLoginUsername:yufanghuaPassword:*LoginNo accountfound!Username:yufanghua!Password:*LoginTry again.Username:yufanghuaPassword:*Login.LoginSuccessfuUsername:yufanghuaPassword:*LoginPurchaseQ?A(Eventual Consistency)App Serve
10、rA0000011111222223333344444555556666677777888889999910DriverCreate Account10App ServerADriverCreate AccountCREATE (:User)000001111122222333334444455555666667777788888999991010App ServerADriverCreate AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 1110App ServerADriverCreate
11、 AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 1110 11App ServerADriverCreate AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 1110 11App ServerADriverCreate AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 1110 11App Serv
12、erADriverCreate AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 111010 1110App Server ADriverCreate AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 111010 1110AppServer B DriverLoginMATCH (:User)App ServerADriverCreate AccountCREATE (:User)00000111
13、11222223333344444555556666677777888889999910 111010 1110AppServer B DriverLoginMATCH (:User)(Bookmark) String() App ServerADriverCreate AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 1110 11App ServerACreateDriverAccountCREATE (:User)000001111122222333334444455555666667777
14、7888889999910 1110 11App ServerADriverCreate AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 111010 1110App ServerADriverCreate AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 111010 1110App ServerBDriverLoginMATCH (:User)App ServerADriverCreate Ac
15、countCREATE (:User)0000011111222223333344444555556666677777888889999910 111010 1110AppServer B DriverLoginMATCH (:User)10AppServer A DriverCreate AccountCREATE (:User)0000011111222223333344444555556666677777888889999910 111010 1110AppServer B DriverLoginMATCH (:User)10 11App ServerADriverCreate Acco
16、untCREATE (:User)0000011111222223333344444555556666677777888889999910 111010 1110App ServerBDriverLoginMATCH (:User)10 11try ( Session session = driver.session( AccessMode.WRITE ) )try ( Transaction tx = session.beginTransaction() )tx.run( CREATE (user:User userId: userId, passwordHash: passwordH as
17、h),parameters( userId , userId , passwordHash , passwordH ash ) ) ;tx.success() ;String bookmark = session.lastBookmark () ;try ( Session session = driver.session( AccessMode.READ ) )try ( Transaction tx = session.beginTransaction( bookmark ) )tx.run( MATCH (user:User userId: userId) RETURN * ,parameters( userId , userId ) ) ;tx.success() ;3.23.13.0