Skip to content

Commit 5e0030e

Browse files
committed
Adjust BWC for peer recovery retention leases (#50351)
Relates #50351
1 parent 99b3562 commit 5e0030e

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ public void testOperationBasedRecovery() throws Exception {
12781278
}
12791279
}
12801280
flush(index, true);
1281-
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index, false);
1281+
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index);
12821282
// less than 10% of the committed docs (see IndexSetting#FILE_BASED_RECOVERY_THRESHOLD_SETTING).
12831283
int uncommittedDocs = randomIntBetween(0, (int) (committedDocs * 0.1));
12841284
for (int i = 0; i < uncommittedDocs; i++) {
@@ -1288,7 +1288,7 @@ public void testOperationBasedRecovery() throws Exception {
12881288
} else {
12891289
ensureGreen(index);
12901290
assertNoFileBasedRecovery(index, n -> true);
1291-
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index, true);
1291+
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index);
12921292
}
12931293
}
12941294

@@ -1313,7 +1313,7 @@ public void testTurnOffTranslogRetentionAfterUpgraded() throws Exception {
13131313
ensureGreen(index);
13141314
flush(index, true);
13151315
assertEmptyTranslog(index);
1316-
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index, true);
1316+
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index);
13171317
}
13181318
}
13191319
}

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -511,28 +511,6 @@ private static Version indexVersionCreated(final String indexName) throws IOExce
511511
return Version.fromId(Integer.parseInt(ObjectPath.createFromResponse(response).evaluate(versionCreatedSetting)));
512512
}
513513

