Skip to content

Commit 036f6bc

Browse files
authored
Add disallow settings update during repository in use ITs (opensearch-project#16001)
Signed-off-by: Ashish Singh <ssashish@amazon.com>
1 parent 05dab3b commit 036f6bc

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/ConcurrentSnapshotsIT.java

+55
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.opensearch.common.util.concurrent.UncategorizedExecutionException;
5151
import org.opensearch.core.action.ActionListener;
5252
import org.opensearch.core.common.Strings;
53+
import org.opensearch.core.rest.RestStatus;
5354
import org.opensearch.discovery.AbstractDisruptionTestCase;
5455
import org.opensearch.plugins.Plugin;
5556
import org.opensearch.repositories.RepositoryData;
@@ -135,6 +136,60 @@ public void testLongRunningSnapshotAllowsConcurrentSnapshot() throws Exception {
135136
assertSuccessful(createSlowFuture);
136137
}
137138

139+
public void testSettingsUpdateFailWhenCreateSnapshotInProgress() throws Exception {
140+
// Start a cluster with a cluster manager node and a data node
141+
internalCluster().startClusterManagerOnlyNode();
142+
final String dataNode = internalCluster().startDataOnlyNode();
143+
final String repoName = "test-repo";
144+
// Create a repository with random settings
145+
Settings.Builder settings = randomRepositorySettings();
146+
createRepository(repoName, "mock", settings);
147+
createIndexWithContent("index");
148+
// Start a full snapshot and block it on the data node
149+
final ActionFuture<CreateSnapshotResponse> createSlowFuture = startFullSnapshotBlockedOnDataNode(
150+
"slow-snapshot",
151+
repoName,
152+
dataNode
153+
);
154+
Thread.sleep(1000); // Wait for the snapshot to start
155+
assertFalse(createSlowFuture.isDone()); // Ensure the snapshot is still in progress
156+
// Attempt to update the repository settings while the snapshot is in progress
157+
IllegalStateException ex = assertThrows(IllegalStateException.class, () -> updateRepository(repoName, "mock", settings));
158+
// Verify that the update fails with an appropriate exception
159+
assertEquals("trying to modify or unregister repository that is currently used", ex.getMessage());
160+
unblockNode(repoName, dataNode); // Unblock the snapshot
161+
assertSuccessful(createSlowFuture); // Ensure the snapshot completes successfully
162+
}
163+
164+
public void testSettingsUpdateFailWhenDeleteSnapshotInProgress() throws InterruptedException {
165+
// Start a cluster with a cluster manager node and a data node
166+
String clusterManagerName = internalCluster().startClusterManagerOnlyNode();
167+
internalCluster().startDataOnlyNode();
168+
final String repoName = "test-repo";
169+
// Create a repository with random settings
170+
Settings.Builder settings = randomRepositorySettings();
171+
createRepository(repoName, "mock", settings);
172+
createIndexWithContent("index");
173+
final String snapshotName = "snapshot-1";
174+
// Create a full snapshot
175+
SnapshotInfo snapshotInfo = createFullSnapshot(repoName, snapshotName);
176+
assertEquals(SnapshotState.SUCCESS, snapshotInfo.state()); // Ensure the snapshot was successful
177+
assertEquals(RestStatus.OK, snapshotInfo.status()); // Ensure the snapshot status is OK
178+
// Start deleting the snapshot and block it on the cluster manager node
179+
ActionFuture<AcknowledgedResponse> future = deleteSnapshotBlockedOnClusterManager(repoName, snapshotName);
180+
Thread.sleep(1000); // Wait for the delete operation to start
181+
assertFalse(future.isDone()); // Ensure the delete operation is still in progress
182+
// Attempt to update the repository settings while the delete operation is in progress
183+
IllegalStateException ex = assertThrows(
184+
IllegalStateException.class,
185+
() -> updateRepository(repoName, "mock", randomRepositorySettings())
186+
);
187+
// Verify that the update fails with an appropriate exception
188+
assertEquals("trying to modify or unregister repository that is currently used", ex.getMessage());
189+
unblockNode(repoName, clusterManagerName); // Unblock the delete operation
190+
assertAcked(future.actionGet()); // Wait for the delete operation to complete
191+
}
192+
138193
public void testDeletesAreBatched() throws Exception {
139194
internalCluster().startClusterManagerOnlyNode();
140195
final String dataNode = internalCluster().startDataOnlyNode();

test/framework/src/main/java/org/opensearch/snapshots/AbstractSnapshotIntegTestCase.java

+10
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,16 @@ public void onTimeout(TimeValue timeout) {
665665
}
666666
}
667667

668+
protected ActionFuture<AcknowledgedResponse> deleteSnapshotBlockedOnClusterManager(String repoName, String snapshotName) {
669+
blockClusterManagerFromDeletingIndexNFile(repoName);
670+
return deleteSnapshot(repoName, snapshotName);
671+
}
672+
673+
protected ActionFuture<AcknowledgedResponse> deleteSnapshot(String repoName, String snapshotName) {
674+
logger.info("--> Deleting snapshot [{}] to repo [{}]", snapshotName, repoName);
675+
return clusterAdmin().prepareDeleteSnapshot(repoName, snapshotName).execute();
676+
}
677+
668678
protected ActionFuture<CreateSnapshotResponse> startFullSnapshotBlockedOnDataNode(String snapshotName, String repoName, String dataNode)
669679
throws InterruptedException {
670680
blockDataNode(repoName, dataNode);

0 commit comments

Comments
 (0)