Skip to content

Commit

Permalink
Add disallow settings update during repository in use ITs (opensearch…
Browse files Browse the repository at this point in the history
…-project#16001)

Signed-off-by: Ashish Singh <[email protected]>
  • Loading branch information
ashking94 authored and ruai0511 committed Oct 4, 2024
1 parent 96ed4a8 commit f7d32f5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
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 @@ -135,6 +136,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 @@ -665,6 +665,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

0 comments on commit f7d32f5

Please sign in to comment.