|
30 | 30 | import java.util.concurrent.TimeUnit; |
31 | 31 | import java.util.stream.Collectors; |
32 | 32 |
|
| 33 | +import static org.opensearch.index.IndexSettings.INDEX_REMOTE_TRANSLOG_KEEP_EXTRA_GEN_SETTING; |
33 | 34 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; |
34 | 35 | import static org.hamcrest.Matchers.equalTo; |
35 | 36 | import static org.hamcrest.Matchers.greaterThan; |
@@ -312,6 +313,107 @@ public void testRemoteStoreCleanupForDeletedIndexForSnapshotV2MultipleSnapshots( |
312 | 313 | // translogPostDeletionOfSnapshot1.size()), 60, TimeUnit.SECONDS); |
313 | 314 | } |
314 | 315 |
|
| 316 | + public void testRemoteStoreCleanupMultiplePrimaryOnSnapshotDeletion() throws Exception { |
| 317 | + disableRepoConsistencyCheck("Remote store repository is being used in the test"); |
| 318 | + final Path remoteStoreRepoPath = randomRepoPath(); |
| 319 | + Settings settings = remoteStoreClusterSettings(REMOTE_REPO_NAME, remoteStoreRepoPath); |
| 320 | + settings = Settings.builder() |
| 321 | + .put(settings) |
| 322 | + .put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED.getKey(), true) |
| 323 | + .put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING.getKey(), RemoteStoreEnums.PathType.FIXED.toString()) |
| 324 | + .build(); |
| 325 | + String clusterManagerName = internalCluster().startClusterManagerOnlyNode(settings); |
| 326 | + internalCluster().startDataOnlyNodes(3, settings); |
| 327 | + final Client clusterManagerClient = internalCluster().clusterManagerClient(); |
| 328 | + ensureStableCluster(4); |
| 329 | + |
| 330 | + RemoteStorePinnedTimestampService remoteStorePinnedTimestampService = internalCluster().getInstance( |
| 331 | + RemoteStorePinnedTimestampService.class, |
| 332 | + clusterManagerName |
| 333 | + ); |
| 334 | + remoteStorePinnedTimestampService.rescheduleAsyncUpdatePinnedTimestampTask(TimeValue.timeValueSeconds(1)); |
| 335 | + RemoteStoreSettings.setPinnedTimestampsLookbackInterval(TimeValue.ZERO); |
| 336 | + |
| 337 | + final String snapshotRepoName = "snapshot-repo-name"; |
| 338 | + final Path snapshotRepoPath = randomRepoPath(); |
| 339 | + createRepository(snapshotRepoName, "mock", snapshotRepoSettingsForShallowV2(snapshotRepoPath)); |
| 340 | + |
| 341 | + final String remoteStoreEnabledIndexName = "remote-index-1"; |
| 342 | + final Settings remoteStoreEnabledIndexSettings = Settings.builder() |
| 343 | + .put(getRemoteStoreBackedIndexSettings()) |
| 344 | + .put(INDEX_REMOTE_TRANSLOG_KEEP_EXTRA_GEN_SETTING.getKey(), 2) |
| 345 | + .build(); |
| 346 | + createIndex(remoteStoreEnabledIndexName, remoteStoreEnabledIndexSettings); |
| 347 | + ensureGreen(remoteStoreEnabledIndexName); |
| 348 | + |
| 349 | + // Create 2 snapshots for primary term 1 |
| 350 | + keepPinnedTimestampSchedulerUpdated(); |
| 351 | + indexRandomDocs(remoteStoreEnabledIndexName, 5); |
| 352 | + createSnapshot(snapshotRepoName, "snap1"); |
| 353 | + keepPinnedTimestampSchedulerUpdated(); |
| 354 | + indexRandomDocs(remoteStoreEnabledIndexName, 5); |
| 355 | + createSnapshot(snapshotRepoName, "snap2"); |
| 356 | + |
| 357 | + // Restart current primary to change the primary term |
| 358 | + internalCluster().restartNode(primaryNodeName(remoteStoreEnabledIndexName)); |
| 359 | + ensureGreen(remoteStoreEnabledIndexName); |
| 360 | + |
| 361 | + // Create 2 snapshots for primary term 2 |
| 362 | + keepPinnedTimestampSchedulerUpdated(); |
| 363 | + indexRandomDocs(remoteStoreEnabledIndexName, 5); |
| 364 | + createSnapshot(snapshotRepoName, "snap3"); |
| 365 | + keepPinnedTimestampSchedulerUpdated(); |
| 366 | + indexRandomDocs(remoteStoreEnabledIndexName, 5); |
| 367 | + createSnapshot(snapshotRepoName, "snap4"); |
| 368 | + |
| 369 | + String indexUUID = client().admin() |
| 370 | + .indices() |
| 371 | + .prepareGetSettings(remoteStoreEnabledIndexName) |
| 372 | + .get() |
| 373 | + .getSetting(remoteStoreEnabledIndexName, IndexMetadata.SETTING_INDEX_UUID); |
| 374 | + |
| 375 | + Path indexPath = Path.of(String.valueOf(remoteStoreRepoPath), indexUUID); |
| 376 | + Path shardPath = Path.of(String.valueOf(indexPath), "0"); |
| 377 | + Path translogPath = Path.of(String.valueOf(shardPath), "translog", "data", "1"); |
| 378 | + |
| 379 | + // Deleting snap1 will still keep files in primary term 1 due to snap2 |
| 380 | + deleteSnapshot(clusterManagerClient, snapshotRepoName, "snap1"); |
| 381 | + assertTrue(RemoteStoreBaseIntegTestCase.getFileCount(translogPath) > 0); |
| 382 | + |
| 383 | + // Deleting snap2 will not remove primary term 1 as we need to trigger trimUnreferencedReaders once |
| 384 | + deleteSnapshot(clusterManagerClient, snapshotRepoName, "snap2"); |
| 385 | + assertTrue(RemoteStoreBaseIntegTestCase.getFileCount(translogPath) > 0); |
| 386 | + |
| 387 | + // Index a doc to trigger trimUnreferencedReaders |
| 388 | + RemoteStoreSettings.setPinnedTimestampsLookbackInterval(TimeValue.ZERO); |
| 389 | + keepPinnedTimestampSchedulerUpdated(); |
| 390 | + indexRandomDocs(remoteStoreEnabledIndexName, 5); |
| 391 | + |
| 392 | + assertBusy(() -> assertFalse(Files.exists(translogPath)), 30, TimeUnit.SECONDS); |
| 393 | + } |
| 394 | + |
| 395 | + private void createSnapshot(String repoName, String snapshotName) { |
| 396 | + CreateSnapshotResponse createSnapshotResponse = client().admin() |
| 397 | + .cluster() |
| 398 | + .prepareCreateSnapshot(repoName, snapshotName) |
| 399 | + .setWaitForCompletion(true) |
| 400 | + .get(); |
| 401 | + SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo(); |
| 402 | + |
| 403 | + assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS)); |
| 404 | + assertThat(snapshotInfo.successfulShards(), greaterThan(0)); |
| 405 | + assertThat(snapshotInfo.successfulShards(), equalTo(snapshotInfo.totalShards())); |
| 406 | + assertThat(snapshotInfo.snapshotId().getName(), equalTo(snapshotName)); |
| 407 | + } |
| 408 | + |
| 409 | + private void deleteSnapshot(Client clusterManagerClient, String repoName, String snapshotName) { |
| 410 | + AcknowledgedResponse deleteSnapshotResponse = clusterManagerClient.admin() |
| 411 | + .cluster() |
| 412 | + .prepareDeleteSnapshot(repoName, snapshotName) |
| 413 | + .get(); |
| 414 | + assertAcked(deleteSnapshotResponse); |
| 415 | + } |
| 416 | + |
315 | 417 | private Settings snapshotV2Settings(Path remoteStoreRepoPath) { |
316 | 418 | Settings settings = Settings.builder() |
317 | 419 | .put(remoteStoreClusterSettings(REMOTE_REPO_NAME, remoteStoreRepoPath)) |
|
0 commit comments