Skip to content

Commit 2eba0ca

Browse files
committed
support scale down without search replica
Signed-off-by: guojialiang <guojialiang.2012@bytedance.com>
1 parent 06539a4 commit 2eba0ca

3 files changed

Lines changed: 30 additions & 39 deletions

File tree

server/src/internalClusterTest/java/org/opensearch/action/admin/indices/scale/searchonly/ScaleIndexIT.java

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ public Settings indexSettings() {
4444
return Settings.builder().put(SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT).build();
4545
}
4646

47+
public void testFullLifecycleWithSearchReplica() throws Exception {
48+
testFullLifecycle(1);
49+
}
50+
51+
public void testFullLifecycleWithoutSearchReplicas() throws Exception {
52+
testFullLifecycle(0);
53+
}
54+
4755
/**
4856
* Tests the full lifecycle of scaling an index down to search-only mode,
4957
* scaling search replicas while in search-only mode, verifying cluster health in
5058
* various states, and then scaling back up to normal mode.
5159
*/
52-
public void testFullSearchOnlyReplicasFullLifecycle() throws Exception {
60+
private void testFullLifecycle(int searchOnlyReplica) throws Exception {
5361
internalCluster().startClusterManagerOnlyNode();
5462
internalCluster().startDataOnlyNodes(2);
5563
internalCluster().startSearchOnlyNodes(3);
@@ -58,7 +66,7 @@ public void testFullSearchOnlyReplicasFullLifecycle() throws Exception {
5866
.put(indexSettings())
5967
.put(SETTING_NUMBER_OF_SHARDS, 1)
6068
.put(SETTING_NUMBER_OF_REPLICAS, 1)
61-
.put(SETTING_NUMBER_OF_SEARCH_REPLICAS, 1)
69+
.put(SETTING_NUMBER_OF_SEARCH_REPLICAS, searchOnlyReplica)
6270
.build();
6371

6472
createIndex(TEST_INDEX, specificSettings);
@@ -76,7 +84,15 @@ public void testFullSearchOnlyReplicasFullLifecycle() throws Exception {
7684
assertBusy(() -> {
7785
SearchResponse searchResponse = client().prepareSearch(TEST_INDEX).get();
7886
assertHitCount(searchResponse, 10);
79-
assertSearchNodeDocCounts(10, TEST_INDEX);
87+
if (searchOnlyReplica > 0) {
88+
assertSearchNodeDocCounts(10, TEST_INDEX);
89+
} else {
90+
try {
91+
client().prepareSearch(TEST_INDEX).setSize(0).get();
92+
} catch (Exception e) {
93+
assertTrue(e.getMessage().contains("all shards failed"));
94+
}
95+
}
8096
}, 30, TimeUnit.SECONDS);
8197

8298
ensureGreen(TEST_INDEX);
@@ -108,6 +124,16 @@ public void testFullSearchOnlyReplicasFullLifecycle() throws Exception {
108124

109125
ensureGreen(TEST_INDEX);
110126

127+
assertAcked(
128+
client().admin()
129+
.indices()
130+
.prepareUpdateSettings(TEST_INDEX)
131+
.setSettings(Settings.builder().put(SETTING_NUMBER_OF_SEARCH_REPLICAS, 1).build())
132+
.get()
133+
);
134+
135+
ensureGreen(TEST_INDEX);
136+
111137
// Verify search still works on all search nodes
112138
assertSearchNodeDocCounts(10, TEST_INDEX);
113139

@@ -179,34 +205,6 @@ public void testFullSearchOnlyReplicasFullLifecycle() throws Exception {
179205
});
180206
}
181207

182-
/**
183-
* Tests scaling down an index to search-only mode when there are no search replicas.
184-
*/
185-
public void testScaleDownValidationWithoutSearchReplicas() {
186-
internalCluster().startClusterManagerOnlyNode();
187-
internalCluster().startDataOnlyNodes(2);
188-
internalCluster().startSearchOnlyNode();
189-
190-
Settings specificSettings = Settings.builder()
191-
.put(indexSettings())
192-
.put(SETTING_NUMBER_OF_SHARDS, 2)
193-
.put(SETTING_NUMBER_OF_REPLICAS, 1)
194-
.build();
195-
196-
createIndex(TEST_INDEX, specificSettings);
197-
ensureYellow(TEST_INDEX);
198-
199-
IllegalArgumentException exception = expectThrows(
200-
IllegalArgumentException.class,
201-
() -> client().admin().indices().prepareScaleSearchOnly(TEST_INDEX, true).get()
202-
);
203-
204-
assertTrue(
205-
"Expected error about missing search replicas",
206-
exception.getMessage().contains("Cannot scale to zero without search replicas for index:")
207-
);
208-
}
209-
210208
/**
211209
* Scenario 1: Tests search-only replicas recovery with persistent data directory
212210
* and cluster.remote_store.state.enabled=false

server/src/main/java/org/opensearch/action/admin/indices/scale/searchonly/ScaleIndexOperationValidator.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ boolean validateScalePrerequisites(
6262
throw new IllegalStateException("Index [" + index + "] is already in search-only mode");
6363
}
6464

65-
if (indexMetadata.getNumberOfSearchOnlyReplicas() == 0) {
66-
throw new IllegalArgumentException("Cannot scale to zero without search replicas for index: " + index);
67-
}
6865
if (indexMetadata.getSettings().getAsBoolean(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false) == false) {
6966
throw new IllegalArgumentException(
7067
"To scale to zero, " + IndexMetadata.SETTING_REMOTE_STORE_ENABLED + " must be enabled for index: " + index

server/src/main/java/org/opensearch/cluster/health/ClusterShardHealth.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,7 @@ public static ClusterHealthStatus getShardHealth(
266266

267267
if (primaryRouting == null) {
268268
if (isSearchOnlyClusterBlockEnabled) {
269-
if (activeShards == 0) {
270-
return ClusterHealthStatus.RED;
271-
} else {
272-
return (activeShards < totalShards) ? ClusterHealthStatus.YELLOW : ClusterHealthStatus.GREEN;
273-
}
269+
return (activeShards < totalShards) ? ClusterHealthStatus.YELLOW : ClusterHealthStatus.GREEN;
274270
} else {
275271
return ClusterHealthStatus.RED;
276272
}

0 commit comments

Comments
 (0)