@@ -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
0 commit comments