Skip to content

Commit 1755bf5

Browse files
committed
Address flakiness of testRemoteCleanupDeleteStale
- Make RemoteReadResult have Object rather than ToXContent - Fix getManifestCodecVersion in RemoteClusterMetadataManifest Signed-off-by: Shivansh Arora <hishiv@amazon.com>
1 parent afeddc2 commit 1755bf5

File tree

7 files changed

+50
-15
lines changed

7 files changed

+50
-15
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/RemoteClusterStateAttributesManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.opensearch.common.remote.RemoteWritableEntityStore;
1616
import org.opensearch.core.action.ActionListener;
1717
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
18-
import org.opensearch.core.xcontent.ToXContent;
1918
import org.opensearch.gateway.remote.model.RemoteClusterBlocks;
2019
import org.opensearch.gateway.remote.model.RemoteClusterStateBlobStore;
2120
import org.opensearch.gateway.remote.model.RemoteClusterStateCustoms;
@@ -121,7 +120,7 @@ public CheckedRunnable<IOException> getAsyncMetadataReadAction(
121120
LatchedActionListener<RemoteReadResult> listener
122121
) {
123122
final ActionListener actionListener = ActionListener.wrap(
124-
response -> listener.onResponse(new RemoteReadResult((ToXContent) response, CLUSTER_STATE_ATTRIBUTE, component)),
123+
response -> listener.onResponse(new RemoteReadResult(response, CLUSTER_STATE_ATTRIBUTE, component)),
125124
listener::onFailure
126125
);
127126
return () -> getStore(blobEntity).readAsync(blobEntity, actionListener);

server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public RemoteClusterStateManifestInfo writeIncrementalMetadata(
276276
ClusterState clusterState,
277277
ClusterMetadataManifest previousManifest
278278
) throws IOException {
279-
logger.info("WRITING INCREMENTAL STATE");
279+
logger.trace("WRITING INCREMENTAL STATE");
280280

281281
final long startTimeNanos = relativeTimeNanosSupplier.getAsLong();
282282
if (clusterState.nodes().isLocalNodeElectedClusterManager() == false) {
@@ -766,7 +766,7 @@ private UploadedMetadataResults writeMetadataInParallel(
766766
throw new IllegalStateException("Unknown metadata component name " + name);
767767
}
768768
});
769-
logger.info("response {}", response.uploadedIndicesRoutingMetadata.toString());
769+
logger.trace("response {}", response.uploadedIndicesRoutingMetadata.toString());
770770
return response;
771771
}
772772

server/src/main/java/org/opensearch/gateway/remote/RemoteGlobalMetadataManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
2626
import org.opensearch.core.compress.Compressor;
2727
import org.opensearch.core.xcontent.NamedXContentRegistry;
28-
import org.opensearch.core.xcontent.ToXContent;
2928
import org.opensearch.gateway.remote.model.RemoteClusterStateBlobStore;
3029
import org.opensearch.gateway.remote.model.RemoteCoordinationMetadata;
3130
import org.opensearch.gateway.remote.model.RemoteCustomMetadata;
@@ -194,7 +193,7 @@ CheckedRunnable<IOException> getAsyncMetadataReadAction(
194193
LatchedActionListener<RemoteReadResult> listener
195194
) {
196195
ActionListener actionListener = ActionListener.wrap(
197-
response -> listener.onResponse(new RemoteReadResult((ToXContent) response, readEntity.getType(), componentName)),
196+
response -> listener.onResponse(new RemoteReadResult(response, readEntity.getType(), componentName)),
198197
listener::onFailure
199198
);
200199
return () -> getStore(readEntity).readAsync(readEntity, actionListener);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,17 @@ 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[] splitName = getBlobFileName().split(DELIMITER);
137138
if (splitName.length == SPLITTED_MANIFEST_FILE_LENGTH) {
138139
return Integer.parseInt(splitName[splitName.length - 1]); // Last value would be codec version.
139140
} else if (splitName.length < SPLITTED_MANIFEST_FILE_LENGTH) { // Where codec is not part of file name, i.e. default codec version 0
140141
// is used.
141142
return ClusterMetadataManifest.CODEC_V0;
142143
} else {
143-
throw new IllegalArgumentException("Manifest file name is corrupted");
144+
throw new IllegalArgumentException("Manifest file name is corrupted : " + blobName);
144145
}
145146
}
146147

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,22 @@
88

