|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.opensearch.remotestore; |
| 10 | + |
| 11 | +import org.opensearch.action.admin.indices.delete.DeleteIndexRequest; |
| 12 | +import org.opensearch.cluster.metadata.IndexMetadata; |
| 13 | +import org.opensearch.common.settings.Settings; |
| 14 | +import org.opensearch.core.util.FileSystemUtils; |
| 15 | +import org.opensearch.index.remote.RemoteIndexPath; |
| 16 | +import org.opensearch.index.remote.RemoteStoreEnums; |
| 17 | +import org.opensearch.test.OpenSearchIntegTestCase; |
| 18 | + |
| 19 | +import java.io.IOException; |
| 20 | +import java.util.Locale; |
| 21 | +import java.util.concurrent.ExecutionException; |
| 22 | + |
| 23 | +import static org.opensearch.gateway.remote.RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING; |
| 24 | +import static org.opensearch.indices.RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING; |
| 25 | +import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; |
| 26 | + |
| 27 | +@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) |
| 28 | +public class RemoteStoreUploadIndexPathIT extends RemoteStoreBaseIntegTestCase { |
| 29 | + |
| 30 | + private final String INDEX_NAME = "remote-store-test-idx-1"; |
| 31 | + |
| 32 | + @Override |
| 33 | + protected Settings nodeSettings(int nodeOrdinal) { |
| 34 | + return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true).build(); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Checks that the remote index path file gets created for the intended remote store path type and does not get created |
| 39 | + * wherever not required. |
| 40 | + */ |
| 41 | + public void testRemoteIndexPathFileCreation() throws ExecutionException, InterruptedException, IOException { |
| 42 | + String clusterManagerNode = internalCluster().startClusterManagerOnlyNode(); |
| 43 | + internalCluster().startDataOnlyNodes(2); |
| 44 | + |
| 45 | + // Case 1 - Hashed_prefix, we would need the remote index path file to be created. |
| 46 | + client(clusterManagerNode).admin() |
| 47 | + .cluster() |
| 48 | + .prepareUpdateSettings() |
| 49 | + .setTransientSettings( |
| 50 | + Settings.builder().put(CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING.getKey(), RemoteStoreEnums.PathType.HASHED_PREFIX) |
| 51 | + ) |
| 52 | + .get(); |
| 53 | + |
| 54 | + createIndex(INDEX_NAME, remoteStoreIndexSettings(0, 1)); |
| 55 | + validateRemoteIndexPathFile(true); |
| 56 | + assertAcked(client().admin().indices().delete(new DeleteIndexRequest(INDEX_NAME)).get()); |
| 57 | + FileSystemUtils.deleteSubDirectories(translogRepoPath); |
| 58 | + FileSystemUtils.deleteSubDirectories(segmentRepoPath); |
| 59 | + |
| 60 | + // Case 2 - Hashed_infix, we would not have the remote index path file created here. |
| 61 | + client(clusterManagerNode).admin() |
| 62 | + .cluster() |
| 63 | + .prepareUpdateSettings() |
| 64 | + .setTransientSettings( |
| 65 | + Settings.builder().put(CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING.getKey(), RemoteStoreEnums.PathType.HASHED_INFIX) |
| 66 | + ) |
| 67 | + .get(); |
| 68 | + createIndex(INDEX_NAME, remoteStoreIndexSettings(0, 1)); |
| 69 | + validateRemoteIndexPathFile(false); |
| 70 | + assertAcked(client().admin().indices().delete(new DeleteIndexRequest(INDEX_NAME)).get()); |
| 71 | + |
| 72 | + // Case 3 - fixed, we would not have the remote index path file created here either. |
| 73 | + client(clusterManagerNode).admin() |
| 74 | + .cluster() |
| 75 | + .prepareUpdateSettings() |
| 76 | + .setTransientSettings(Settings.builder().put(CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING.getKey(), RemoteStoreEnums.PathType.FIXED)) |
| 77 | + .get(); |
| 78 | + createIndex(INDEX_NAME, remoteStoreIndexSettings(0, 1)); |
| 79 | + validateRemoteIndexPathFile(false); |
| 80 | + assertAcked(client().admin().indices().delete(new DeleteIndexRequest(INDEX_NAME)).get()); |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + private void validateRemoteIndexPathFile(boolean exists) { |
| 85 | + String indexUUID = client().admin() |
| 86 | + .indices() |
| 87 | + .prepareGetSettings(INDEX_NAME) |
| 88 | + .get() |
| 89 | + .getSetting(INDEX_NAME, IndexMetadata.SETTING_INDEX_UUID); |
| 90 | + |
| 91 | + assertEquals(exists, FileSystemUtils.exists(translogRepoPath.resolve(RemoteIndexPath.DIR))); |
| 92 | + assertEquals( |
| 93 | + exists, |
| 94 | + FileSystemUtils.exists( |
| 95 | + translogRepoPath.resolve(RemoteIndexPath.DIR) |
| 96 | + .resolve(String.format(Locale.ROOT, RemoteIndexPath.FILE_NAME_FORMAT, indexUUID)) |
| 97 | + ) |
| 98 | + ); |
| 99 | + assertEquals(exists, FileSystemUtils.exists(segmentRepoPath.resolve(RemoteIndexPath.DIR))); |
| 100 | + assertEquals( |
| 101 | + exists, |
| 102 | + FileSystemUtils.exists( |
| 103 | + segmentRepoPath.resolve(RemoteIndexPath.DIR) |
| 104 | + .resolve(String.format(Locale.ROOT, RemoteIndexPath.FILE_NAME_FORMAT, indexUUID)) |
| 105 | + ) |
| 106 | + ); |
| 107 | + } |
| 108 | +} |
0 commit comments