Skip to content

Commit

Permalink
Fix remote cluster restore for data stream
Browse files Browse the repository at this point in the history
Signed-off-by: Dhwanil Patel <dhwanip@amazon.com>
  • Loading branch information
dhwanilpatel committed Oct 20, 2023
1 parent 7936f94 commit 084404a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@
import static org.opensearch.test.OpenSearchIntegTestCase.Scope;
import static org.hamcrest.Matchers.is;

@ClusterScope(scope = Scope.TEST, numDataNodes = 2)
@ClusterScope(scope = Scope.TEST, numDataNodes = DataStreamTestCase.DATA_NODE_COUNT)
public class DataStreamTestCase extends OpenSearchIntegTestCase {

protected static final int DATA_NODE_COUNT = 2;

private void resetCluster() {
internalCluster().stopAllNodes();
internalCluster().startNodes(DATA_NODE_COUNT);
}

public AcknowledgedResponse createDataStream(String name) throws Exception {
CreateDataStreamAction.Request request = new CreateDataStreamAction.Request(name);
AcknowledgedResponse response = client().admin().indices().createDataStream(request).get();
assertThat(response.isAcknowledged(), is(true));
if (performRemoteStateRestore()) {
resetCluster();
}
return response;
}

Expand Down Expand Up @@ -67,6 +77,12 @@ public RolloverResponse rolloverDataStream(String name) throws Exception {
RolloverResponse response = client().admin().indices().rolloverIndex(request).get();
assertThat(response.isAcknowledged(), is(true));
assertThat(response.isRolledOver(), is(true));
if (performRemoteStateRestore()) {
String clusterUUIDBefore = clusterService().state().metadata().clusterUUID();
resetCluster();
String clusterUUIDAfter = clusterService().state().metadata().clusterUUID();
assertFalse(clusterUUIDBefore.equals(clusterUUIDAfter));
}
return response;
}

Expand Down Expand Up @@ -110,4 +126,7 @@ public AcknowledgedResponse deleteIndexTemplate(String name) throws Exception {
return response;
}

protected boolean performRemoteStateRestore() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.opensearch.remotestore;

import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.opensearch.action.admin.indices.datastream.DataStreamRolloverIT;
import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.opensearch.cluster.ClusterState;
Expand Down Expand Up @@ -215,6 +216,14 @@ private void validateCurrentMetadata() throws Exception {
});
}

public void testDataStreamWithRemoteStateRestore() throws Exception {
new DataStreamRolloverIT() {
protected boolean performRemoteStateRestore() {
return true;
}
}.testDataStreamRollover();
}

public void testFullClusterRestoreGlobalMetadata() throws Exception {
int shardCount = randomIntBetween(1, 2);
int replicaCount = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,10 @@ public Metadata getLatestMetadata(String clusterName, String clusterUUID) {
// Fetch Index Metadata
Map<String, IndexMetadata> indices = getIndexMetadataMap(clusterName, clusterUUID, clusterMetadataManifest.get());

return Metadata.builder(globalMetadata).indices(indices).build();
Map<String, IndexMetadata> indexMetadataMap = new HashMap<>();
indices.values().forEach(indexMetadata -> { indexMetadataMap.put(indexMetadata.getIndex().getName(), indexMetadata); });

return Metadata.builder(globalMetadata).indices(indexMetadataMap).build();
}

private Metadata getGlobalMetadata(String clusterName, String clusterUUID, ClusterMetadataManifest clusterMetadataManifest) {
Expand Down

0 comments on commit 084404a

Please sign in to comment.