SOLR-12805: Store previous term (generation) of replica when start recovery process

This commit is contained in:
Cao Manh Dat 2018-09-26 10:35:44 +07:00
parent 58167666c3
commit 667b8299e6
3 changed files with 17 additions and 7 deletions

View File

@ -71,6 +71,8 @@ Other Changes
java.time.DateTimeFormatter instead of Joda time (see upgrade notes). "Lenient" is enabled. Removed Joda Time dependency.
(David Smiley, Bar Rotstein)
* SOLR-12805: Store previous term (generation) of replica when start recovery process (Cao Manh Dat)
================== 7.6.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -588,12 +588,16 @@ public class ZkShardTerms implements AutoCloseable{
*/
Terms startRecovering(String coreNodeName) {
long maxTerm = getMaxTerm();
if (values.get(coreNodeName) == maxTerm && values.getOrDefault(coreNodeName+"_recovering", -1L) == maxTerm)
if (values.get(coreNodeName) == maxTerm)
return null;
HashMap<String, Long> newValues = new HashMap<>(values);
if (!newValues.containsKey(coreNodeName+"_recovering")) {
long currentTerm = newValues.getOrDefault(coreNodeName, 0L);
// by keeping old term, we will have more information in leader election
newValues.put(coreNodeName+"_recovering", currentTerm);
}
newValues.put(coreNodeName, maxTerm);
newValues.put(coreNodeName+"_recovering", maxTerm);
return new Terms(newValues, version);
}

View File

@ -83,16 +83,19 @@ public class ZkShardTermsTest extends SolrCloudTestCase {
// List all possible orders of ensureTermIsHigher, startRecovering, doneRecovering
zkShardTerms.registerTerm("replica1");
zkShardTerms.registerTerm("replica2");
// normal case when leader start lir process
zkShardTerms.ensureTermsIsHigher("replica1", Collections.singleton("replica2"));
zkShardTerms.startRecovering("replica2");
assertEquals(zkShardTerms.getTerm("replica2"), 1);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), 1);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), 0);
zkShardTerms.doneRecovering("replica2");
assertEquals(zkShardTerms.getTerm("replica1"), 1);
assertEquals(zkShardTerms.getTerm("replica2"), 1);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), -1);
// stack of lir processes
zkShardTerms.ensureTermsIsHigher("replica1", Collections.singleton("replica2"));
assertEquals(zkShardTerms.getTerm("replica1"), 2);
assertEquals(zkShardTerms.getTerm("replica2"), 1);
@ -100,16 +103,17 @@ public class ZkShardTermsTest extends SolrCloudTestCase {
zkShardTerms.startRecovering("replica2");
assertEquals(zkShardTerms.getTerm("replica2"), 2);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), 2);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), 1);
zkShardTerms.ensureTermsIsHigher("replica1", Collections.singleton("replica2"));
assertEquals(zkShardTerms.getTerm("replica1"), 3);
assertEquals(zkShardTerms.getTerm("replica2"), 2);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), 2);
zkShardTerms.doneRecovering("replica2");
assertEquals(zkShardTerms.getTerm("replica2_recovering"), 1);
zkShardTerms.doneRecovering("replica2");
assertEquals(zkShardTerms.getTerm("replica2"), 2);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), -1);
zkShardTerms.startRecovering("replica2");
zkShardTerms.doneRecovering("replica2");
@ -119,7 +123,7 @@ public class ZkShardTermsTest extends SolrCloudTestCase {
zkShardTerms.startRecovering("replica2");
assertEquals(zkShardTerms.getTerm("replica1"), 5);
assertEquals(zkShardTerms.getTerm("replica2"), 5);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), 5);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), 3);
zkShardTerms.doneRecovering("replica2");
assertEquals(zkShardTerms.getTerm("replica2_recovering"), -1);