|
| 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.tiering; |
| 10 | + |
| 11 | +import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; |
| 12 | + |
| 13 | +import org.opensearch.action.admin.indices.get.GetIndexResponse; |
| 14 | +import org.opensearch.action.admin.indices.tiering.HotToWarmTieringAction; |
| 15 | +import org.opensearch.action.admin.indices.tiering.HotToWarmTieringResponse; |
| 16 | +import org.opensearch.action.admin.indices.tiering.TieringIndexRequest; |
| 17 | +import org.opensearch.action.search.SearchResponse; |
| 18 | +import org.opensearch.cluster.ClusterInfoService; |
| 19 | +import org.opensearch.cluster.MockInternalClusterInfoService; |
| 20 | +import org.opensearch.cluster.metadata.IndexMetadata; |
| 21 | +import org.opensearch.common.settings.Settings; |
| 22 | +import org.opensearch.common.util.FeatureFlags; |
| 23 | +import org.opensearch.core.common.unit.ByteSizeUnit; |
| 24 | +import org.opensearch.core.common.unit.ByteSizeValue; |
| 25 | +import org.opensearch.index.IndexModule; |
| 26 | +import org.opensearch.index.query.QueryBuilders; |
| 27 | +import org.opensearch.index.store.remote.file.CleanerDaemonThreadLeakFilter; |
| 28 | +import org.opensearch.monitor.fs.FsInfo; |
| 29 | +import org.opensearch.plugins.Plugin; |
| 30 | +import org.opensearch.remotestore.RemoteStoreBaseIntegTestCase; |
| 31 | +import org.opensearch.test.OpenSearchIntegTestCase; |
| 32 | +import org.junit.Before; |
| 33 | + |
| 34 | +import java.util.Collection; |
| 35 | +import java.util.Collections; |
| 36 | +import java.util.Map; |
| 37 | + |
| 38 | +import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; |
| 39 | +import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount; |
| 40 | +import static org.hamcrest.Matchers.equalTo; |
| 41 | +import static org.hamcrest.Matchers.notNullValue; |
| 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 tiering package", value = |
| 47 | +// "org.opensearch.tiering:TRACE,org.opensearch.cluster.routing.allocation.decider:TRACE") |
| 48 | +public class HotToWarmTieringServiceIT extends RemoteStoreBaseIntegTestCase { |
| 49 | + |
| 50 | + protected static final String TEST_IDX_1 = "test-idx-1"; |
| 51 | + protected static final String TEST_IDX_2 = "test-idx-2"; |
| 52 | + protected static final String TARGET_TIER = "warm"; |
| 53 | + protected static final int NUM_DOCS_IN_BULK = 10; |
| 54 | + private static final long TOTAL_SPACE_BYTES = new ByteSizeValue(1000, ByteSizeUnit.KB).getBytes(); |
| 55 | + |
| 56 | + /* |
| 57 | + Disabling MockFSIndexStore plugin as the MockFSDirectoryFactory wraps the FSDirectory over a OpenSearchMockDirectoryWrapper which extends FilterDirectory (whereas FSDirectory extends BaseDirectory) |
| 58 | + 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 |
| 59 | + */ |
| 60 | + @Override |
| 61 | + protected boolean addMockIndexStorePlugin() { |
| 62 | + return false; |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + protected Collection<Class<? extends Plugin>> nodePlugins() { |
| 67 | + return Collections.singletonList(MockInternalClusterInfoService.TestPlugin.class); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + protected Settings featureFlagSettings() { |
| 72 | + Settings.Builder featureSettings = Settings.builder(); |
| 73 | + featureSettings.put(FeatureFlags.TIERED_REMOTE_INDEX, true); |
| 74 | + return featureSettings.build(); |
| 75 | + } |
| 76 | + |
| 77 | + @Before |
| 78 | + public void setup() { |
| 79 | + internalCluster().startClusterManagerOnlyNode(); |
| 80 | + } |
| 81 | + |
| 82 | + public void testTieringBasic() { |
| 83 | + final int numReplicasIndex = 0; |
| 84 | + internalCluster().ensureAtLeastNumDataNodes(1); |
| 85 | + final Settings settings = Settings.builder() |
| 86 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) |
| 87 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numReplicasIndex) |
| 88 | + .put(IndexModule.INDEX_STORE_LOCALITY_SETTING.getKey(), IndexModule.DataLocalityType.FULL.name()) |
| 89 | + .build(); |
| 90 | + |
| 91 | + String[] indices = new String[] { TEST_IDX_1, TEST_IDX_2 }; |
| 92 | + for (String index : indices) { |
| 93 | + assertAcked(client().admin().indices().prepareCreate(index).setSettings(settings).get()); |
| 94 | + ensureGreen(index); |
| 95 | + // Ingesting some docs |
| 96 | + indexBulk(index, NUM_DOCS_IN_BULK); |
| 97 | + flushAndRefresh(index); |
| 98 | + // ensuring cluster is green after performing force-merge |
| 99 | + ensureGreen(); |
| 100 | + SearchResponse searchResponse = client().prepareSearch(index).setQuery(QueryBuilders.matchAllQuery()).get(); |
| 101 | + // Asserting that search returns same number of docs as ingested |
| 102 | + assertHitCount(searchResponse, NUM_DOCS_IN_BULK); |
| 103 | + } |
| 104 | + |
| 105 | + // Spin up node having search role |
| 106 | + internalCluster().ensureAtLeastNumSearchAndDataNodes(1); |
| 107 | + |
| 108 | + final MockInternalClusterInfoService clusterInfoService = getMockInternalClusterInfoService(); |
| 109 | + clusterInfoService.setDiskUsageFunctionAndRefresh( |
| 110 | + (discoveryNode, fsInfoPath) -> setDiskUsage(fsInfoPath, TOTAL_SPACE_BYTES, TOTAL_SPACE_BYTES) |
| 111 | + ); |
| 112 | + |
| 113 | + TieringIndexRequest request = new TieringIndexRequest(TARGET_TIER, indices); |
| 114 | + request.waitForCompletion(true); |
| 115 | + HotToWarmTieringResponse response = client().admin().indices().execute(HotToWarmTieringAction.INSTANCE, request).actionGet(); |
| 116 | + assertAcked(response); |
| 117 | + assertTrue(response.getFailedIndices().isEmpty()); |
| 118 | + assertTrue(response.isAcknowledged()); |
| 119 | + ensureGreen(); |
| 120 | + for (String index : indices) { |
| 121 | + SearchResponse searchResponse = client().prepareSearch(index).setQuery(QueryBuilders.matchAllQuery()).get(); |
| 122 | + // Asserting that search returns same number of docs as ingested |
| 123 | + assertHitCount(searchResponse, NUM_DOCS_IN_BULK); |
| 124 | + GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().addIndices(index).get(); |
| 125 | + assertWarmSettings(getIndexResponse, index); |
| 126 | + assertAcked(client().admin().indices().prepareDelete(index).get()); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + private MockInternalClusterInfoService getMockInternalClusterInfoService() { |
| 131 | + return (MockInternalClusterInfoService) internalCluster().getCurrentClusterManagerNodeInstance(ClusterInfoService.class); |
| 132 | + } |
| 133 | + |
| 134 | + private static FsInfo.Path setDiskUsage(FsInfo.Path original, long totalBytes, long freeBytes) { |
| 135 | + return new FsInfo.Path(original.getPath(), original.getMount(), totalBytes, freeBytes, freeBytes); |
| 136 | + } |
| 137 | + |
| 138 | + private void assertWarmSettings(GetIndexResponse response, String indexName) { |
| 139 | + final Map<String, Settings> settings = response.settings(); |
| 140 | + assertThat(settings, notNullValue()); |
| 141 | + assertThat(settings.size(), equalTo(1)); |
| 142 | + Settings indexSettings = settings.get(indexName); |
| 143 | + assertThat(indexSettings, notNullValue()); |
| 144 | + assertThat( |
| 145 | + indexSettings.get(IndexModule.INDEX_STORE_LOCALITY_SETTING.getKey()), |
| 146 | + equalTo(IndexModule.DataLocalityType.PARTIAL.name()) |
| 147 | + ); |
| 148 | + assertThat(indexSettings.get(IndexModule.INDEX_TIERING_STATE.getKey()), equalTo(IndexModule.TieringState.WARM.name())); |
| 149 | + } |
| 150 | +} |
0 commit comments