|
29 | 29 | import org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction; |
30 | 30 | import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotAction; |
31 | 31 | import org.elasticsearch.action.admin.cluster.snapshots.create.TransportCreateSnapshotAction; |
| 32 | +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotAction; |
| 33 | +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; |
| 34 | +import org.elasticsearch.action.admin.cluster.snapshots.delete.TransportDeleteSnapshotAction; |
32 | 35 | import org.elasticsearch.action.admin.indices.create.CreateIndexAction; |
33 | 36 | import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; |
34 | 37 | import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction; |
@@ -196,6 +199,53 @@ public void testSuccessfulSnapshot() { |
196 | 199 | assertEquals(0, snapshotInfo.failedShards()); |
197 | 200 | } |
198 | 201 |
|
| 202 | + public void testConcurrentSnapshotCreateAndDelete() { |
| 203 | + setupTestCluster(randomFrom(1, 3, 5), randomIntBetween(2, 10)); |
| 204 | + |
| 205 | + String repoName = "repo"; |
| 206 | + String snapshotName = "snapshot"; |
| 207 | + final String index = "test"; |
| 208 | + |
| 209 | + final int shards = randomIntBetween(1, 10); |
| 210 | + |
| 211 | + TestClusterNode masterNode = |
| 212 | + testClusterNodes.currentMaster(testClusterNodes.nodes.values().iterator().next().clusterService.state()); |
| 213 | + final AtomicBoolean createdSnapshot = new AtomicBoolean(); |
| 214 | + masterNode.client.admin().cluster().preparePutRepository(repoName) |
| 215 | + .setType(FsRepository.TYPE).setSettings(Settings.builder().put("location", randomAlphaOfLength(10))) |
| 216 | + .execute( |
| 217 | + assertNoFailureListener( |
| 218 | + () -> masterNode.client.admin().indices().create( |
| 219 | + new CreateIndexRequest(index).waitForActiveShards(ActiveShardCount.ALL).settings( |
| 220 | + Settings.builder() |
| 221 | + .put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), shards) |
| 222 | + .put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)), |
| 223 | + assertNoFailureListener( |
| 224 | + () -> masterNode.client.admin().cluster().prepareCreateSnapshot(repoName, snapshotName) |
| 225 | + .execute(assertNoFailureListener( |
| 226 | + () -> masterNode.client.admin().cluster().deleteSnapshot( |
| 227 | + new DeleteSnapshotRequest(repoName, snapshotName), |
| 228 | + assertNoFailureListener(() -> masterNode.client.admin().cluster() |
| 229 | + .prepareCreateSnapshot(repoName, snapshotName).execute( |
| 230 | + assertNoFailureListener(() -> createdSnapshot.set(true)) |
| 231 | + ))))))))); |
| 232 | + |
| 233 | + deterministicTaskQueue.runAllRunnableTasks(); |
| 234 | + |
| 235 | + assertTrue(createdSnapshot.get()); |
| 236 | + SnapshotsInProgress finalSnapshotsInProgress = masterNode.clusterService.state().custom(SnapshotsInProgress.TYPE); |
| 237 | + assertFalse(finalSnapshotsInProgress.entries().stream().anyMatch(entry -> entry.state().completed() == false)); |
| 238 | + final Repository repository = masterNode.repositoriesService.repository(repoName); |
| 239 | + Collection<SnapshotId> snapshotIds = repository.getRepositoryData().getSnapshotIds(); |
| 240 | + assertThat(snapshotIds, hasSize(1)); |
| 241 | + |
| 242 | + final SnapshotInfo snapshotInfo = repository.getSnapshotInfo(snapshotIds.iterator().next()); |
| 243 | + assertEquals(SnapshotState.SUCCESS, snapshotInfo.state()); |
| 244 | + assertThat(snapshotInfo.indices(), containsInAnyOrder(index)); |
| 245 | + assertEquals(shards, snapshotInfo.successfulShards()); |
| 246 | + assertEquals(0, snapshotInfo.failedShards()); |
| 247 | + } |
| 248 | + |
199 | 249 | private void startCluster() { |
200 | 250 | final ClusterState initialClusterState = |
201 | 251 | new ClusterState.Builder(ClusterName.DEFAULT).nodes(testClusterNodes.randomDiscoveryNodes()).build(); |
@@ -519,6 +569,11 @@ allocationService, new AliasValidator(), environment, indexScopedSettings, |
519 | 569 | transportService, clusterService, threadPool, |
520 | 570 | snapshotsService, actionFilters, indexNameExpressionResolver |
521 | 571 | )); |
| 572 | + actions.put(DeleteSnapshotAction.INSTANCE, |
| 573 | + new TransportDeleteSnapshotAction( |
| 574 | + transportService, clusterService, threadPool, |
| 575 | + snapshotsService, actionFilters, indexNameExpressionResolver |
| 576 | + )); |
522 | 577 | client.initialize(actions, () -> clusterService.localNode().getId(), transportService.getRemoteClusterService()); |
523 | 578 | } |
524 | 579 |
|
|
0 commit comments