Skip to content

Commit de65982

Browse files
authored
Retry on wait_for_metada_version timeout (#38521)
Closes #37807
1 parent c0328d5 commit de65982

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/CcrRequests.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,29 @@ public static void getIndexMetadata(Client client, Index index, long mappingVers
5757
}
5858
client.admin().cluster().state(request, ActionListener.wrap(
5959
response -> {
60-
if (response.getState() == null) {
60+
if (response.getState() == null) { // timeout on wait_for_metadata_version
6161
assert metadataVersion > 0 : metadataVersion;
62-
throw new IllegalStateException("timeout to get cluster state with" +
63-
" metadata version [" + metadataVersion + "], mapping version [" + mappingVersion + "]");
62+
if (timeoutSupplier.get().nanos() < 0) {
63+
listener.onFailure(new IllegalStateException("timeout to get cluster state with" +
64+
" metadata version [" + metadataVersion + "], mapping version [" + mappingVersion + "]"));
65+
} else {
66+
getIndexMetadata(client, index, mappingVersion, metadataVersion, timeoutSupplier, listener);
67+
}
68+
} else {
69+
final MetaData metaData = response.getState().metaData();
70+
final IndexMetaData indexMetaData = metaData.getIndexSafe(index);
71+
if (indexMetaData.getMappingVersion() >= mappingVersion) {
72+
listener.onResponse(indexMetaData);
73+
return;
74+
}
75+
if (timeoutSupplier.get().nanos() < 0) {
76+
listener.onFailure(new IllegalStateException(
77+
"timeout to get cluster state with mapping version [" + mappingVersion + "]"));
78+
} else {
79+
// ask for the next version.
80+
getIndexMetadata(client, index, mappingVersion, metaData.version() + 1, timeoutSupplier, listener);
81+
}
6482
}
65-
final MetaData metaData = response.getState().metaData();
66-
final IndexMetaData indexMetaData = metaData.getIndexSafe(index);
67-
if (indexMetaData.getMappingVersion() >= mappingVersion) {
68-
listener.onResponse(indexMetaData);
69-
return;
70-
}
71-
if (timeoutSupplier.get().nanos() < 0) {
72-
throw new IllegalStateException("timeout to get cluster state with mapping version [" + mappingVersion + "]");
73-
}
74-
// ask for the next version.
75-
getIndexMetadata(client, index, mappingVersion, metaData.version() + 1, timeoutSupplier, listener);
7683
},
7784
listener::onFailure
7885
));

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/FollowerFailOverIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ public void testAddNewReplicasOnFollower() throws Exception {
235235
pauseFollow("follower-index");
236236
}
237237

238-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37807")
239238
public void testReadRequestsReturnLatestMappingVersion() throws Exception {
240239
InternalTestCluster leaderCluster = getLeaderCluster();
241240
Settings nodeAttributes = Settings.builder().put("node.attr.box", "large").build();

0 commit comments

Comments
 (0)