Skip to content
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

[Backport 2.x] Add ITs for disallow repo settings update during repo in use #16027

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.opensearch.common.util.concurrent.UncategorizedExecutionException;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.common.Strings;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.discovery.AbstractDisruptionTestCase;
import org.opensearch.plugins.Plugin;
import org.opensearch.repositories.RepositoryData;
Expand Down Expand Up @@ -136,6 +137,60 @@ public void testLongRunningSnapshotAllowsConcurrentSnapshot() throws Exception {
assertSuccessful(createSlowFuture);
}

public void testSettingsUpdateFailWhenCreateSnapshotInProgress() throws Exception {
// Start a cluster with a cluster manager node and a data node
internalCluster().startClusterManagerOnlyNode();
final String dataNode = internalCluster().startDataOnlyNode();
final String repoName = "test-repo";
// Create a repository with random settings
Settings.Builder settings = randomRepositorySettings();
createRepository(repoName, "mock", settings);
createIndexWithContent("index");
// Start a full snapshot and block it on the data node
final ActionFuture<CreateSnapshotResponse> createSlowFuture = startFullSnapshotBlockedOnDataNode(
"slow-snapshot",
repoName,
dataNode
);
Thread.sleep(1000); // Wait for the snapshot to start
assertFalse(createSlowFuture.isDone()); // Ensure the snapshot is still in progress
// Attempt to update the repository settings while the snapshot is in progress
IllegalStateException ex = assertThrows(IllegalStateException.class, () -> updateRepository(repoName, "mock", settings));
// Verify that the update fails with an appropriate exception
assertEquals("trying to modify or unregister repository that is currently used", ex.getMessage());
unblockNode(repoName, dataNode); // Unblock the snapshot
assertSuccessful(createSlowFuture); // Ensure the snapshot completes successfully
}

public void testSettingsUpdateFailWhenDeleteSnapshotInProgress() throws InterruptedException {
// Start a cluster with a cluster manager node and a data node
String clusterManagerName = internalCluster().startClusterManagerOnlyNode();
internalCluster().startDataOnlyNode();
final String repoName = "test-repo";
// Create a repository with random settings
Settings.Builder settings = randomRepositorySettings();
createRepository(repoName, "mock", settings);
createIndexWithContent("index");
final String snapshotName = "snapshot-1";
// Create a full snapshot
SnapshotInfo snapshotInfo = createFullSnapshot(repoName, snapshotName);
assertEquals(SnapshotState.SUCCESS, snapshotInfo.state()); // Ensure the snapshot was successful
assertEquals(RestStatus.OK, snapshotInfo.status()); // Ensure the snapshot status is OK
// Start deleting the snapshot and block it on the cluster manager node
ActionFuture<AcknowledgedResponse> future = deleteSnapshotBlockedOnClusterManager(repoName, snapshotName);
Thread.sleep(1000); // Wait for the delete operation to start
assertFalse(future.isDone()); // Ensure the delete operation is still in progress
// Attempt to update the repository settings while the delete operation is in progress
IllegalStateException ex = assertThrows(
IllegalStateException.class,
() -> updateRepository(repoName, "mock", randomRepositorySettings())
);
// Verify that the update fails with an appropriate exception
assertEquals("trying to modify or unregister repository that is currently used", ex.getMessage());
unblockNode(repoName, clusterManagerName); // Unblock the delete operation
assertAcked(future.actionGet()); // Wait for the delete operation to complete
}

public void testDeletesAreBatched() throws Exception {
internalCluster().startClusterManagerOnlyNode();
final String dataNode = internalCluster().startDataOnlyNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,16 @@ public void onTimeout(TimeValue timeout) {
}
}

protected ActionFuture<AcknowledgedResponse> deleteSnapshotBlockedOnClusterManager(String repoName, String snapshotName) {
blockClusterManagerFromDeletingIndexNFile(repoName);
return deleteSnapshot(repoName, snapshotName);
}

protected ActionFuture<AcknowledgedResponse> deleteSnapshot(String repoName, String snapshotName) {
logger.info("--> Deleting snapshot [{}] to repo [{}]", snapshotName, repoName);
return clusterAdmin().prepareDeleteSnapshot(repoName, snapshotName).execute();
}

protected ActionFuture<CreateSnapshotResponse> startFullSnapshotBlockedOnDataNode(String snapshotName, String repoName, String dataNode)
throws InterruptedException {
blockDataNode(repoName, dataNode);
Expand Down
Loading