Skip to content

Commit f5831ac

Browse files
committed
Address flakiness of testRemoteCleanupDeleteStale
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
1 parent 2e13e9c commit f5831ac

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteClusterStateCleanupManagerIT.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public void testRemoteCleanupDeleteStale() throws Exception {
108108
.add("cluster-state")
109109
.add(getClusterState().metadata().clusterUUID());
110110
BlobPath manifestContainerPath = baseMetadataPath.add("manifest");
111+
RemoteClusterStateCleanupManager remoteClusterStateCleanupManager = internalCluster().getClusterManagerNodeInstance(
112+
RemoteClusterStateCleanupManager.class
113+
);
111114

112115
// set cleanup interval to 100 ms to make the test faster
113116
ClusterUpdateSettingsResponse response = client().admin()
@@ -117,6 +120,7 @@ public void testRemoteCleanupDeleteStale() throws Exception {
117120
.get();
118121

119122
assertTrue(response.isAcknowledged());
123+
assertBusy(() -> assertEquals(100, remoteClusterStateCleanupManager.getStaleFileDeletionTask().getInterval().getMillis()));
120124

121125
assertBusy(() -> {
122126
int manifestFiles = repository.blobStore().blobContainer(manifestContainerPath).listBlobsByPrefix("manifest").size();
@@ -128,7 +132,7 @@ public void testRemoteCleanupDeleteStale() throws Exception {
128132
"Current number of manifest files: " + manifestFiles,
129133
manifestFiles >= RETAINED_MANIFESTS && manifestFiles < RETAINED_MANIFESTS + 2 * SKIP_CLEANUP_STATE_CHANGES
130134
);
131-
}, 500, TimeUnit.MILLISECONDS);
135+
});
132136

133137
// disable the clean up to avoid race condition during shutdown
134138
response = client().admin()

server/src/main/java/org/opensearch/gateway/remote/model/RemoteClusterMetadataManifest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,18 @@ public ClusterMetadataManifest deserialize(final InputStream inputStream) throws
131131
return blobStoreFormat.deserialize(blobName, getNamedXContentRegistry(), Streams.readFully(inputStream));
132132
}
133133

134-
private int getManifestCodecVersion() {
134+
// package private for testing
135+
int getManifestCodecVersion() {
135136
assert blobName != null;
136-
String[] splitName = blobName.split(DELIMITER);
137+
String[] pathTokens = getBlobPathTokens();
138+
String[] splitName = pathTokens[pathTokens.length - 1].split(DELIMITER);
137139
if (splitName.length == SPLITTED_MANIFEST_FILE_LENGTH) {
138140
return Integer.parseInt(splitName[splitName.length - 1]); // Last value would be codec version.
139141
} else if (splitName.length < SPLITTED_MANIFEST_FILE_LENGTH) { // Where codec is not part of file name, i.e. default codec version 0
140142
// is used.
141143
return ClusterMetadataManifest.CODEC_V0;
142144
} else {
143-
throw new IllegalArgumentException("Manifest file name is corrupted");
145+
throw new IllegalArgumentException("Manifest file name is corrupted : " + blobName);
144146
}
145147
}
146148

server/src/test/java/org/opensearch/gateway/remote/model/RemoteClusterMetadataManifestTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import java.util.stream.Stream;
4242

4343
import static java.util.stream.Collectors.toList;
44+
import static org.opensearch.gateway.remote.ClusterMetadataManifest.CODEC_V0;
45+
import static org.opensearch.gateway.remote.ClusterMetadataManifest.CODEC_V2;
4446
import static org.opensearch.gateway.remote.model.RemoteClusterMetadataManifest.MANIFEST;
4547
import static org.opensearch.gateway.remote.model.RemoteClusterMetadataManifest.MANIFEST_CURRENT_CODEC_VERSION;
4648
import static org.hamcrest.Matchers.greaterThan;
@@ -236,6 +238,28 @@ public void testSerDe() throws IOException {
236238
assertThrows(IllegalArgumentException.class, () -> invalidRemoteObject.deserialize(new ByteArrayInputStream(new byte[0])));
237239
}
238240

241+
public void testGetManifestCodecVersion() {
242+
String manifestFileWithDelimiterInPath =
243+
"123456789012_test-cluster/cluster-state/dsgYj10__Nkso7/manifest/manifest__9223372036854775806__9223372036854775804__C__9223370319103329556__2";
244+
RemoteClusterMetadataManifest remoteManifestForDownload = new RemoteClusterMetadataManifest(
245+
manifestFileWithDelimiterInPath,
246+
clusterUUID,
247+
compressor,
248+
namedXContentRegistry
249+
);
250+
assertEquals(CODEC_V2, remoteManifestForDownload.getManifestCodecVersion());
251+
252+
String v0ManifestFileWithDelimiterInPath =
253+
"123456789012_test-cluster/cluster-state/dsgYj10__Nkso7/manifest/manifest__9223372036854775806__9223372036854775804__C__9223370319103329556";
254+
RemoteClusterMetadataManifest remoteManifestV0ForDownload = new RemoteClusterMetadataManifest(
255+
v0ManifestFileWithDelimiterInPath,
256+
clusterUUID,
257+
compressor,
258+
namedXContentRegistry
259+
);
260+
assertEquals(CODEC_V0, remoteManifestV0ForDownload.getManifestCodecVersion());
261+
}
262+
239263
private ClusterMetadataManifest getClusterMetadataManifest() {
240264
return ClusterMetadataManifest.builder()
241265
.opensearchVersion(Version.CURRENT)

0 commit comments

Comments
 (0)