Skip to content

Commit fabe9c1

Browse files
Add disallow settings update during repository in use ITs (#16001) (#16027)
(cherry picked from commit 036f6bc) Signed-off-by: Ashish Singh <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 234c4da commit fabe9c1

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

Lines changed: 55 additions & 0 deletions
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;
@@ -136,6 +137,60 @@ public void testLongRunningSnapshotAllowsConcurrentSnapshot() throws Exception {
136137
assertSuccessful(createSlowFuture);
137138
}
138139

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

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,16 @@ public void onTimeout(TimeValue timeout) {
666666
}
667667
}
668668

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

0 commit comments

Comments
 (0)