|
18 | 18 | import org.opensearch.action.support.PlainActionFuture;
|
19 | 19 | import org.opensearch.client.Client;
|
20 | 20 | import org.opensearch.client.Requests;
|
| 21 | +import org.opensearch.cluster.ClusterState; |
21 | 22 | import org.opensearch.cluster.metadata.IndexMetadata;
|
22 | 23 | import org.opensearch.common.io.PathUtils;
|
23 | 24 | import org.opensearch.common.settings.Settings;
|
|
26 | 27 | import org.opensearch.core.rest.RestStatus;
|
27 | 28 | import org.opensearch.index.IndexService;
|
28 | 29 | import org.opensearch.index.IndexSettings;
|
| 30 | +import org.opensearch.index.remote.RemoteStorePathType; |
29 | 31 | import org.opensearch.index.shard.IndexShard;
|
30 | 32 | import org.opensearch.indices.IndicesService;
|
31 | 33 | import org.opensearch.indices.replication.common.ReplicationType;
|
|
43 | 45 | import java.util.ArrayList;
|
44 | 46 | import java.util.Arrays;
|
45 | 47 | import java.util.List;
|
| 48 | +import java.util.Map; |
46 | 49 | import java.util.Optional;
|
47 | 50 | import java.util.concurrent.ExecutionException;
|
48 | 51 | import java.util.stream.Collectors;
|
49 | 52 | import java.util.stream.Stream;
|
50 | 53 |
|
51 | 54 | import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_SEGMENT_STORE_REPOSITORY;
|
52 | 55 | import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_STORE_ENABLED;
|
53 |
| -import static org.opensearch.remotestore.RemoteStoreBaseIntegTestCase.remoteStoreClusterSettings; |
| 56 | +import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_STORE_PATH_PREFIX_TYPE_SETTING; |
54 | 57 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
|
55 | 58 | import static org.hamcrest.Matchers.equalTo;
|
56 | 59 | import static org.hamcrest.Matchers.greaterThan;
|
@@ -257,6 +260,85 @@ public void testRestoreOperationsShallowCopyEnabled() throws IOException, Execut
|
257 | 260 | assertDocsPresentInIndex(client, restoredIndexName1Doc, numDocsInIndex1 + 2);
|
258 | 261 | }
|
259 | 262 |
|
| 263 | + /** |
| 264 | + * In this test, we validate presence of remote_store custom data in index metadata for standard index creation and |
| 265 | + * on snapshot restore. |
| 266 | + */ |
| 267 | + public void testRemoteStoreCustomDataOnIndexCreationAndRestore() { |
| 268 | + String clusterManagerNode = internalCluster().startClusterManagerOnlyNode(); |
| 269 | + internalCluster().startDataOnlyNode(); |
| 270 | + String indexName1 = "testindex1"; |
| 271 | + String indexName2 = "testindex2"; |
| 272 | + String snapshotRepoName = "test-restore-snapshot-repo"; |
| 273 | + String snapshotName1 = "test-restore-snapshot1"; |
| 274 | + Path absolutePath1 = randomRepoPath().toAbsolutePath(); |
| 275 | + logger.info("Snapshot Path [{}]", absolutePath1); |
| 276 | + String restoredIndexName1version1 = indexName1 + "-restored-1"; |
| 277 | + String restoredIndexName1version2 = indexName1 + "-restored-2"; |
| 278 | + |
| 279 | + createRepository(snapshotRepoName, "fs", getRepositorySettings(absolutePath1, true)); |
| 280 | + Client client = client(); |
| 281 | + Settings indexSettings = getIndexSettings(1, 0).build(); |
| 282 | + createIndex(indexName1, indexSettings); |
| 283 | + |
| 284 | + indexDocuments(client, indexName1, randomIntBetween(5, 10)); |
| 285 | + ensureGreen(indexName1); |
| 286 | + validateRemoteStorePathType(indexName1, RemoteStorePathType.FIXED); |
| 287 | + |
| 288 | + logger.info("--> snapshot"); |
| 289 | + SnapshotInfo snapshotInfo = createSnapshot(snapshotRepoName, snapshotName1, new ArrayList<>(Arrays.asList(indexName1))); |
| 290 | + assertEquals(SnapshotState.SUCCESS, snapshotInfo.state()); |
| 291 | + assertTrue(snapshotInfo.successfulShards() > 0); |
| 292 | + assertEquals(snapshotInfo.totalShards(), snapshotInfo.successfulShards()); |
| 293 | + |
| 294 | + RestoreSnapshotResponse restoreSnapshotResponse = client.admin() |
| 295 | + .cluster() |
| 296 | + .prepareRestoreSnapshot(snapshotRepoName, snapshotName1) |
| 297 | + .setWaitForCompletion(false) |
| 298 | + .setRenamePattern(indexName1) |
| 299 | + .setRenameReplacement(restoredIndexName1version1) |
| 300 | + .get(); |
| 301 | + assertEquals(RestStatus.ACCEPTED, restoreSnapshotResponse.status()); |
| 302 | + ensureGreen(restoredIndexName1version1); |
| 303 | + validateRemoteStorePathType(restoredIndexName1version1, RemoteStorePathType.FIXED); |
| 304 | + |
| 305 | + client(clusterManagerNode).admin() |
| 306 | + .cluster() |
| 307 | + .prepareUpdateSettings() |
| 308 | + .setTransientSettings( |
| 309 | + Settings.builder().put(CLUSTER_REMOTE_STORE_PATH_PREFIX_TYPE_SETTING.getKey(), RemoteStorePathType.HASHED_PREFIX) |
| 310 | + ) |
| 311 | + .get(); |
| 312 | + |
| 313 | + restoreSnapshotResponse = client.admin() |
| 314 | + .cluster() |
| 315 | + .prepareRestoreSnapshot(snapshotRepoName, snapshotName1) |
| 316 | + .setWaitForCompletion(false) |
| 317 | + .setRenamePattern(indexName1) |
| 318 | + .setRenameReplacement(restoredIndexName1version2) |
| 319 | + .get(); |
| 320 | + assertEquals(RestStatus.ACCEPTED, restoreSnapshotResponse.status()); |
| 321 | + ensureGreen(restoredIndexName1version2); |
| 322 | + validateRemoteStorePathType(restoredIndexName1version2, RemoteStorePathType.HASHED_PREFIX); |
| 323 | + |
| 324 | + // Create index with cluster setting cluster.remote_store.index.path.prefix.type as hashed_prefix. |
| 325 | + indexSettings = getIndexSettings(1, 0).build(); |
| 326 | + createIndex(indexName2, indexSettings); |
| 327 | + ensureGreen(indexName2); |
| 328 | + validateRemoteStorePathType(indexName2, RemoteStorePathType.HASHED_PREFIX); |
| 329 | + |
| 330 | + // Validating that custom data has not changed for indexes which were created before the cluster setting got updated |
| 331 | + validateRemoteStorePathType(indexName1, RemoteStorePathType.FIXED); |
| 332 | + } |
| 333 | + |
| 334 | + private void validateRemoteStorePathType(String index, RemoteStorePathType pathType) { |
| 335 | + ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState(); |
| 336 | + // Validate that the remote_store custom data is present in index metadata for the created index. |
| 337 | + Map<String, String> remoteCustomData = state.metadata().index(index).getCustomData(IndexMetadata.REMOTE_STORE_CUSTOM_KEY); |
| 338 | + assertNotNull(remoteCustomData); |
| 339 | + assertEquals(pathType.toString(), remoteCustomData.get(RemoteStorePathType.NAME)); |
| 340 | + } |
| 341 | + |
260 | 342 | public void testRestoreInSameRemoteStoreEnabledIndex() throws IOException {
|
261 | 343 | String clusterManagerNode = internalCluster().startClusterManagerOnlyNode();
|
262 | 344 | String primary = internalCluster().startDataOnlyNode();
|
|
0 commit comments