99
package org.opensearch.gateway.remote.model;
1010

11-
import org.opensearch.core.xcontent.ToXContent;
12-
1311
/**
1412
* Container class for entity read from remote store
1513
*/
1614
public class RemoteReadResult {
1715

18-
ToXContent obj;
16+
Object obj;
1917
String component;
2018
String componentName;
2119

22-
public RemoteReadResult(ToXContent obj, String component, String componentName) {
20+
public RemoteReadResult(Object obj, String component, String componentName) {
2321
this.obj = obj;
2422
this.component = component;
2523
this.componentName = componentName;
2624
}
2725

28-
public ToXContent getObj() {
26+
public Object getObj() {
2927
return obj;
3028
}
3129

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

Lines changed: 34 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;
@@ -191,6 +193,16 @@ public void testGenerateBlobFileName() {
191193
assertThat(nameTokens[3], is("C"));
192194
assertThat(RemoteStoreUtils.invertLong(nameTokens[4]), lessThanOrEqualTo(System.currentTimeMillis()));
193195
assertThat(nameTokens[5], is(String.valueOf(MANIFEST_CURRENT_CODEC_VERSION)));
196+
197+
String blobName = "/usr/local/random/path/to/manifest/manifest__1__2__3__4__2";
198+
RemoteClusterMetadataManifest remoteObjectForDownload = new RemoteClusterMetadataManifest(
199+
blobName,
200+
clusterUUID,
201+
compressor,
202+
namedXContentRegistry
203+
);
204+
assertEquals("manifest__1__2__3__4__2", remoteObjectForDownload.generateBlobFileName());
205+
assertEquals(remoteObjectForDownload.getManifestCodecVersion(), 2);
194206
}
195207

196208
public void testGetUploadedMetadata() throws IOException {
@@ -236,6 +248,28 @@ public void testSerDe() throws IOException {
236248
assertThrows(IllegalArgumentException.class, () -> invalidRemoteObject.deserialize(new ByteArrayInputStream(new byte[0])));
237249
}
238250

251+
public void testGetManifestCodecVersion() {
252+
String manifestFileWithDelimiterInPath =
253+
"123456789012_test-cluster/cluster-state/dsgYj10__Nkso7/manifest/manifest__9223372036854775806__9223372036854775804__C__9223370319103329556__2";
254+
RemoteClusterMetadataManifest remoteManifestForDownload = new RemoteClusterMetadataManifest(
255+
manifestFileWithDelimiterInPath,
256+
clusterUUID,
257+
compressor,
258+
namedXContentRegistry
259+
);
260+
assertEquals(CODEC_V2, remoteManifestForDownload.getManifestCodecVersion());
261+
262+
String v0ManifestFileWithDelimiterInPath =
263+
"123456789012_test-cluster/cluster-state/dsgYj10__Nkso7/manifest/manifest__9223372036854775806__9223372036854775804__C__9223370319103329556";
264+
RemoteClusterMetadataManifest remoteManifestV0ForDownload = new RemoteClusterMetadataManifest(
265+
v0ManifestFileWithDelimiterInPath,
266+
clusterUUID,
267+
compressor,
268+
namedXContentRegistry
269+
);
270+
assertEquals(CODEC_V0, remoteManifestV0ForDownload.getManifestCodecVersion());
271+
}
272+
239273
private ClusterMetadataManifest getClusterMetadataManifest() {
240274
return ClusterMetadataManifest.builder()
241275
.opensearchVersion(Version.CURRENT)

0 commit comments

Comments
 (0)