|
50 | 50 | import org.opensearch.common.util.concurrent.UncategorizedExecutionException;
|
51 | 51 | import org.opensearch.core.action.ActionListener;
|
52 | 52 | import org.opensearch.core.common.Strings;
|
| 53 | +import org.opensearch.core.rest.RestStatus; |
53 | 54 | import org.opensearch.discovery.AbstractDisruptionTestCase;
|
54 | 55 | import org.opensearch.plugins.Plugin;
|
55 | 56 | import org.opensearch.repositories.RepositoryData;
|
@@ -135,6 +136,60 @@ public void testLongRunningSnapshotAllowsConcurrentSnapshot() throws Exception {
|
135 | 136 | assertSuccessful(createSlowFuture);
|
136 | 137 | }
|
137 | 138 |
|
| 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 | + |
138 | 193 | public void testDeletesAreBatched() throws Exception {
|
139 | 194 | internalCluster().startClusterManagerOnlyNode();
|
140 | 195 | final String dataNode = internalCluster().startDataOnlyNode();
|
|
0 commit comments