|
| 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.indices.replication; |
| 10 | + |
| 11 | +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX; |
| 12 | +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT; |
| 13 | + |
| 14 | +import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; |
| 15 | +import java.nio.file.Path; |
| 16 | +import java.util.Locale; |
| 17 | +import java.util.Map; |
| 18 | +import java.util.stream.Collectors; |
| 19 | +import org.junit.After; |
| 20 | +import org.junit.Before; |
| 21 | +import org.opensearch.cluster.metadata.RepositoriesMetadata; |
| 22 | +import org.opensearch.cluster.metadata.RepositoryMetadata; |
| 23 | +import org.opensearch.cluster.node.DiscoveryNode; |
| 24 | +import org.opensearch.cluster.service.ClusterService; |
| 25 | +import org.opensearch.common.settings.Settings; |
| 26 | +import org.opensearch.common.util.FeatureFlags; |
| 27 | +import org.opensearch.index.IndexModule; |
| 28 | +import org.opensearch.index.store.remote.file.CleanerDaemonThreadLeakFilter; |
| 29 | +import org.opensearch.index.store.remote.filecache.FileCache; |
| 30 | +import org.opensearch.node.Node; |
| 31 | +import org.opensearch.repositories.RepositoriesService; |
| 32 | +import org.opensearch.repositories.blobstore.BlobStoreRepository; |
| 33 | +import org.opensearch.test.OpenSearchIntegTestCase; |
| 34 | + |
| 35 | +@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) |
| 36 | +@ThreadLeakFilters(filters = CleanerDaemonThreadLeakFilter.class) |
| 37 | +public class WarmIndexRemoteStoreSegmentReplicationIT extends SegmentReplicationIT { |
| 38 | + |
| 39 | + protected static final String REPOSITORY_NAME = "test-remote-store-repo"; |
| 40 | + protected static final String REPOSITORY_2_NAME = "test-remote-store-repo-2"; |
| 41 | + |
| 42 | + protected Path segmentRepoPath; |
| 43 | + protected Path translogRepoPath; |
| 44 | + protected boolean clusterSettingsSuppliedByTest = false; |
| 45 | + |
| 46 | + @Before |
| 47 | + private void setup() { |
| 48 | + internalCluster().startClusterManagerOnlyNode(); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public Settings indexSettings() { |
| 53 | + return Settings.builder() |
| 54 | + .put(super.indexSettings()) |
| 55 | + .put(IndexModule.INDEX_STORE_LOCALITY_SETTING.getKey(), IndexModule.DataLocalityType.PARTIAL.name()) |
| 56 | + .build(); |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + protected Settings nodeSettings(int nodeOrdinal) { |
| 61 | + if (segmentRepoPath == null || translogRepoPath == null) { |
| 62 | + segmentRepoPath = randomRepoPath().toAbsolutePath(); |
| 63 | + translogRepoPath = randomRepoPath().toAbsolutePath(); |
| 64 | + } |
| 65 | + if (clusterSettingsSuppliedByTest) { |
| 66 | + return Settings.builder().put(super.nodeSettings(nodeOrdinal)).build(); |
| 67 | + } else { |
| 68 | + return Settings.builder() |
| 69 | + .put(super.nodeSettings(nodeOrdinal)) |
| 70 | + .put(remoteStoreClusterSettings(REPOSITORY_NAME, segmentRepoPath, REPOSITORY_2_NAME, translogRepoPath)) |
| 71 | + //.put(RemoteStoreSettings.CLUSTER_REMOTE_INDEX_SEGMENT_METADATA_RETENTION_MAX_COUNT_SETTING.getKey(), -1) |
| 72 | + .build(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + protected Settings featureFlagSettings() { |
| 78 | + Settings.Builder featureSettings = Settings.builder(); |
| 79 | + featureSettings.put(FeatureFlags.TIERED_REMOTE_INDEX, true); |
| 80 | + |
| 81 | + return featureSettings.build(); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + protected boolean addMockIndexStorePlugin() { |
| 86 | + return false; |
| 87 | + } |
| 88 | + |
| 89 | + protected boolean warmIndexSegmentReplicationEnabled() { |
| 90 | + return true; |
| 91 | + } |
| 92 | + |
| 93 | + @After |
| 94 | + public void teardown() { |
| 95 | + clusterSettingsSuppliedByTest = false; |
| 96 | + for (String nodeName : internalCluster().getNodeNames()) { |
| 97 | + logger.info("file cache node name is {}", nodeName); |
| 98 | + FileCache fileCache = internalCluster().getInstance(Node.class, nodeName).fileCache(); |
| 99 | + fileCache.clear(); |
| 100 | + } |
| 101 | + assertRemoteStoreRepositoryOnAllNodes(REPOSITORY_NAME); |
| 102 | + assertRemoteStoreRepositoryOnAllNodes(REPOSITORY_2_NAME); |
| 103 | + clusterAdmin().prepareCleanupRepository(REPOSITORY_NAME).get(); |
| 104 | + clusterAdmin().prepareCleanupRepository(REPOSITORY_2_NAME).get(); |
| 105 | + } |
| 106 | + |
| 107 | + public RepositoryMetadata buildRepositoryMetadata(DiscoveryNode node, String name) { |
| 108 | + Map<String, String> nodeAttributes = node.getAttributes(); |
| 109 | + String type = nodeAttributes.get(String.format(Locale.getDefault(), REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, name)); |
| 110 | + |
| 111 | + String settingsAttributeKeyPrefix = String.format(Locale.getDefault(), REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX, name); |
| 112 | + Map<String, String> settingsMap = node.getAttributes() |
| 113 | + .keySet() |
| 114 | + .stream() |
| 115 | + .filter(key -> key.startsWith(settingsAttributeKeyPrefix)) |
| 116 | + .collect(Collectors.toMap(key -> key.replace(settingsAttributeKeyPrefix, ""), key -> node.getAttributes().get(key))); |
| 117 | + |
| 118 | + Settings.Builder settings = Settings.builder(); |
| 119 | + settingsMap.entrySet().forEach(entry -> settings.put(entry.getKey(), entry.getValue())); |
| 120 | + settings.put(BlobStoreRepository.SYSTEM_REPOSITORY_SETTING.getKey(), true); |
| 121 | + |
| 122 | + return new RepositoryMetadata(name, type, settings.build()); |
| 123 | + } |
| 124 | + |
| 125 | + public void assertRemoteStoreRepositoryOnAllNodes(String repositoryName) { |
| 126 | + RepositoriesMetadata repositories = internalCluster().getInstance(ClusterService.class, internalCluster().getNodeNames()[0]) |
| 127 | + .state() |
| 128 | + .metadata() |
| 129 | + .custom(RepositoriesMetadata.TYPE); |
| 130 | + RepositoryMetadata actualRepository = repositories.repository(repositoryName); |
| 131 | + |
| 132 | + final RepositoriesService repositoriesService = internalCluster().getClusterManagerNodeInstance(RepositoriesService.class); |
| 133 | + final BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(repositoryName); |
| 134 | + |
| 135 | + for (String nodeName : internalCluster().getNodeNames()) { |
| 136 | + ClusterService clusterService = internalCluster().getInstance(ClusterService.class, nodeName); |
| 137 | + DiscoveryNode node = clusterService.localNode(); |
| 138 | + RepositoryMetadata expectedRepository = buildRepositoryMetadata(node, repositoryName); |
| 139 | + |
| 140 | + // Validated that all the restricted settings are entact on all the nodes. |
| 141 | + repository.getRestrictedSystemRepositorySettings() |
| 142 | + .stream() |
| 143 | + .forEach( |
| 144 | + setting -> assertEquals( |
| 145 | + String.format(Locale.ROOT, "Restricted Settings mismatch [%s]", setting.getKey()), |
| 146 | + setting.get(actualRepository.settings()), |
| 147 | + setting.get(expectedRepository.settings()) |
| 148 | + ) |
| 149 | + ); |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | +} |
0 commit comments