Skip to content

Commit 97340ed

Browse files
authored
Revert "Optimize remote state stale file deletion (opensearch-project#13131)" (opensearch-project#13969)
This reverts commit b9befaa. Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
1 parent 293905a commit 97340ed

File tree

10 files changed

+442
-1056
lines changed

10 files changed

+442
-1056
lines changed

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

-145
This file was deleted.

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

+63
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest;
1212
import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;
13+
import org.opensearch.cluster.metadata.IndexMetadata;
1314
import org.opensearch.common.blobstore.BlobPath;
1415
import org.opensearch.common.settings.Settings;
1516
import org.opensearch.discovery.DiscoveryStats;
@@ -26,6 +27,7 @@
2627
import java.util.function.Function;
2728
import java.util.stream.Collectors;
2829

30+
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
2931
import static org.opensearch.gateway.remote.RemoteClusterStateService.COORDINATION_METADATA;
3032
import static org.opensearch.gateway.remote.RemoteClusterStateService.CUSTOM_METADATA;
3133
import static org.opensearch.gateway.remote.RemoteClusterStateService.DELIMITER;
@@ -49,6 +51,16 @@ protected Settings nodeSettings(int nodeOrdinal) {
4951
return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true).build();
5052
}
5153

54+
private void prepareCluster(int numClusterManagerNodes, int numDataOnlyNodes, String indices, int replicaCount, int shardCount) {
55+
internalCluster().startClusterManagerOnlyNodes(numClusterManagerNodes);
56+
internalCluster().startDataOnlyNodes(numDataOnlyNodes);
57+
for (String index : indices.split(",")) {
58+
createIndex(index, remoteStoreIndexSettings(replicaCount, shardCount));
59+
ensureYellowAndNoInitializingShards(index);
60+
ensureGreen(index);
61+
}
62+
}
63+
5264
private Map<String, Long> initialTestSetup(int shardCount, int replicaCount, int dataNodeCount, int clusterManagerNodeCount) {
5365
prepareCluster(clusterManagerNodeCount, dataNodeCount, INDEX_NAME, replicaCount, shardCount);
5466
Map<String, Long> indexStats = indexData(1, false, INDEX_NAME);
@@ -57,6 +69,49 @@ private Map<String, Long> initialTestSetup(int shardCount, int replicaCount, int
5769
return indexStats;
5870
}
5971

72+
public void testFullClusterRestoreStaleDelete() throws Exception {
73+
int shardCount = randomIntBetween(1, 2);
74+
int replicaCount = 1;
75+
int dataNodeCount = shardCount * (replicaCount + 1);
76+
int clusterManagerNodeCount = 1;
77+
78+
initialTestSetup(shardCount, replicaCount, dataNodeCount, clusterManagerNodeCount);
79+
setReplicaCount(0);
80+
setReplicaCount(2);
81+
setReplicaCount(0);
82+
setReplicaCount(1);
83+
setReplicaCount(0);
84+
setReplicaCount(1);
85+
setReplicaCount(0);
86+
setReplicaCount(2);
87+
setReplicaCount(0);
88+
89+
RemoteClusterStateService remoteClusterStateService = internalCluster().getClusterManagerNodeInstance(
90+
RemoteClusterStateService.class
91+
);
92+
93+
RepositoriesService repositoriesService = internalCluster().getClusterManagerNodeInstance(RepositoriesService.class);
94+
95+
BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(REPOSITORY_NAME);
96+
BlobPath baseMetadataPath = repository.basePath()
97+
.add(
98+
Base64.getUrlEncoder()
99+
.withoutPadding()
100+
.encodeToString(getClusterState().getClusterName().value().getBytes(StandardCharsets.UTF_8))
101+
)
102+
.add("cluster-state")
103+
.add(getClusterState().metadata().clusterUUID());
104+
105+
assertEquals(10, repository.blobStore().blobContainer(baseMetadataPath.add("manifest")).listBlobsByPrefix("manifest").size());
106+
107+
Map<String, IndexMetadata> indexMetadataMap = remoteClusterStateService.getLatestClusterState(
108+
cluster().getClusterName(),
109+
getClusterState().metadata().clusterUUID()
110+
).getMetadata().getIndices();
111+
assertEquals(0, indexMetadataMap.values().stream().findFirst().get().getNumberOfReplicas());
112+
assertEquals(shardCount, indexMetadataMap.values().stream().findFirst().get().getNumberOfShards());
113+
}
114+
60115
public void testRemoteStateStats() {
61116
int shardCount = randomIntBetween(1, 2);
62117
int replicaCount = 1;
@@ -186,4 +241,12 @@ private void validateNodesStatsResponse(NodesStatsResponse nodesStatsResponse) {
186241
assertNotNull(nodesStatsResponse.getNodes().get(0));
187242
assertNotNull(nodesStatsResponse.getNodes().get(0).getDiscoveryStats());
188243
}
244+
245+
private void setReplicaCount(int replicaCount) {
246+
client().admin()
247+
.indices()
248+
.prepareUpdateSettings(INDEX_NAME)
249+
.setSettings(Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, replicaCount))
250+
.get();
251+
}
189252
}

server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteStoreBaseIntegTestCase.java

-10
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,4 @@ protected void restore(boolean restoreAllShards, String... indices) {
350350
PlainActionFuture.newFuture()
351351
);
352352
}
353-
354-
protected void prepareCluster(int numClusterManagerNodes, int numDataOnlyNodes, String indices, int replicaCount, int shardCount) {
355-
internalCluster().startClusterManagerOnlyNodes(numClusterManagerNodes);
356-
internalCluster().startDataOnlyNodes(numDataOnlyNodes);
357-
for (String index : indices.split(",")) {
358-
createIndex(index, remoteStoreIndexSettings(replicaCount, shardCount));
359-
ensureYellowAndNoInitializingShards(index);
360-
ensureGreen(index);
361-
}
362-
}
363353
}

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
import org.opensearch.gateway.GatewayService;
105105
import org.opensearch.gateway.PersistedClusterStateService;
106106
import org.opensearch.gateway.ShardsBatchGatewayAllocator;
107-
import org.opensearch.gateway.remote.RemoteClusterStateCleanupManager;
108107
import org.opensearch.gateway.remote.RemoteClusterStateService;
109108
import org.opensearch.http.HttpTransportSettings;
110109
import org.opensearch.index.IndexModule;
@@ -712,7 +711,6 @@ public void apply(Settings value, Settings current, Settings previous) {
712711
SearchRequestSlowLog.CLUSTER_SEARCH_REQUEST_SLOWLOG_LEVEL,
713712

714713
// Remote cluster state settings
715-
RemoteClusterStateCleanupManager.REMOTE_CLUSTER_STATE_CLEANUP_INTERVAL_SETTING,
716714
RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING,
717715
RemoteClusterStateService.INDEX_METADATA_UPLOAD_TIMEOUT_SETTING,
718716
RemoteClusterStateService.GLOBAL_METADATA_UPLOAD_TIMEOUT_SETTING,

0 commit comments

Comments
 (0)