|
16 | 16 | import org.opensearch.action.support.PlainActionFuture;
|
17 | 17 | import org.opensearch.client.Client;
|
18 | 18 | import org.opensearch.client.Requests;
|
| 19 | +import org.opensearch.cluster.ClusterState; |
19 | 20 | import org.opensearch.cluster.metadata.IndexMetadata;
|
20 | 21 | import org.opensearch.common.io.PathUtils;
|
21 | 22 | import org.opensearch.common.settings.Settings;
|
|
24 | 25 | import org.opensearch.core.rest.RestStatus;
|
25 | 26 | import org.opensearch.index.IndexService;
|
26 | 27 | import org.opensearch.index.IndexSettings;
|
| 28 | +import org.opensearch.index.remote.RemoteStorePathType; |
27 | 29 | import org.opensearch.index.shard.IndexShard;
|
28 | 30 | import org.opensearch.indices.IndicesService;
|
29 | 31 | import org.opensearch.indices.replication.common.ReplicationType;
|
|
42 | 44 | import java.util.ArrayList;
|
43 | 45 | import java.util.Arrays;
|
44 | 46 | import java.util.List;
|
| 47 | +import java.util.Map; |
45 | 48 | import java.util.Optional;
|
46 | 49 | import java.util.concurrent.ExecutionException;
|
47 | 50 | import java.util.stream.Collectors;
|
48 | 51 | import java.util.stream.Stream;
|
49 | 52 |
|
50 | 53 | import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_STORE_ENABLED;
|
51 |
| -import static org.opensearch.remotestore.RemoteStoreBaseIntegTestCase.remoteStoreClusterSettings; |
| 54 | +import static org.opensearch.indices.IndicesService.CLUSTER_REMOTE_STORE_PATH_PREFIX_TYPE_SETTING; |
52 | 55 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
|
53 | 56 | import static org.hamcrest.Matchers.equalTo;
|
54 | 57 | import static org.hamcrest.Matchers.greaterThan;
|
@@ -199,6 +202,85 @@ public void testRestoreOperationsShallowCopyEnabled() throws Exception {
|
199 | 202 | assertDocsPresentInIndex(client, restoredIndexName1, numDocsInIndex1 + 2);
|
200 | 203 | }
|
201 | 204 |
|
| 205 | + /** |
| 206 | + * In this test, we validate presence of remote_store custom data in index metadata for standard index creation and |
| 207 | + * on snapshot restore. |
| 208 | + */ |
| 209 | + public void testRemoteStoreCustomDataOnIndexCreationAndRestore() { |
| 210 | + String clusterManagerNode = internalCluster().startClusterManagerOnlyNode(); |
| 211 | + internalCluster().startDataOnlyNode(); |
| 212 | + String indexName1 = "testindex1"; |
| 213 | + String indexName2 = "testindex2"; |
| 214 | + String snapshotRepoName = "test-restore-snapshot-repo"; |
| 215 | + String snapshotName1 = "test-restore-snapshot1"; |
| 216 | + Path absolutePath1 = randomRepoPath().toAbsolutePath(); |
| 217 | + logger.info("Snapshot Path [{}]", absolutePath1); |
| 218 | + String restoredIndexName1version1 = indexName1 + "-restored-1"; |
| 219 | + String restoredIndexName1version2 = indexName1 + "-restored-2"; |
| 220 | + |
| 221 | + createRepository(snapshotRepoName, "fs", getRepositorySettings(absolutePath1, true)); |
| 222 | + Client client = client(); |
| 223 | + Settings indexSettings = getIndexSettings(1, 0).build(); |
| 224 | + createIndex(indexName1, indexSettings); |
| 225 | + |
| 226 | + indexDocuments(client, indexName1, randomIntBetween(5, 10)); |
| 227 | + ensureGreen(indexName1); |
| 228 | + validateRemoteStorePathType(indexName1, RemoteStorePathType.FIXED); |
| 229 | + |
| 230 | + logger.info("--> snapshot"); |
| 231 | + SnapshotInfo snapshotInfo = createSnapshot(snapshotRepoName, snapshotName1, new ArrayList<>(Arrays.asList(indexName1))); |
| 232 | + assertEquals(SnapshotState.SUCCESS, snapshotInfo.state()); |
| 233 | + assertTrue(snapshotInfo.successfulShards() > 0); |
| 234 | + assertEquals(snapshotInfo.totalShards(), snapshotInfo.successfulShards()); |
| 235 | + |
| 236 | + RestoreSnapshotResponse restoreSnapshotResponse = client.admin() |
| 237 | + .cluster() |
| 238 | + .prepareRestoreSnapshot(snapshotRepoName, snapshotName1) |
| 239 | + .setWaitForCompletion(false) |
| 240 | + .setRenamePattern(indexName1) |
| 241 | + .setRenameReplacement(restoredIndexName1version1) |
| 242 | + .get(); |
| 243 | + assertEquals(RestStatus.ACCEPTED, restoreSnapshotResponse.status()); |
| 244 | + ensureGreen(restoredIndexName1version1); |
| 245 | + validateRemoteStorePathType(restoredIndexName1version1, RemoteStorePathType.FIXED); |
| 246 | + |
| 247 | + client(clusterManagerNode).admin() |
| 248 | + .cluster() |
| 249 | + .prepareUpdateSettings() |
| 250 | + .setTransientSettings( |
| 251 | + Settings.builder().put(CLUSTER_REMOTE_STORE_PATH_PREFIX_TYPE_SETTING.getKey(), RemoteStorePathType.HASHED_PREFIX) |
| 252 | + ) |
| 253 | + .get(); |
| 254 | + |
| 255 | + restoreSnapshotResponse = client.admin() |
| 256 | + .cluster() |
| 257 | + .prepareRestoreSnapshot(snapshotRepoName, snapshotName1) |
| 258 | + .setWaitForCompletion(false) |
| 259 | + .setRenamePattern(indexName1) |
| 260 | + .setRenameReplacement(restoredIndexName1version2) |
| 261 | + .get(); |
| 262 | + assertEquals(RestStatus.ACCEPTED, restoreSnapshotResponse.status()); |
| 263 | + ensureGreen(restoredIndexName1version2); |
| 264 | + validateRemoteStorePathType(restoredIndexName1version2, RemoteStorePathType.HASHED_PREFIX); |
| 265 | + |
| 266 | + // Create index with cluster setting cluster.remote_store.index.path.prefix.type as hashed_prefix. |
| 267 | + indexSettings = getIndexSettings(1, 0).build(); |
| 268 | + createIndex(indexName2, indexSettings); |
| 269 | + ensureGreen(indexName2); |
| 270 | + validateRemoteStorePathType(indexName2, RemoteStorePathType.HASHED_PREFIX); |
| 271 | + |
| 272 | + // Validating that custom data has not changed for indexes which were created before the cluster setting got updated |
| 273 | + validateRemoteStorePathType(indexName1, RemoteStorePathType.FIXED); |
| 274 | + } |
| 275 | + |
| 276 | + private void validateRemoteStorePathType(String index, RemoteStorePathType pathType) { |
| 277 | + ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState(); |
| 278 | + // Validate that the remote_store custom data is present in index metadata for the created index. |
| 279 | + Map<String, String> remoteCustomData = state.metadata().index(index).getCustomData(IndexMetadata.REMOTE_STORE_CUSTOM_KEY); |
| 280 | + assertNotNull(remoteCustomData); |
| 281 | + assertEquals(pathType.toString(), remoteCustomData.get(RemoteStorePathType.NAME)); |
| 282 | + } |
| 283 | + |
202 | 284 | public void testRestoreInSameRemoteStoreEnabledIndex() throws IOException {
|
203 | 285 | String clusterManagerNode = internalCluster().startClusterManagerOnlyNode();
|
204 | 286 | String primary = internalCluster().startDataOnlyNode();
|
|
0 commit comments