1919import org .opensearch .common .Priority ;
2020import org .opensearch .common .settings .Settings ;
2121import org .opensearch .common .unit .TimeValue ;
22+ import org .opensearch .core .common .unit .ByteSizeValue ;
2223import org .opensearch .index .query .QueryBuilders ;
2324import org .opensearch .indices .recovery .RecoverySettings ;
2425import org .opensearch .plugins .Plugin ;
3839
3940@ OpenSearchIntegTestCase .ClusterScope (scope = OpenSearchIntegTestCase .Scope .TEST , numDataNodes = 0 )
4041public class RemotePrimaryRelocationIT extends MigrationBaseTestCase {
42+
43+ private final String INDEX_NAME = "primary-relocation" ;
44+
4145 protected int maximumNumberOfShards () {
4246 return 1 ;
4347 }
@@ -58,14 +62,14 @@ public void testRemotePrimaryRelocation() throws Exception {
5862 assertAcked (client ().admin ().cluster ().updateSettings (updateSettingsRequest ).actionGet ());
5963
6064 // create shard with 0 replica and 1 shard
61- client ().admin ().indices ().prepareCreate ("test" ).setSettings (indexSettings ()).setMapping ("field" , "type=text" ).get ();
62- ensureGreen ("test" );
65+ client ().admin ().indices ().prepareCreate (INDEX_NAME ).setSettings (indexSettings ()).setMapping ("field" , "type=text" ).get ();
66+ ensureGreen (INDEX_NAME );
6367
6468 AtomicInteger numAutoGenDocs = new AtomicInteger ();
6569 final AtomicBoolean finished = new AtomicBoolean (false );
66- AsyncIndexingService asyncIndexingService = new AsyncIndexingService ("test" );
70+ AsyncIndexingService asyncIndexingService = new AsyncIndexingService (INDEX_NAME );
6771 asyncIndexingService .startIndexing ();
68- refresh ("test" );
72+ refresh (INDEX_NAME );
6973
7074 // add remote node in mixed mode cluster
7175 setAddRemote (true );
@@ -86,7 +90,12 @@ public void testRemotePrimaryRelocation() throws Exception {
8690 // Index some more docs
8791 int currentDoc = numAutoGenDocs .get ();
8892 int finalCurrentDoc1 = currentDoc ;
89- waitUntil (() -> numAutoGenDocs .get () > finalCurrentDoc1 + 5 );
93+ waitUntil (() -> numAutoGenDocs .get () > finalCurrentDoc1 + 100 );
94+
95+ ByteSizeValue shardSize = client ().admin ().indices ().prepareStats (INDEX_NAME ).execute ().actionGet ().getShards ()[0 ].getStats ()
96+ .getStore ()
97+ .size ();
98+ slowDownRecovery (shardSize );
9099
91100 // Change direction to remote store
92101 updateSettingsRequest .persistentSettings (Settings .builder ().put (MIGRATION_DIRECTION_SETTING .getKey (), "remote_store" ));
@@ -96,7 +105,7 @@ public void testRemotePrimaryRelocation() throws Exception {
96105 client ().admin ()
97106 .cluster ()
98107 .prepareReroute ()
99- .add (new MoveAllocationCommand ("test" , 0 , primaryNodeName ("test" ), remoteNode ))
108+ .add (new MoveAllocationCommand (INDEX_NAME , 0 , primaryNodeName (INDEX_NAME ), remoteNode ))
100109 .execute ()
101110 .actionGet ();
102111 ClusterHealthResponse clusterHealthResponse = client ().admin ()
@@ -109,7 +118,7 @@ public void testRemotePrimaryRelocation() throws Exception {
109118 .actionGet ();
110119
111120 assertEquals (0 , clusterHealthResponse .getRelocatingShards ());
112- assertEquals (remoteNode , primaryNodeName ("test" ));
121+ assertEquals (remoteNode , primaryNodeName (INDEX_NAME ));
113122 logger .info ("--> relocation from docrep to remote complete" );
114123
115124 // Index some more docs
@@ -120,7 +129,7 @@ public void testRemotePrimaryRelocation() throws Exception {
120129 client ().admin ()
121130 .cluster ()
122131 .prepareReroute ()
123- .add (new MoveAllocationCommand ("test" , 0 , remoteNode , remoteNode2 ))
132+ .add (new MoveAllocationCommand (INDEX_NAME , 0 , remoteNode , remoteNode2 ))
124133 .execute ()
125134 .actionGet ();
126135 clusterHealthResponse = client ().admin ()
@@ -133,23 +142,23 @@ public void testRemotePrimaryRelocation() throws Exception {
133142 .actionGet ();
134143
135144 assertEquals (0 , clusterHealthResponse .getRelocatingShards ());
136- assertEquals (remoteNode2 , primaryNodeName ("test" ));
145+ assertEquals (remoteNode2 , primaryNodeName (INDEX_NAME ));
137146
138147 logger .info ("--> relocation from remote to remote complete" );
139148
140149 finished .set (true );
141150 asyncIndexingService .stopIndexing ();
142- refresh ("test" );
151+ refresh (INDEX_NAME );
143152 OpenSearchAssertions .assertHitCount (
144- client ().prepareSearch ("test" ).setTrackTotalHits (true ).get (),
153+ client ().prepareSearch (INDEX_NAME ).setTrackTotalHits (true ).get (),
145154 asyncIndexingService .getIndexedDocs ()
146155 );
147156 OpenSearchAssertions .assertHitCount (
148- client ().prepareSearch ("test" )
157+ client ().prepareSearch (INDEX_NAME )
149158 .setTrackTotalHits (true )// extra paranoia ;)
150159 .setQuery (QueryBuilders .termQuery ("auto" , true ))
151160 .get (),
152- asyncIndexingService .getIndexedDocs ()
161+ asyncIndexingService .getSingleIndexedDocs ()
153162 );
154163 }
155164
@@ -161,13 +170,13 @@ public void testMixedModeRelocation_RemoteSeedingFail() throws Exception {
161170 assertAcked (client ().admin ().cluster ().updateSettings (updateSettingsRequest ).actionGet ());
162171
163172 // create shard with 0 replica and 1 shard
164- client ().admin ().indices ().prepareCreate ("test" ).setSettings (indexSettings ()).setMapping ("field" , "type=text" ).get ();
165- ensureGreen ("test" );
173+ client ().admin ().indices ().prepareCreate (INDEX_NAME ).setSettings (indexSettings ()).setMapping ("field" , "type=text" ).get ();
174+ ensureGreen (INDEX_NAME );
166175
167- AsyncIndexingService asyncIndexingService = new AsyncIndexingService ("test" );
176+ AsyncIndexingService asyncIndexingService = new AsyncIndexingService (INDEX_NAME );
168177 asyncIndexingService .startIndexing ();
169178
170- refresh ("test" );
179+ refresh (INDEX_NAME );
171180
172181 // add remote node in mixed mode cluster
173182 setAddRemote (true );
@@ -186,7 +195,12 @@ public void testMixedModeRelocation_RemoteSeedingFail() throws Exception {
186195 assertAcked (client ().admin ().cluster ().updateSettings (updateSettingsRequest ).actionGet ());
187196
188197 logger .info ("--> relocating from {} to {} " , docRepNode , remoteNode );
189- client ().admin ().cluster ().prepareReroute ().add (new MoveAllocationCommand ("test" , 0 , docRepNode , remoteNode )).execute ().actionGet ();
198+ client ().admin ()
199+ .cluster ()
200+ .prepareReroute ()
201+ .add (new MoveAllocationCommand (INDEX_NAME , 0 , docRepNode , remoteNode ))
202+ .execute ()
203+ .actionGet ();
190204 ClusterHealthResponse clusterHealthResponse = client ().admin ()
191205 .cluster ()
192206 .prepareHealth ()
@@ -205,7 +219,7 @@ public void testMixedModeRelocation_RemoteSeedingFail() throws Exception {
205219 .waitForNoInitializingShards (true );
206220 ClusterHealthResponse actionGet = client ().admin ().cluster ().health (healthRequest ).actionGet ();
207221 assertEquals (actionGet .getRelocatingShards (), 0 );
208- assertEquals (docRepNode , primaryNodeName ("test" ));
222+ assertEquals (docRepNode , primaryNodeName (INDEX_NAME ));
209223
210224 asyncIndexingService .stopIndexing ();
211225 client ().admin ()
0 commit comments