mirror of https://github.com/apache/lucene.git
SOLR-12805: Store previous term (generation) of replica when start recovery process
This commit is contained in:
parent
58167666c3
commit
667b8299e6
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue