Skip to content

Commit c4a9cfb

Browse files
Gagan6164gbbafna
authored andcommitted
Disallow resize for Warm Index, add Parameterized ITs for close in remote store (opensearch-project#18686)
Signed-off-by: Gagan Singh Saini <gagasa@amazon.com> Co-authored-by: Gaurav Bafna <gbbafna@amazon.com>
1 parent bc8de1c commit c4a9cfb

File tree

5 files changed

+143
-2
lines changed

5 files changed

+143
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
### Added
88
- Add support for Warm Indices Write Block on Flood Watermark breach ([#18375](https://github.com/opensearch-project/OpenSearch/pull/18375))
99
- Add support for custom index name resolver from cluster plugin ([#18593](https://github.com/opensearch-project/OpenSearch/pull/18593))
10+
- Disallow resize for Warm Index, add Parameterized ITs for close in remote store ([#18686](https://github.com/opensearch-project/OpenSearch/pull/18686))
1011
- Ability to run Code Coverage with Gradle and produce the jacoco reports locally ([#18509](https://github.com/opensearch-project/OpenSearch/issues/18509))
1112
- Add NodeResourceUsageStats to ClusterInfo ([#18480](https://github.com/opensearch-project/OpenSearch/issues/18472))
1213
- Introduce SecureHttpTransportParameters experimental API (to complement SecureTransportParameters counterpart) ([#18572](https://github.com/opensearch-project/OpenSearch/issues/18572))

server/src/internalClusterTest/java/org/opensearch/indices/state/CloseIndexIT.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
package org.opensearch.indices.state;
3434

35+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
36+
3537
import org.opensearch.ExceptionsHelper;
3638
import org.opensearch.action.ActionRequestValidationException;
3739
import org.opensearch.action.admin.indices.close.CloseIndexRequestBuilder;
@@ -56,11 +58,13 @@
5658
import org.opensearch.indices.recovery.RecoveryState;
5759
import org.opensearch.test.BackgroundIndexer;
5860
import org.opensearch.test.InternalTestCluster;
59-
import org.opensearch.test.OpenSearchIntegTestCase;
61+
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;
6062
import org.opensearch.transport.client.Client;
6163

6264
import java.util.ArrayList;
6365
import java.util.Arrays;
66+
import java.util.Collection;
67+
import java.util.Collections;
6468
import java.util.List;
6569
import java.util.Locale;
6670
import java.util.concurrent.CountDownLatch;
@@ -70,6 +74,7 @@
7074
import static java.util.Collections.emptySet;
7175
import static java.util.stream.Collectors.toList;
7276
import static org.opensearch.action.support.IndicesOptions.lenientExpandOpen;
77+
import static org.opensearch.search.SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING;
7378
import static org.opensearch.search.internal.SearchContext.TRACK_TOTAL_HITS_ACCURATE;
7479
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
7580
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
@@ -82,10 +87,23 @@
8287
import static org.hamcrest.Matchers.notNullValue;
8388
import static org.hamcrest.Matchers.nullValue;
8489

85-
public class CloseIndexIT extends OpenSearchIntegTestCase {
90+
public class CloseIndexIT extends ParameterizedStaticSettingsOpenSearchIntegTestCase {
8691

8792
private static final int MAX_DOCS = 25_000;
8893

94+
public CloseIndexIT(Settings nodeSettings) {
95+
super(nodeSettings);
96+
}
97+
98+
// This is to reuse CloseIndexIT in RemoteCloseIndexIT .
99+
// Concurrent search deosn't make a difference in these tests.
100+
@ParametersFactory
101+
public static Collection<Object[]> parameters() {
102+
return Collections.singletonList(
103+
new Object[] { Settings.builder().put(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING.getKey(), false).build() }
104+
);
105+
}
106+
89107
@Override
90108
public Settings indexSettings() {
91109
return Settings.builder()
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.state;
10+
11+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
12+
13+
import org.opensearch.cluster.metadata.IndexMetadata;
14+
import org.opensearch.common.settings.Settings;
15+
import org.opensearch.core.common.unit.ByteSizeUnit;
16+
import org.opensearch.core.common.unit.ByteSizeValue;
17+
import org.opensearch.index.IndexModule;
18+
import org.opensearch.index.IndexSettings;
19+
import org.opensearch.node.Node;
20+
21+
import java.nio.file.Path;
22+
import java.util.Arrays;
23+
import java.util.Collection;
24+
25+
import static org.opensearch.common.util.FeatureFlags.WRITABLE_WARM_INDEX_SETTING;
26+
27+
public class RemoteCloseIndexIT extends CloseIndexIT {
28+
29+
public RemoteCloseIndexIT(Settings nodeSettings) {
30+
super(nodeSettings);
31+
}
32+
33+
protected Path remoteRepoPath;
34+
35+
protected final static String TEST_REMOTE_STORE_REPO_SUFFIX = "__rs";
36+
protected static final String BASE_REMOTE_REPO = "test-rs-repo" + TEST_REMOTE_STORE_REPO_SUFFIX;
37+
38+
@Override
39+
protected Settings nodeSettings(int nodeOrdinal) {
40+
if (remoteRepoPath == null) {
41+
remoteRepoPath = randomRepoPath().toAbsolutePath();
42+
}
43+
ByteSizeValue cacheSize = new ByteSizeValue(16, ByteSizeUnit.GB);
44+
return Settings.builder()
45+
.put(super.nodeSettings(nodeOrdinal))
46+
.put(remoteStoreClusterSettings(BASE_REMOTE_REPO, remoteRepoPath))
47+
.put(Node.NODE_SEARCH_CACHE_SIZE_SETTING.getKey(), cacheSize.toString())
48+
.build();
49+
}
50+
51+
protected Settings.Builder getIndexSettings(int numOfShards, int numOfReplicas) {
52+
Settings.Builder settingsBuilder = Settings.builder()
53+
.put(super.indexSettings())
54+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numOfShards)
55+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numOfReplicas)
56+
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "300s");
57+
if (WRITABLE_WARM_INDEX_SETTING.get(settings)) {
58+
settingsBuilder.put(IndexModule.IS_WARM_INDEX_SETTING.getKey(), true);
59+
}
60+
return settingsBuilder;
61+
}
62+
63+
@ParametersFactory
64+
public static Collection<Object[]> parameters() {
65+
return Arrays.asList(
66+
new Object[] { Settings.builder().put(WRITABLE_WARM_INDEX_SETTING.getKey(), true).build() },
67+
new Object[] { Settings.builder().put(WRITABLE_WARM_INDEX_SETTING.getKey(), false).build() }
68+
);
69+
}
70+
71+
void assertNoFileBasedRecovery(String indexName) {
72+
// skipping for remote store
73+
}
74+
}

server/src/internalClusterTest/java/org/opensearch/remotestore/WritableWarmIT.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.opensearch.action.admin.indices.delete.DeleteIndexRequest;
1919
import org.opensearch.action.admin.indices.get.GetIndexRequest;
2020
import org.opensearch.action.admin.indices.get.GetIndexResponse;
21+
import org.opensearch.action.admin.indices.shrink.ResizeType;
2122
import org.opensearch.action.search.SearchResponse;
2223
import org.opensearch.cluster.metadata.IndexMetadata;
2324
import org.opensearch.common.settings.Settings;
@@ -34,9 +35,11 @@
3435
import org.opensearch.index.store.remote.filecache.FileCache;
3536
import org.opensearch.index.store.remote.utils.FileTypeUtils;
3637
import org.opensearch.indices.IndicesService;
38+
import org.opensearch.indices.replication.common.ReplicationType;
3739
import org.opensearch.node.Node;
3840
import org.opensearch.test.InternalTestCluster;
3941
import org.opensearch.test.OpenSearchIntegTestCase;
42+
import org.junit.Assert;
4043

4144
import java.util.Arrays;
4245
import java.util.HashSet;
@@ -45,8 +48,11 @@
4548
import java.util.concurrent.ExecutionException;
4649
import java.util.stream.Collectors;
4750

51+
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
52+
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
4853
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
4954
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
55+
import static org.hamcrest.core.StringContains.containsString;
5056

5157
@ThreadLeakFilters(filters = CleanerDaemonThreadLeakFilter.class)
5258
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, supportsDedicatedMasters = false)
@@ -247,4 +253,41 @@ public void testFullFileAndFileCacheStats() throws ExecutionException, Interrupt
247253
private boolean isFileCacheEmpty(AggregateFileCacheStats stats) {
248254
return stats.getUsed().getBytes() == 0L && stats.getActive().getBytes() == 0L;
249255
}
256+
257+
public void testNoResizeOnWarm() {
258+
InternalTestCluster internalTestCluster = internalCluster();
259+
internalTestCluster.startClusterManagerOnlyNode();
260+
internalCluster().startDataAndWarmNodes(1).get(0);
261+
Settings idxSettings = Settings.builder()
262+
.put(super.indexSettings())
263+
.put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), false)
264+
.put(SETTING_NUMBER_OF_REPLICAS, 0)
265+
.put(SETTING_NUMBER_OF_SHARDS, 2)
266+
.put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT)
267+
.put(IndexModule.IS_WARM_INDEX_SETTING.getKey(), true)
268+
.build();
269+
270+
createIndex(INDEX_NAME, idxSettings);
271+
ensureYellowAndNoInitializingShards(INDEX_NAME);
272+
ensureGreen(INDEX_NAME);
273+
client().admin().indices().prepareUpdateSettings(INDEX_NAME).setSettings(Settings.builder().put("index.blocks.write", true)).get();
274+
ResizeType type = randomFrom(ResizeType.CLONE, ResizeType.SHRINK, ResizeType.SPLIT);
275+
try {
276+
client().admin()
277+
.indices()
278+
.prepareResizeIndex(INDEX_NAME, "target")
279+
.setResizeType(type)
280+
.setSettings(
281+
Settings.builder()
282+
.put("index.number_of_replicas", 0)
283+
.put("index.number_of_shards", 2)
284+
.putNull("index.blocks.write")
285+
.build()
286+
)
287+
.get();
288+
fail();
289+
} catch (Exception e) {
290+
Assert.assertThat(e.getMessage(), containsString("cannot resize warm index"));
291+
}
292+
}
250293
}

server/src/main/java/org/opensearch/action/admin/indices/shrink/TransportResizeAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.opensearch.core.common.io.stream.StreamInput;
5454
import org.opensearch.core.common.unit.ByteSizeValue;
5555
import org.opensearch.core.index.shard.ShardId;
56+
import org.opensearch.index.IndexModule;
5657
import org.opensearch.index.IndexNotFoundException;
5758
import org.opensearch.index.IndexSettings;
5859
import org.opensearch.index.shard.DocsStats;
@@ -146,6 +147,10 @@ protected void clusterManagerOperation(
146147
final String sourceIndex = indexNameExpressionResolver.resolveDateMathExpression(resizeRequest.getSourceIndex());
147148
final String targetIndex = indexNameExpressionResolver.resolveDateMathExpression(resizeRequest.getTargetIndexRequest().index());
148149
IndexMetadata indexMetadata = state.metadata().index(sourceIndex);
150+
if (indexMetadata.getSettings().getAsBoolean(IndexModule.IS_WARM_INDEX_SETTING.getKey(), false) == true) {
151+
throw new IllegalStateException("cannot resize warm index");
152+
}
153+
149154
ClusterSettings clusterSettings = clusterService.getClusterSettings();
150155
if (resizeRequest.getResizeType().equals(ResizeType.SHRINK)
151156
&& state.metadata().isSegmentReplicationEnabled(sourceIndex)

0 commit comments

Comments
 (0)