514-
/**
515-
* Returns the minimum node version among all nodes of the cluster
516-
*/
517-
private static Version minimumNodeVersion() throws IOException {
518-
final Request request = new Request("GET", "_nodes");
519-
request.addParameter("filter_path", "nodes.*.version");
520-
521-
final Response response = client().performRequest(request);
522-
final Map<String, Object> nodes = ObjectPath.createFromResponse(response).evaluate("nodes");
523-
524-
Version minVersion = null;
525-
for (Map.Entry<String, Object> node : nodes.entrySet()) {
526-
@SuppressWarnings("unchecked")
527-
Version nodeVersion = Version.fromString((String) ((Map<String, Object>) node.getValue()).get("version"));
528-
if (minVersion == null || minVersion.after(nodeVersion)) {
529-
minVersion = nodeVersion;
530-
}
531-
}
532-
assertNotNull(minVersion);
533-
return minVersion;
534-
}
535-
536514
/**
537515
* Asserts that an index is closed in the cluster state. If `checkRoutingTable` is true, it also asserts
538516
* that the index has started shards.
@@ -695,7 +673,7 @@ public void testOperationBasedRecovery() throws Exception {
695673
ensureGreen(index);
696674
indexDocs(index, 0, randomIntBetween(100, 200));
697675
flush(index, randomBoolean());
698-
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index, false);
676+
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index);
699677
// uncommitted docs must be less than 10% of committed docs (see IndexSetting#FILE_BASED_RECOVERY_THRESHOLD_SETTING).
700678
indexDocs(index, randomIntBetween(0, 100), randomIntBetween(0, 3));
701679
} else {
@@ -705,9 +683,7 @@ public void testOperationBasedRecovery() throws Exception {
705683
|| nodeName.startsWith(CLUSTER_NAME + "-0")
706684
|| (nodeName.startsWith(CLUSTER_NAME + "-1") && Booleans.parseBoolean(System.getProperty("tests.first_round")) == false));
707685
indexDocs(index, randomIntBetween(0, 100), randomIntBetween(0, 3));
708-
if (CLUSTER_TYPE == ClusterType.UPGRADED) {
709-
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index, true);
710-
}
686+
ensurePeerRecoveryRetentionLeasesRenewedAndSynced(index);
711687
}
712688
}
713689

server/src/main/java/org/elasticsearch/index/seqno/ReplicationTracker.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,10 @@ public ReplicationTracker(
895895
this.pendingInSync = new HashSet<>();
896896
this.routingTable = null;
897897
this.replicationGroup = null;
898-
this.hasAllPeerRecoveryRetentionLeases = indexSettings.getIndexVersionCreated().onOrAfter(Version.V_8_0_0)
898+
this.hasAllPeerRecoveryRetentionLeases = indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_6_0)
899899
|| (indexSettings.isSoftDeleteEnabled() &&
900-
(indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_6_0) ||
901-
(indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_4_0) &&
902-
indexSettings.getIndexMetaData().getState() == IndexMetaData.State.OPEN)));
900+
indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_4_0) &&
901+
indexSettings.getIndexMetaData().getState() == IndexMetaData.State.OPEN);
903902

904903
this.fileBasedRecoveryThreshold = IndexSettings.FILE_BASED_RECOVERY_THRESHOLD_SETTING.get(indexSettings.getSettings());
905904
this.safeCommitInfoSupplier = safeCommitInfoSupplier;

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.elasticsearch.rest.RestStatus;
5757
import org.elasticsearch.snapshots.SnapshotState;
5858
import org.elasticsearch.test.ESTestCase;
59+
import org.elasticsearch.test.rest.yaml.ObjectPath;
5960
import org.hamcrest.Matchers;
6061
import org.junit.After;
6162
import org.junit.AfterClass;
@@ -1132,18 +1133,20 @@ public void assertEmptyTranslog(String index) throws Exception {
11321133
* Peer recovery retention leases are renewed and synced to replicas periodically (every 30 seconds). This ensures
11331134
* that we have renewed every PRRL to the global checkpoint of the corresponding copy and properly synced to all copies.
11341135
*/
1135-
public void ensurePeerRecoveryRetentionLeasesRenewedAndSynced(String index, boolean alwaysExists) throws Exception {
1136+
public void ensurePeerRecoveryRetentionLeasesRenewedAndSynced(String index) throws Exception {
1137+
boolean mustHavePRRLs = minimumNodeVersion().onOrAfter(Version.V_7_6_0);
11361138
assertBusy(() -> {
11371139
Map<String, Object> stats = entityAsMap(client().performRequest(new Request("GET", index + "/_stats?level=shards")));
11381140
@SuppressWarnings("unchecked") Map<String, List<Map<String, ?>>> shards =
11391141
(Map<String, List<Map<String, ?>>>) XContentMapValues.extractValue("indices." + index + ".shards", stats);
11401142
for (List<Map<String, ?>> shard : shards.values()) {
11411143
for (Map<String, ?> copy : shard) {
11421144
Integer globalCheckpoint = (Integer) XContentMapValues.extractValue("seq_no.global_checkpoint", copy);
1145+
assertThat(XContentMapValues.extractValue("seq_no.max_seq_no", copy), equalTo(globalCheckpoint));
11431146
assertNotNull(globalCheckpoint);
11441147
@SuppressWarnings("unchecked") List<Map<String, ?>> retentionLeases =
11451148
(List<Map<String, ?>>) XContentMapValues.extractValue("retention_leases.leases", copy);
1146-
if (alwaysExists == false && retentionLeases == null) {
1149+
if (mustHavePRRLs == false && retentionLeases == null) {
11471150
continue;
11481151
}
11491152
assertNotNull(retentionLeases);
@@ -1152,7 +1155,7 @@ public void ensurePeerRecoveryRetentionLeasesRenewedAndSynced(String index, bool
11521155
assertThat(retentionLease.get("retaining_seq_no"), equalTo(globalCheckpoint + 1));
11531156
}
11541157
}
1155-
if (alwaysExists) {
1158+
if (mustHavePRRLs) {
11561159
List<String> existingLeaseIds = retentionLeases.stream().map(lease -> (String) lease.get("id"))
11571160
.collect(Collectors.toList());
11581161
List<String> expectedLeaseIds = shard.stream()
@@ -1165,4 +1168,26 @@ public void ensurePeerRecoveryRetentionLeasesRenewedAndSynced(String index, bool
11651168
}
11661169
}, 60, TimeUnit.SECONDS);
11671170
}
1171+
1172+
/**
1173+
* Returns the minimum node version among all nodes of the cluster
1174+
*/
1175+
protected static Version minimumNodeVersion() throws IOException {
1176+
final Request request = new Request("GET", "_nodes");
1177+
request.addParameter("filter_path", "nodes.*.version");
1178+
1179+
final Response response = client().performRequest(request);
1180+
final Map<String, Object> nodes = ObjectPath.createFromResponse(response).evaluate("nodes");
1181+
1182+
Version minVersion = null;
1183+
for (Map.Entry<String, Object> node : nodes.entrySet()) {
1184+
@SuppressWarnings("unchecked")
1185+
Version nodeVersion = Version.fromString((String) ((Map<String, Object>) node.getValue()).get("version"));
1186+
if (minVersion == null || minVersion.after(nodeVersion)) {
1187+
minVersion = nodeVersion;
1188+
}
1189+
}
1190+
assertNotNull(minVersion);
1191+
return minVersion;
1192+
}
11681193
}

0 commit comments

Comments
 (0)