-
Couldn't load subscription status.
- Fork 2.3k
Optimize remote state stale file deletion #13131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
55ed245
Optimize remote state stale file deletion
shiv0408 bef9d2e
Added UT
shiv0408 6bed64b
Refactored into a clean up manager file
shiv0408 bb4b71f
Add UT
shiv0408 1febb68
Modify the Integ test
shiv0408 8f5d7d7
Address PR comment
shiv0408 4e3c9e9
Add changelog
shiv0408 5ea5dbb
apply spotless
shiv0408 04140ff
Made minor requested changes
shiv0408 1a6940f
Merge branch 'main' into async_delete
shiv0408 2025f70
Fix default time interval
shiv0408 3ff82b3
Merge branch 'main' into async_delete
shiv0408 12632fc
Merge branch 'main' into async_delete
shiv0408 3825951
Merge branch 'main' into async_delete
shiv0408 b604b09
Clean up global metadata attribute objects from remote
shiv0408 5079415
Merge branch 'main' into async_delete
shiv0408 7bd079f
fix build
shiv0408 072652d
apply spotless
shiv0408 b51c0b1
Merge branch 'main' into async_delete
shiv0408 0a18f8d
Merge branch 'main' into async_delete
shiv0408 7c4d618
Merge branch 'main' into async_delete
shiv0408 1d330c8
remove MockAsyncUploadFSRepo to avoid flakiness
shiv0408 06b2d10
apply spotless
shiv0408 2f8d2e1
Merge branch 'main' into async_delete
shiv0408 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
...nalClusterTest/java/org/opensearch/gateway/remote/RemoteClusterStateCleanupManagerIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.gateway.remote; | ||
|
|
||
| import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; | ||
| import org.opensearch.common.blobstore.BlobPath; | ||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.remotestore.RemoteStoreBaseIntegTestCase; | ||
| import org.opensearch.repositories.RepositoriesService; | ||
| import org.opensearch.repositories.blobstore.BlobStoreRepository; | ||
| import org.opensearch.test.OpenSearchIntegTestCase; | ||
| import org.junit.Before; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Base64; | ||
| import java.util.Map; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.opensearch.gateway.remote.RemoteClusterStateCleanupManager.CLUSTER_STATE_CLEANUP_INTERVAL_DEFAULT; | ||
| import static org.opensearch.gateway.remote.RemoteClusterStateCleanupManager.REMOTE_CLUSTER_STATE_CLEANUP_INTERVAL_SETTING; | ||
| import static org.opensearch.gateway.remote.RemoteClusterStateCleanupManager.RETAINED_MANIFESTS; | ||
| import static org.opensearch.gateway.remote.RemoteClusterStateCleanupManager.SKIP_CLEANUP_STATE_CHANGES; | ||
| import static org.opensearch.gateway.remote.RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING; | ||
| import static org.opensearch.indices.IndicesService.CLUSTER_DEFAULT_INDEX_REFRESH_INTERVAL_SETTING; | ||
|
|
||
| @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
| public class RemoteClusterStateCleanupManagerIT extends RemoteStoreBaseIntegTestCase { | ||
|
|
||
| private static final String INDEX_NAME = "test-index"; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| asyncUploadMockFsRepo = false; | ||
| } | ||
|
|
||
| @Override | ||
| protected Settings nodeSettings(int nodeOrdinal) { | ||
| return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true).build(); | ||
| } | ||
|
|
||
| private Map<String, Long> initialTestSetup(int shardCount, int replicaCount, int dataNodeCount, int clusterManagerNodeCount) { | ||
| prepareCluster(clusterManagerNodeCount, dataNodeCount, INDEX_NAME, replicaCount, shardCount); | ||
| Map<String, Long> indexStats = indexData(1, false, INDEX_NAME); | ||
| assertEquals(shardCount * (replicaCount + 1), getNumShards(INDEX_NAME).totalNumShards); | ||
| ensureGreen(INDEX_NAME); | ||
| return indexStats; | ||
| } | ||
|
|
||
| public void testRemoteCleanupTaskUpdated() { | ||
| int shardCount = randomIntBetween(1, 2); | ||
| int replicaCount = 1; | ||
| int dataNodeCount = shardCount * (replicaCount + 1); | ||
| int clusterManagerNodeCount = 1; | ||
|
|
||
| initialTestSetup(shardCount, replicaCount, dataNodeCount, clusterManagerNodeCount); | ||
| RemoteClusterStateCleanupManager remoteClusterStateCleanupManager = internalCluster().getClusterManagerNodeInstance( | ||
| RemoteClusterStateCleanupManager.class | ||
| ); | ||
|
|
||
| assertEquals(CLUSTER_STATE_CLEANUP_INTERVAL_DEFAULT, remoteClusterStateCleanupManager.getStaleFileDeletionTask().getInterval()); | ||
| assertTrue(remoteClusterStateCleanupManager.getStaleFileDeletionTask().isScheduled()); | ||
|
|
||
| // now disable | ||
| client().admin() | ||
| .cluster() | ||
| .prepareUpdateSettings() | ||
| .setPersistentSettings(Settings.builder().put(REMOTE_CLUSTER_STATE_CLEANUP_INTERVAL_SETTING.getKey(), -1)) | ||
| .get(); | ||
|
|
||
| assertEquals(-1, remoteClusterStateCleanupManager.getStaleFileDeletionTask().getInterval().getMillis()); | ||
| assertFalse(remoteClusterStateCleanupManager.getStaleFileDeletionTask().isScheduled()); | ||
|
|
||
| // now set Clean up interval to 1 min | ||
| client().admin() | ||
| .cluster() | ||
| .prepareUpdateSettings() | ||
| .setPersistentSettings(Settings.builder().put(REMOTE_CLUSTER_STATE_CLEANUP_INTERVAL_SETTING.getKey(), "1m")) | ||
| .get(); | ||
| assertEquals(1, remoteClusterStateCleanupManager.getStaleFileDeletionTask().getInterval().getMinutes()); | ||
| } | ||
|
|
||
| public void testRemoteCleanupDeleteStale() throws Exception { | ||
| int shardCount = randomIntBetween(1, 2); | ||
| int replicaCount = 1; | ||
| int dataNodeCount = shardCount * (replicaCount + 1); | ||
| int clusterManagerNodeCount = 1; | ||
|
|
||
| initialTestSetup(shardCount, replicaCount, dataNodeCount, clusterManagerNodeCount); | ||
|
|
||
| // set cleanup interval to 100 ms to make the test faster | ||
| ClusterUpdateSettingsResponse response = client().admin() | ||
| .cluster() | ||
| .prepareUpdateSettings() | ||
| .setPersistentSettings(Settings.builder().put(REMOTE_CLUSTER_STATE_CLEANUP_INTERVAL_SETTING.getKey(), "100ms")) | ||
| .get(); | ||
|
|
||
| assertTrue(response.isAcknowledged()); | ||
|
|
||
| // update cluster state 21 times to ensure that clean up has run after this will upload 42 manifest files | ||
| // to repository, if manifest files are less than that it means clean up has run | ||
| updateClusterStateNTimes(RETAINED_MANIFESTS + SKIP_CLEANUP_STATE_CHANGES + 1); | ||
|
|
||
| RepositoriesService repositoriesService = internalCluster().getClusterManagerNodeInstance(RepositoriesService.class); | ||
| BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(REPOSITORY_NAME); | ||
| BlobPath baseMetadataPath = repository.basePath() | ||
| .add( | ||
| Base64.getUrlEncoder() | ||
| .withoutPadding() | ||
| .encodeToString(getClusterState().getClusterName().value().getBytes(StandardCharsets.UTF_8)) | ||
| ) | ||
| .add("cluster-state") | ||
| .add(getClusterState().metadata().clusterUUID()); | ||
| BlobPath manifestContainerPath = baseMetadataPath.add("manifest"); | ||
|
|
||
| assertBusy(() -> { | ||
| int manifestFiles = repository.blobStore().blobContainer(manifestContainerPath).listBlobsByPrefix("manifest").size(); | ||
| logger.info("number of current manifest file: {}", manifestFiles); | ||
| // we can't guarantee that we have same number of manifest as Retained manifest in our repo as there can be other queued task | ||
| // other than replica count change which can upload new manifest files, that's why we check that number of manifests is between | ||
| // Retained manifests and Retained manifests + 2 * Skip cleanup state changes (each cluster state update uploads 2 manifests) | ||
| assertTrue( | ||
| "Current number of manifest files: " + manifestFiles, | ||
| manifestFiles >= RETAINED_MANIFESTS && manifestFiles < RETAINED_MANIFESTS + 2 * SKIP_CLEANUP_STATE_CHANGES | ||
| ); | ||
| }, 500, TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| private void updateClusterStateNTimes(int n) { | ||
| int newReplicaCount = randomIntBetween(0, 3); | ||
| for (int i = n; i > 0; i--) { | ||
| ClusterUpdateSettingsResponse response = client().admin() | ||
| .cluster() | ||
| .prepareUpdateSettings() | ||
| .setPersistentSettings(Settings.builder().put(CLUSTER_DEFAULT_INDEX_REFRESH_INTERVAL_SETTING.getKey(), i, TimeUnit.SECONDS)) | ||
| .get(); | ||
| assertTrue(response.isAcknowledged()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.