@@ -226,6 +226,7 @@ public void testPersistenceStateMetadataPersistence() throws Exception {
226
226
}
227
227
228
228
public void testFailShard () throws Exception {
229
+ allowShardFailures ();
229
230
IndexShard shard = newStartedShard ();
230
231
final ShardPath shardPath = shard .shardPath ();
231
232
assertNotNull (shardPath );
@@ -309,7 +310,8 @@ public void testRejectOperationPermitWithHigherTermWhenNotStarted() throws IOExc
309
310
}
310
311
311
312
public void testPrimaryPromotionDelaysOperations () throws IOException , BrokenBarrierException , InterruptedException {
312
- final IndexShard indexShard = newStartedShard (false );
313
+ final IndexShard indexShard = newShard (false );
314
+ recoveryEmptyReplica (indexShard , randomBoolean ());
313
315
314
316
final int operations = scaledRandomIntBetween (1 , 64 );
315
317
final CyclicBarrier barrier = new CyclicBarrier (1 + operations );
@@ -353,20 +355,10 @@ public void onFailure(Exception e) {
353
355
barrier .await ();
354
356
latch .await ();
355
357
356
- // promote the replica
357
358
final ShardRouting replicaRouting = indexShard .routingEntry ();
358
- final ShardRouting primaryRouting =
359
- newShardRouting (
360
- replicaRouting .shardId (),
361
- replicaRouting .currentNodeId (),
362
- null ,
363
- true ,
364
- ShardRoutingState .STARTED ,
365
- replicaRouting .allocationId ());
366
- indexShard .updateShardState (primaryRouting , indexShard .getPrimaryTerm () + 1 , (shard , listener ) -> {},
367
- 0L , Collections .singleton (primaryRouting .allocationId ().getId ()),
368
- new IndexShardRoutingTable .Builder (primaryRouting .shardId ()).addShard (primaryRouting ).build (),
369
- Collections .emptySet ());
359
+ promoteReplica (indexShard , Collections .singleton (replicaRouting .allocationId ().getId ()),
360
+ new IndexShardRoutingTable .Builder (replicaRouting .shardId ()).addShard (replicaRouting ).build ());
361
+
370
362
371
363
final int delayedOperations = scaledRandomIntBetween (1 , 64 );
372
364
final CyclicBarrier delayedOperationsBarrier = new CyclicBarrier (1 + delayedOperations );
@@ -428,8 +420,9 @@ public void onFailure(Exception e) {
428
420
* 1) Internal state (ala ReplicationTracker) have been updated
429
421
* 2) Primary term is set to the new term
430
422
*/
431
- public void testPublishingOrderOnPromotion () throws IOException , BrokenBarrierException , InterruptedException {
432
- final IndexShard indexShard = newStartedShard (false );
423
+ public void testPublishingOrderOnPromotion () throws IOException , InterruptedException , BrokenBarrierException {
424
+ final IndexShard indexShard = newShard (false );
425
+ recoveryEmptyReplica (indexShard , randomBoolean ());
433
426
final long promotedTerm = indexShard .getPrimaryTerm () + 1 ;
434
427
final CyclicBarrier barrier = new CyclicBarrier (2 );
435
428
final AtomicBoolean stop = new AtomicBoolean ();
@@ -448,18 +441,10 @@ public void testPublishingOrderOnPromotion() throws IOException, BrokenBarrierEx
448
441
});
449
442
thread .start ();
450
443
451
- final ShardRouting replicaRouting = indexShard .routingEntry ();
452
- final ShardRouting primaryRouting = newShardRouting (replicaRouting .shardId (), replicaRouting .currentNodeId (), null , true ,
453
- ShardRoutingState .STARTED , replicaRouting .allocationId ());
454
-
455
-
456
- final Set <String > inSyncAllocationIds = Collections .singleton (primaryRouting .allocationId ().getId ());
457
- final IndexShardRoutingTable routingTable =
458
- new IndexShardRoutingTable .Builder (primaryRouting .shardId ()).addShard (primaryRouting ).build ();
459
444
barrier .await ();
460
- // promote the replica
461
- indexShard . updateShardState ( primaryRouting , promotedTerm , ( shard , listener ) -> {}, 0L , inSyncAllocationIds , routingTable ,
462
- Collections . emptySet ());
445
+ final ShardRouting replicaRouting = indexShard . routingEntry ();
446
+ promoteReplica ( indexShard , Collections . singleton ( replicaRouting . allocationId (). getId ()) ,
447
+ new IndexShardRoutingTable . Builder ( replicaRouting . shardId ()). addShard ( replicaRouting ). build ());
463
448
464
449
stop .set (true );
465
450
thread .join ();
@@ -468,7 +453,8 @@ public void testPublishingOrderOnPromotion() throws IOException, BrokenBarrierEx
468
453
469
454
470
455
public void testPrimaryFillsSeqNoGapsOnPromotion () throws Exception {
471
- final IndexShard indexShard = newStartedShard (false );
456
+ final IndexShard indexShard = newShard (false );
457
+ recoveryEmptyReplica (indexShard , randomBoolean ());
472
458
473
459
// most of the time this is large enough that most of the time there will be at least one gap
474
460
final int operations = 1024 - scaledRandomIntBetween (0 , 1024 );
@@ -479,17 +465,8 @@ public void testPrimaryFillsSeqNoGapsOnPromotion() throws Exception {
479
465
480
466
// promote the replica
481
467
final ShardRouting replicaRouting = indexShard .routingEntry ();
482
- final ShardRouting primaryRouting =
483
- newShardRouting (
484
- replicaRouting .shardId (),
485
- replicaRouting .currentNodeId (),
486
- null ,
487
- true ,
488
- ShardRoutingState .STARTED ,
489
- replicaRouting .allocationId ());
490
- indexShard .updateShardState (primaryRouting , indexShard .getPrimaryTerm () + 1 , (shard , listener ) -> {},
491
- 0L , Collections .singleton (primaryRouting .allocationId ().getId ()),
492
- new IndexShardRoutingTable .Builder (primaryRouting .shardId ()).addShard (primaryRouting ).build (), Collections .emptySet ());
468
+ promoteReplica (indexShard , Collections .singleton (replicaRouting .allocationId ().getId ()),
469
+ new IndexShardRoutingTable .Builder (replicaRouting .shardId ()).addShard (replicaRouting ).build ());
493
470
494
471
/*
495
472
* This operation completing means that the delay operation executed as part of increasing the primary term has completed and the
@@ -506,7 +483,7 @@ public void onResponse(Releasable releasable) {
506
483
507
484
@ Override
508
485
public void onFailure (Exception e ) {
509
- throw new RuntimeException (e );
486
+ throw new AssertionError (e );
510
487
}
511
488
},
512
489
ThreadPool .Names .GENERIC , "" );
@@ -846,7 +823,7 @@ public void testGlobalCheckpointSync() throws IOException {
846
823
// add a replica
847
824
recoverShardFromStore (primaryShard );
848
825
final IndexShard replicaShard = newShard (shardId , false );
849
- recoverReplica (replicaShard , primaryShard );
826
+ recoverReplica (replicaShard , primaryShard , true );
850
827
final int maxSeqNo = randomIntBetween (0 , 128 );
851
828
for (int i = 0 ; i <= maxSeqNo ; i ++) {
852
829
EngineTestCase .generateNewSeqNo (primaryShard .getEngine ());
@@ -1625,7 +1602,7 @@ public void testPrimaryHandOffUpdatesLocalCheckpoint() throws IOException {
1625
1602
IndexShardTestCase .updateRoutingEntry (primarySource , primarySource .routingEntry ().relocate (randomAlphaOfLength (10 ), -1 ));
1626
1603
final IndexShard primaryTarget = newShard (primarySource .routingEntry ().getTargetRelocatingShard ());
1627
1604
updateMappings (primaryTarget , primarySource .indexSettings ().getIndexMetaData ());
1628
- recoverReplica (primaryTarget , primarySource );
1605
+ recoverReplica (primaryTarget , primarySource , true );
1629
1606
1630
1607
// check that local checkpoint of new primary is properly tracked after primary relocation
1631
1608
assertThat (primaryTarget .getLocalCheckpoint (), equalTo (totalOps - 1L ));
@@ -2082,7 +2059,7 @@ public long indexTranslogOperations(List<Translog.Operation> operations, int tot
2082
2059
assertFalse (replica .isSyncNeeded ());
2083
2060
return localCheckpoint ;
2084
2061
}
2085
- }, true );
2062
+ }, true , true );
2086
2063
2087
2064
closeShards (primary , replica );
2088
2065
}
@@ -2189,7 +2166,7 @@ public long indexTranslogOperations(List<Translog.Operation> operations, int tot
2189
2166
assertTrue (replica .isActive ());
2190
2167
return localCheckpoint ;
2191
2168
}
2192
- }, false );
2169
+ }, false , true );
2193
2170
2194
2171
closeShards (primary , replica );
2195
2172
}
@@ -2241,7 +2218,7 @@ public void finalizeRecovery(long globalCheckpoint) throws IOException {
2241
2218
super .finalizeRecovery (globalCheckpoint );
2242
2219
assertListenerCalled .accept (replica );
2243
2220
}
2244
- }, false );
2221
+ }, false , true );
2245
2222
2246
2223
closeShards (primary , replica );
2247
2224
}
0 commit comments