31
31
import org .junit .After ;
32
32
33
33
import java .nio .file .Path ;
34
- import java .util .List ;
35
34
import java .util .Set ;
36
35
import java .util .concurrent .ExecutionException ;
37
36
38
37
import static org .opensearch .cluster .metadata .IndexMetadata .SETTING_NUMBER_OF_REPLICAS ;
39
38
import static org .opensearch .cluster .metadata .IndexMetadata .SETTING_NUMBER_OF_SEARCH_REPLICAS ;
40
39
import static org .opensearch .cluster .routing .RecoverySource .Type .EMPTY_STORE ;
41
40
import static org .opensearch .cluster .routing .RecoverySource .Type .EXISTING_STORE ;
42
- import static org .opensearch .cluster .routing .allocation .decider .SearchReplicaAllocationDecider .SEARCH_REPLICA_ROUTING_INCLUDE_GROUP_SETTING ;
43
41
44
42
@ OpenSearchIntegTestCase .ClusterScope (scope = OpenSearchIntegTestCase .Scope .TEST , numDataNodes = 0 )
45
43
public class SearchReplicaReplicationAndRecoveryIT extends SegmentReplicationBaseIT {
@@ -84,20 +82,22 @@ public void testReplication() throws Exception {
84
82
final String primary = internalCluster ().startDataOnlyNode ();
85
83
createIndex (INDEX_NAME );
86
84
ensureYellowAndNoInitializingShards (INDEX_NAME );
87
- final String replica = internalCluster ().startDataOnlyNode ();
85
+ final String searchNode = internalCluster ().startSearchOnlyNode ();
86
+
88
87
ensureGreen (INDEX_NAME );
89
88
90
89
final int docCount = 10 ;
91
90
for (int i = 0 ; i < docCount ; i ++) {
92
91
client ().prepareIndex (INDEX_NAME ).setId (Integer .toString (i )).setSource ("field" , "value" + i ).execute ().get ();
93
92
}
94
93
refresh (INDEX_NAME );
95
- waitForSearchableDocs (docCount , primary , replica );
94
+ waitForSearchableDocs (docCount , primary , searchNode );
96
95
}
97
96
98
97
public void testSegmentReplicationStatsResponseWithSearchReplica () throws Exception {
99
98
internalCluster ().startClusterManagerOnlyNode ();
100
- final List <String > nodes = internalCluster ().startDataOnlyNodes (2 );
99
+ final String searchNode = internalCluster ().startSearchOnlyNode ();
100
+ final String primary = internalCluster ().startDataOnlyNode ();
101
101
createIndex (
102
102
INDEX_NAME ,
103
103
Settings .builder ()
@@ -107,14 +107,15 @@ public void testSegmentReplicationStatsResponseWithSearchReplica() throws Except
107
107
.put (IndexMetadata .SETTING_REPLICATION_TYPE , ReplicationType .SEGMENT )
108
108
.build ()
109
109
);
110
+
110
111
ensureGreen (INDEX_NAME );
111
112
112
113
final int docCount = 5 ;
113
114
for (int i = 0 ; i < docCount ; i ++) {
114
115
client ().prepareIndex (INDEX_NAME ).setId (Integer .toString (i )).setSource ("field" , "value" + i ).execute ().get ();
115
116
}
116
117
refresh (INDEX_NAME );
117
- waitForSearchableDocs (docCount , nodes );
118
+ waitForSearchableDocs (docCount , primary , searchNode );
118
119
119
120
SegmentReplicationStatsResponse segmentReplicationStatsResponse = dataNodeClient ().admin ()
120
121
.indices ()
@@ -142,46 +143,35 @@ public void testSegmentReplicationStatsResponseWithSearchReplica() throws Except
142
143
public void testSearchReplicaRecovery () throws Exception {
143
144
internalCluster ().startClusterManagerOnlyNode ();
144
145
final String primary = internalCluster ().startDataOnlyNode ();
145
- final String replica = internalCluster ().startDataOnlyNode ();
146
-
147
- // ensure search replicas are only allocated to "replica" node.
148
- client ().admin ()
149
- .cluster ()
150
- .prepareUpdateSettings ()
151
- .setTransientSettings (Settings .builder ().put (SEARCH_REPLICA_ROUTING_INCLUDE_GROUP_SETTING .getKey () + "_name" , replica ))
152
- .execute ()
153
- .actionGet ();
146
+ final String searchNode = internalCluster ().startSearchOnlyNode ();
154
147
155
148
createIndex (INDEX_NAME );
156
149
ensureGreen (INDEX_NAME );
157
- assertRecoverySourceType (replica , EMPTY_STORE );
150
+ assertRecoverySourceType (searchNode , EMPTY_STORE );
158
151
159
152
final int docCount = 10 ;
160
153
for (int i = 0 ; i < docCount ; i ++) {
161
154
client ().prepareIndex (INDEX_NAME ).setId (Integer .toString (i )).setSource ("field" , "value" + i ).execute ().get ();
162
155
}
163
156
refresh (INDEX_NAME );
164
157
flush (INDEX_NAME );
165
- waitForSearchableDocs (10 , primary , replica );
158
+ waitForSearchableDocs (10 , primary , searchNode );
166
159
167
160
// Node stats should show remote download stats as nonzero, use this as a precondition to compare
168
161
// post restart.
169
- assertDownloadStats (replica , true );
170
- NodesStatsResponse nodesStatsResponse ;
171
- NodeStats nodeStats ;
162
+ assertDownloadStats (searchNode , true );
172
163
173
- internalCluster ().restartNode (replica );
164
+ internalCluster ().restartNode (searchNode );
174
165
ensureGreen (INDEX_NAME );
175
- assertDocCounts (10 , replica );
166
+ assertDocCounts (10 , searchNode );
176
167
177
- // assert existing store recovery
178
- assertRecoverySourceType (replica , EXISTING_STORE );
179
- assertDownloadStats (replica , false );
168
+ assertRecoverySourceType (searchNode , EXISTING_STORE );
169
+ assertDownloadStats (searchNode , false );
180
170
}
181
171
182
172
public void testRecoveryAfterDocsIndexed () throws Exception {
183
173
internalCluster ().startClusterManagerOnlyNode ();
184
- final String primary = internalCluster ().startDataOnlyNode ();
174
+ internalCluster ().startDataOnlyNode ();
185
175
createIndex (INDEX_NAME );
186
176
ensureYellowAndNoInitializingShards (INDEX_NAME );
187
177
final int docCount = 10 ;
@@ -190,13 +180,14 @@ public void testRecoveryAfterDocsIndexed() throws Exception {
190
180
}
191
181
refresh (INDEX_NAME );
192
182
193
- final String replica = internalCluster ().startDataOnlyNode ();
183
+ final String searchNode = internalCluster ().startSearchOnlyNode ();
184
+
194
185
ensureGreen (INDEX_NAME );
195
- assertDocCounts (10 , replica );
186
+ assertDocCounts (10 , searchNode );
196
187
197
- assertRecoverySourceType (replica , EMPTY_STORE );
188
+ assertRecoverySourceType (searchNode , EMPTY_STORE );
198
189
// replica should have downloaded from remote
199
- assertDownloadStats (replica , true );
190
+ assertDownloadStats (searchNode , true );
200
191
201
192
client ().admin ()
202
193
.indices ()
@@ -212,14 +203,14 @@ public void testRecoveryAfterDocsIndexed() throws Exception {
212
203
.setSettings (Settings .builder ().put (SETTING_NUMBER_OF_SEARCH_REPLICAS , 1 ))
213
204
.get ();
214
205
ensureGreen (INDEX_NAME );
215
- assertDocCounts (10 , replica );
206
+ assertDocCounts (10 , searchNode );
216
207
217
- internalCluster ().restartNode (replica );
208
+ internalCluster ().restartNode (searchNode );
218
209
219
210
ensureGreen (INDEX_NAME );
220
- assertDocCounts (10 , replica );
221
- assertRecoverySourceType (replica , EXISTING_STORE );
222
- assertDownloadStats (replica , false );
211
+ assertDocCounts (10 , searchNode );
212
+ assertRecoverySourceType (searchNode , EXISTING_STORE );
213
+ assertDownloadStats (searchNode , false );
223
214
}
224
215
225
216
private static void assertRecoverySourceType (String replica , RecoverySource .Type recoveryType ) throws InterruptedException ,
@@ -257,29 +248,30 @@ public void testStopPrimary_RestoreOnNewNode() throws Exception {
257
248
refresh (INDEX_NAME );
258
249
assertDocCounts (docCount , primary );
259
250
260
- final String replica = internalCluster ().startDataOnlyNode ();
251
+ final String searchNode = internalCluster ().startSearchOnlyNode ();
252
+
261
253
ensureGreen (INDEX_NAME );
262
- assertDocCounts (docCount , replica );
254
+ assertDocCounts (docCount , searchNode );
263
255
// stop the primary
264
256
internalCluster ().stopRandomNode (InternalTestCluster .nameFilter (primary ));
265
257
266
258
assertBusy (() -> {
267
259
ClusterHealthResponse clusterHealthResponse = clusterAdmin ().prepareHealth (INDEX_NAME ).get ();
268
260
assertEquals (ClusterHealthStatus .RED , clusterHealthResponse .getStatus ());
269
261
});
270
- assertDocCounts (docCount , replica );
262
+ assertDocCounts (docCount , searchNode );
271
263
272
264
String restoredPrimary = internalCluster ().startDataOnlyNode ();
273
265
274
266
client ().admin ().cluster ().restoreRemoteStore (new RestoreRemoteStoreRequest ().indices (INDEX_NAME ), PlainActionFuture .newFuture ());
275
267
ensureGreen (INDEX_NAME );
276
- assertDocCounts (docCount , replica , restoredPrimary );
268
+ assertDocCounts (docCount , searchNode , restoredPrimary );
277
269
278
270
for (int i = docCount ; i < docCount * 2 ; i ++) {
279
271
client ().prepareIndex (INDEX_NAME ).setId (Integer .toString (i )).setSource ("field" , "value" + i ).execute ().get ();
280
272
}
281
273
refresh (INDEX_NAME );
282
- assertBusy (() -> assertDocCounts (20 , replica , restoredPrimary ));
274
+ assertBusy (() -> assertDocCounts (20 , searchNode , restoredPrimary ));
283
275
}
284
276
285
277
public void testFailoverToNewPrimaryWithPollingReplication () throws Exception {
@@ -293,9 +285,10 @@ public void testFailoverToNewPrimaryWithPollingReplication() throws Exception {
293
285
}
294
286
refresh (INDEX_NAME );
295
287
296
- final String replica = internalCluster ().startDataOnlyNode ();
288
+ final String searchNode = internalCluster ().startSearchOnlyNode ();
289
+
297
290
ensureGreen (INDEX_NAME );
298
- assertDocCounts (10 , replica );
291
+ assertDocCounts (10 , searchNode );
299
292
300
293
client ().admin ()
301
294
.indices ()
@@ -314,12 +307,12 @@ public void testFailoverToNewPrimaryWithPollingReplication() throws Exception {
314
307
});
315
308
ClusterHealthResponse clusterHealthResponse = clusterAdmin ().prepareHealth (INDEX_NAME ).get ();
316
309
assertEquals (ClusterHealthStatus .YELLOW , clusterHealthResponse .getStatus ());
317
- assertDocCounts (10 , replica );
310
+ assertDocCounts (10 , searchNode );
318
311
319
312
for (int i = docCount ; i < docCount * 2 ; i ++) {
320
313
client ().prepareIndex (INDEX_NAME ).setId (Integer .toString (i )).setSource ("field" , "value" + i ).execute ().get ();
321
314
}
322
315
refresh (INDEX_NAME );
323
- assertBusy (() -> assertDocCounts (20 , replica , writer_replica ));
316
+ assertBusy (() -> assertDocCounts (20 , searchNode , writer_replica ));
324
317
}
325
318
}
0 commit comments