|
| 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 com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; |
| 12 | + |
| 13 | +import org.apache.lucene.store.Directory; |
| 14 | +import org.apache.lucene.store.FilterDirectory; |
| 15 | +import org.opensearch.action.admin.indices.delete.DeleteIndexRequest; |
| 16 | +import org.opensearch.action.admin.indices.get.GetIndexRequest; |
| 17 | +import org.opensearch.action.admin.indices.get.GetIndexResponse; |
| 18 | +import org.opensearch.action.search.SearchResponse; |
| 19 | +import org.opensearch.cluster.metadata.IndexMetadata; |
| 20 | +import org.opensearch.common.settings.Settings; |
| 21 | +import org.opensearch.common.settings.SettingsException; |
| 22 | +import org.opensearch.common.util.FeatureFlags; |
| 23 | +import org.opensearch.index.IndexModule; |
| 24 | +import org.opensearch.index.query.QueryBuilders; |
| 25 | +import org.opensearch.index.shard.IndexShard; |
| 26 | +import org.opensearch.index.store.CompositeDirectory; |
| 27 | +import org.opensearch.index.store.remote.file.CleanerDaemonThreadLeakFilter; |
| 28 | +import org.opensearch.index.store.remote.filecache.FileCache; |
| 29 | +import org.opensearch.index.store.remote.utils.FileTypeUtils; |
| 30 | +import org.opensearch.indices.IndicesService; |
| 31 | +import org.opensearch.node.Node; |
| 32 | +import org.opensearch.test.InternalTestCluster; |
| 33 | +import org.opensearch.test.OpenSearchIntegTestCase; |
| 34 | + |
| 35 | +import java.util.Arrays; |
| 36 | +import java.util.HashSet; |
| 37 | +import java.util.Set; |
| 38 | +import java.util.stream.Collectors; |
| 39 | + |
| 40 | +import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; |
| 41 | +import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount; |
| 42 | + |
| 43 | +@ThreadLeakFilters(filters = CleanerDaemonThreadLeakFilter.class) |
| 44 | +@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, supportsDedicatedMasters = false) |
| 45 | +// Uncomment the below line to enable trace level logs for this test for better debugging |
| 46 | +// @TestLogging(reason = "Getting trace logs from composite directory package", value = "org.opensearch.index.store:TRACE") |
| 47 | +public class WritableWarmIT extends RemoteStoreBaseIntegTestCase { |
| 48 | + |
| 49 | + protected static final String INDEX_NAME = "test-idx-1"; |
| 50 | + protected static final int NUM_DOCS_IN_BULK = 1000; |
| 51 | + |
| 52 | + /* |
| 53 | + Disabling MockFSIndexStore plugin as the MockFSDirectoryFactory wraps the FSDirectory over a OpenSearchMockDirectoryWrapper which extends FilterDirectory (whereas FSDirectory extends BaseDirectory) |
| 54 | + As a result of this wrapping the local directory of Composite Directory does not satisfy the assertion that local directory must be of type FSDirectory |
| 55 | + */ |
| 56 | + @Override |
| 57 | + protected boolean addMockIndexStorePlugin() { |
| 58 | + return false; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + protected Settings featureFlagSettings() { |
| 63 | + Settings.Builder featureSettings = Settings.builder(); |
| 64 | + featureSettings.put(FeatureFlags.TIERED_REMOTE_INDEX, true); |
| 65 | + return featureSettings.build(); |
| 66 | + } |
| 67 | + |
| 68 | + public void testWritableWarmFeatureFlagDisabled() { |
| 69 | + Settings clusterSettings = Settings.builder().put(super.nodeSettings(0)).put(FeatureFlags.TIERED_REMOTE_INDEX, false).build(); |
| 70 | + InternalTestCluster internalTestCluster = internalCluster(); |
| 71 | + internalTestCluster.startClusterManagerOnlyNode(clusterSettings); |
| 72 | + internalTestCluster.startDataOnlyNode(clusterSettings); |
| 73 | + |
| 74 | + Settings indexSettings = Settings.builder() |
| 75 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) |
| 76 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) |
| 77 | + .put(IndexModule.INDEX_STORE_LOCALITY_SETTING.getKey(), IndexModule.DataLocalityType.PARTIAL.name()) |
| 78 | + .build(); |
| 79 | + |
| 80 | + try { |
| 81 | + prepareCreate(INDEX_NAME).setSettings(indexSettings).get(); |
| 82 | + fail("Should have thrown Exception as setting should not be registered if Feature Flag is Disabled"); |
| 83 | + } catch (SettingsException ex) { |
| 84 | + assertEquals( |
| 85 | + "unknown setting [" |
| 86 | + + IndexModule.INDEX_STORE_LOCALITY_SETTING.getKey() |
| 87 | + + "] please check that any required plugins are installed, or check the " |
| 88 | + + "breaking changes documentation for removed settings", |
| 89 | + ex.getMessage() |
| 90 | + ); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + public void testWritableWarmBasic() throws Exception { |
| 95 | + InternalTestCluster internalTestCluster = internalCluster(); |
| 96 | + internalTestCluster.startClusterManagerOnlyNode(); |
| 97 | + internalTestCluster.startDataOnlyNode(); |
| 98 | + Settings settings = Settings.builder() |
| 99 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) |
| 100 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) |
| 101 | + .put(IndexModule.INDEX_STORE_LOCALITY_SETTING.getKey(), IndexModule.DataLocalityType.PARTIAL.name()) |
| 102 | + .build(); |
| 103 | + assertAcked(client().admin().indices().prepareCreate(INDEX_NAME).setSettings(settings).get()); |
| 104 | + |
| 105 | + // Verify from the cluster settings if the data locality is partial |
| 106 | + GetIndexResponse getIndexResponse = client().admin() |
| 107 | + .indices() |
| 108 | + .getIndex(new GetIndexRequest().indices(INDEX_NAME).includeDefaults(true)) |
| 109 | + .get(); |
| 110 | + Settings indexSettings = getIndexResponse.settings().get(INDEX_NAME); |
| 111 | + assertEquals(IndexModule.DataLocalityType.PARTIAL.name(), indexSettings.get(IndexModule.INDEX_STORE_LOCALITY_SETTING.getKey())); |
| 112 | + |
| 113 | + // Ingesting some docs |
| 114 | + indexBulk(INDEX_NAME, NUM_DOCS_IN_BULK); |
| 115 | + flushAndRefresh(INDEX_NAME); |
| 116 | + |
| 117 | + // ensuring cluster is green after performing force-merge |
| 118 | + ensureGreen(); |
| 119 | + |
| 120 | + SearchResponse searchResponse = client().prepareSearch(INDEX_NAME).setQuery(QueryBuilders.matchAllQuery()).get(); |
| 121 | + // Asserting that search returns same number of docs as ingested |
| 122 | + assertHitCount(searchResponse, NUM_DOCS_IN_BULK); |
| 123 | + |
| 124 | + // Ingesting docs again before force merge |
| 125 | + indexBulk(INDEX_NAME, NUM_DOCS_IN_BULK); |
| 126 | + flushAndRefresh(INDEX_NAME); |
| 127 | + |
| 128 | + FileCache fileCache = internalTestCluster.getDataNodeInstance(Node.class).fileCache(); |
| 129 | + IndexShard shard = internalTestCluster.getDataNodeInstance(IndicesService.class) |
| 130 | + .indexService(resolveIndex(INDEX_NAME)) |
| 131 | + .getShardOrNull(0); |
| 132 | + Directory directory = (((FilterDirectory) (((FilterDirectory) (shard.store().directory())).getDelegate())).getDelegate()); |
| 133 | + |
| 134 | + // Force merging the index |
| 135 | + Set<String> filesBeforeMerge = new HashSet<>(Arrays.asList(directory.listAll())); |
| 136 | + client().admin().indices().prepareForceMerge(INDEX_NAME).setMaxNumSegments(1).get(); |
| 137 | + flushAndRefresh(INDEX_NAME); |
| 138 | + Set<String> filesAfterMerge = new HashSet<>(Arrays.asList(directory.listAll())); |
| 139 | + |
| 140 | + Set<String> filesFromPreviousGenStillPresent = filesBeforeMerge.stream() |
| 141 | + .filter(filesAfterMerge::contains) |
| 142 | + .filter(file -> !FileTypeUtils.isLockFile(file)) |
| 143 | + .filter(file -> !FileTypeUtils.isSegmentsFile(file)) |
| 144 | + .collect(Collectors.toUnmodifiableSet()); |
| 145 | + |
| 146 | + // Asserting that after merge all the files from previous gen are no more part of the directory |
| 147 | + assertTrue(filesFromPreviousGenStillPresent.isEmpty()); |
| 148 | + |
| 149 | + // Asserting that files from previous gen are not present in File Cache as well |
| 150 | + filesBeforeMerge.stream() |
| 151 | + .filter(file -> !FileTypeUtils.isLockFile(file)) |
| 152 | + .filter(file -> !FileTypeUtils.isSegmentsFile(file)) |
| 153 | + .forEach(file -> assertNull(fileCache.get(((CompositeDirectory) directory).getFilePath(file)))); |
| 154 | + |
| 155 | + // Deleting the index (so that ref count drops to zero for all the files) and then pruning the cache to clear it to avoid any file |
| 156 | + // leaks |
| 157 | + assertAcked(client().admin().indices().delete(new DeleteIndexRequest(INDEX_NAME)).get()); |
| 158 | + fileCache.prune(); |
| 159 | + } |
| 160 | +} |
0 commit comments