Skip to content

Commit

Permalink
Still use joint consensus when only one peer changed (sofastack#482)
Browse files Browse the repository at this point in the history
* still use joint consensus when only one peer changed

* fix ut: readCommittedUserLog
  • Loading branch information
fengjiachun authored Jul 7, 2020
1 parent 11e9406 commit b6338f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,12 @@ void nextStage() {
Requires.requireTrue(isBusy(), "Not in busy stage");
switch (this.stage) {
case STAGE_CATCHING_UP:
if (this.nchanges > 1) {
if (this.nchanges > 0) {
this.stage = Stage.STAGE_JOINT;
this.node.unsafeApplyConfiguration(new Configuration(this.newPeers, this.newLearners),
new Configuration(this.oldPeers), false);
return;
}
// Skip joint consensus since only one peers has been changed here. Make
// it a one-stage change to be compatible with the legacy
// implementation.
case STAGE_JOINT:
this.stage = Stage.STAGE_STABLE;
this.node.unsafeApplyConfiguration(new Configuration(this.newPeers, this.newLearners), null, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2922,16 +2922,16 @@ public void readCommittedUserLog() throws Exception {
assertEquals("User log is deleted at index: 5", e.getMessage());
}

// index == 12 and index == 13 are 2 CONFIGURATION logs, so real_index will be 14 when returned.
// index == 12index == 13、index=14、index=15 are 4 CONFIGURATION logs(joint consensus), so real_index will be 16 when returned.
userLog = leader.readCommittedUserLog(12);
assertNotNull(userLog);
assertEquals(14, userLog.getIndex());
assertEquals(16, userLog.getIndex());
assertEquals("hello10", new String(userLog.getData().array()));

// now index == 15 is a user log
userLog = leader.readCommittedUserLog(15);
// now index == 17 is a user log
userLog = leader.readCommittedUserLog(17);
assertNotNull(userLog);
assertEquals(15, userLog.getIndex());
assertEquals(17, userLog.getIndex());
assertEquals("hello11", new String(userLog.getData().array()));

cluster.ensureSame();
Expand Down

0 comments on commit b6338f5

Please sign in to comment.