Region Merge Mto1Solution
I find a solution to simplify merge implement for raftstore, and extend the ability by merging M regions to 1 region. I present the solution, waiting for feedbacks, to see if the solution is valid.
Merge region A…regionM to region X, including peerA…peerM to peerX, peerA1…peerM1 to peerX1.
(1) peerA.kv_function = false.
(2) peerB.kv_function = false.
(m) peerM.kv_function = false.
(m+1) if (!peerA.kv_function and … !peerM.kv_function) peerX.kv_function = true.
Pre-conditions：peerA open, … peerM open, peerX closed for kv functions.
Post-conditions: peerA closed, … peerM closed, peerX open for kv functions.
(1) client: Create region X for the union of region A…M. Align region A…M and X on nodes. Region X creates peerX, peerX1, kv_function closed, raft_function open, configued to merge region A…M.
(2) client: On A, propose raft function prepare_merging(X).
(3) On peerA, prepare_merging: self.kv_function = false. Call peerX.merge(A).
(4) On peerX, merge: prepared (peerA)=true. if ( prepared (peerA) and … prepared (peerM) ) self.kv_function = true.
(5) client: On M, propose raft function prepare_merging(X).
(6) On peerM, prepare_merging: self.kv_function = false. Call peerX.merge(M).
(7) On peerX, merge: prepared (peerM)=true. if ( prepared (peerA) and … prepared (peerM) ) self.kv_function = true.
(8) client: Wait for peerX open, then remove peerA…peerM.
At step (1), repeat this step to provide pre-conditions for merging when something wrong happens.
At step (2) and (5), client propose raft commands to region A…M. Repeat these steps when something wrong happens.
At step (3) and (6), peerA…peerM apply raft commands, closing self.kv_function, calling peerX.merge directly promising the model concept that peerX.kv_function must be open after peerA…peerM.kv_function are closed.