|
39 | 39 | import org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
|
40 | 40 | import org.opensearch.action.index.IndexRequestBuilder;
|
41 | 41 | import org.opensearch.client.Client;
|
| 42 | +import org.opensearch.cluster.ClusterState; |
42 | 43 | import org.opensearch.cluster.block.ClusterBlocks;
|
43 | 44 | import org.opensearch.cluster.metadata.IndexMetadata;
|
44 | 45 | import org.opensearch.cluster.metadata.MappingMetadata;
|
@@ -151,6 +152,62 @@ public void testParallelRestoreOperations() {
|
151 | 152 | assertThat(client.prepareGet(restoredIndexName2, docId2).get().isExists(), equalTo(true));
|
152 | 153 | }
|
153 | 154 |
|
| 155 | + /** |
| 156 | + * In this test, we test that an index created does not have any remote_store custom data in index metadata at the |
| 157 | + * time of index creation and after snapshot restore. |
| 158 | + */ |
| 159 | + public void testNoRemoteStoreCustomDataOnIndexCreationAndRestore() { |
| 160 | + String indexName1 = "testindex1"; |
| 161 | + String repoName = "test-restore-snapshot-repo"; |
| 162 | + String snapshotName1 = "test-restore-snapshot1"; |
| 163 | + Path absolutePath = randomRepoPath().toAbsolutePath(); |
| 164 | + logger.info("Path [{}]", absolutePath); |
| 165 | + String restoredIndexName1 = indexName1 + "-restored"; |
| 166 | + String expectedValue = "expected"; |
| 167 | + |
| 168 | + Client client = client(); |
| 169 | + // Write a document |
| 170 | + String docId = Integer.toString(randomInt()); |
| 171 | + index(indexName1, "_doc", docId, "value", expectedValue); |
| 172 | + |
| 173 | + createRepository(repoName, "fs", absolutePath); |
| 174 | + |
| 175 | + logger.info("--> snapshot"); |
| 176 | + CreateSnapshotResponse createSnapshotResponse = client.admin() |
| 177 | + .cluster() |
| 178 | + .prepareCreateSnapshot(repoName, snapshotName1) |
| 179 | + .setWaitForCompletion(true) |
| 180 | + .setIndices(indexName1) |
| 181 | + .get(); |
| 182 | + assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); |
| 183 | + assertThat( |
| 184 | + createSnapshotResponse.getSnapshotInfo().successfulShards(), |
| 185 | + equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()) |
| 186 | + ); |
| 187 | + assertThat(createSnapshotResponse.getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS)); |
| 188 | + |
| 189 | + ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState(); |
| 190 | + |
| 191 | + // Validate that the remote_store custom data is not present in index metadata for the created index. |
| 192 | + assertNull(state.metadata().index(indexName1).getCustomData(IndexMetadata.REMOTE_STORE_CUSTOM_KEY)); |
| 193 | + |
| 194 | + RestoreSnapshotResponse restoreSnapshotResponse1 = client.admin() |
| 195 | + .cluster() |
| 196 | + .prepareRestoreSnapshot(repoName, snapshotName1) |
| 197 | + .setWaitForCompletion(false) |
| 198 | + .setRenamePattern(indexName1) |
| 199 | + .setRenameReplacement(restoredIndexName1) |
| 200 | + .get(); |
| 201 | + assertThat(restoreSnapshotResponse1.status(), equalTo(RestStatus.ACCEPTED)); |
| 202 | + ensureGreen(restoredIndexName1); |
| 203 | + assertThat(client.prepareGet(restoredIndexName1, docId).get().isExists(), equalTo(true)); |
| 204 | + |
| 205 | + state = client().admin().cluster().prepareState().execute().actionGet().getState(); |
| 206 | + |
| 207 | + // Validate that the remote_store custom data is not present in index metadata for the restored index. |
| 208 | + assertNull(state.metadata().index(restoredIndexName1).getCustomData(IndexMetadata.REMOTE_STORE_CUSTOM_KEY)); |
| 209 | + } |
| 210 | + |
154 | 211 | public void testParallelRestoreOperationsFromSingleSnapshot() throws Exception {
|
155 | 212 | String indexName1 = "testindex1";
|
156 | 213 | String indexName2 = "testindex2";
|
|
0 commit comments