@@ -221,6 +221,7 @@ public void testPersistenceStateMetadataPersistence() throws Exception {
221
221
}
222
222
223
223
public void testFailShard () throws Exception {
224
+ allowShardFailures ();
224
225
IndexShard shard = newStartedShard ();
225
226
final ShardPath shardPath = shard .shardPath ();
226
227
assertNotNull (shardPath );
@@ -304,7 +305,8 @@ public void testRejectOperationPermitWithHigherTermWhenNotStarted() throws IOExc
304
305
}
305
306
306
307
public void testPrimaryPromotionDelaysOperations () throws IOException , BrokenBarrierException , InterruptedException {
307
- final IndexShard indexShard = newStartedShard (false );
308
+ final IndexShard indexShard = newShard (false );
309
+ recoveryEmptyReplica (indexShard , randomBoolean ());
308
310
309
311
final int operations = scaledRandomIntBetween (1 , 64 );
310
312
final CyclicBarrier barrier = new CyclicBarrier (1 + operations );
@@ -348,20 +350,10 @@ public void onFailure(Exception e) {
348
350
barrier .await ();
349
351
latch .await ();
350
352
351
- // promote the replica
352
353
final ShardRouting replicaRouting = indexShard .routingEntry ();
353
- final ShardRouting primaryRouting =
354
- newShardRouting (
355
- replicaRouting .shardId (),
356
- replicaRouting .currentNodeId (),
357
- null ,
358
- true ,
359
- ShardRoutingState .STARTED ,
360
- replicaRouting .allocationId ());
361
- indexShard .updateShardState (primaryRouting , indexShard .getPrimaryTerm () + 1 , (shard , listener ) -> {},
362
- 0L , Collections .singleton (primaryRouting .allocationId ().getId ()),
363
- new IndexShardRoutingTable .Builder (primaryRouting .shardId ()).addShard (primaryRouting ).build (),
364
- Collections .emptySet ());
354
+ promoteReplica (indexShard , Collections .singleton (replicaRouting .allocationId ().getId ()),
355
+ new IndexShardRoutingTable .Builder (replicaRouting .shardId ()).addShard (replicaRouting ).build ());
356
+
365
357
366
358
final int delayedOperations = scaledRandomIntBetween (1 , 64 );
367
359
final CyclicBarrier delayedOperationsBarrier = new CyclicBarrier (1 + delayedOperations );
@@ -423,8 +415,9 @@ public void onFailure(Exception e) {
423
415
* 1) Internal state (ala ReplicationTracker) have been updated
424
416
* 2) Primary term is set to the new term
425
417
*/
426
- public void testPublishingOrderOnPromotion () throws IOException , BrokenBarrierException , InterruptedException {
427
- final IndexShard indexShard = newStartedShard (false );
418
+ public void testPublishingOrderOnPromotion () throws IOException , InterruptedException , BrokenBarrierException {
419
+ final IndexShard indexShard = newShard (false );
420
+ recoveryEmptyReplica (indexShard , randomBoolean ());
428
421
final long promotedTerm = indexShard .getPrimaryTerm () + 1 ;
429
422
final CyclicBarrier barrier = new CyclicBarrier (2 );
430
423
final AtomicBoolean stop = new AtomicBoolean ();
@@ -443,18 +436,10 @@ public void testPublishingOrderOnPromotion() throws IOException, BrokenBarrierEx
443
436
});
444
437
thread .start ();
445
438
446
- final ShardRouting replicaRouting = indexShard .routingEntry ();
447
- final ShardRouting primaryRouting = newShardRouting (replicaRouting .shardId (), replicaRouting .currentNodeId (), null , true ,
448
- ShardRoutingState .STARTED , replicaRouting .allocationId ());
449
-
450
-
451
- final Set <String > inSyncAllocationIds = Collections .singleton (primaryRouting .allocationId ().getId ());
452
- final IndexShardRoutingTable routingTable =
453
- new IndexShardRoutingTable .Builder (primaryRouting .shardId ()).addShard (primaryRouting ).build ();
454
439
barrier .await ();
455
- // promote the replica
456
- indexShard . updateShardState ( primaryRouting , promotedTerm , ( shard , listener ) -> {}, 0L , inSyncAllocationIds , routingTable ,
457
- Collections . emptySet ());
440
+ final ShardRouting replicaRouting = indexShard . routingEntry ();
441
+ promoteReplica ( indexShard , Collections . singleton ( replicaRouting . allocationId (). getId ()) ,
442
+ new IndexShardRoutingTable . Builder ( replicaRouting . shardId ()). addShard ( replicaRouting ). build ());
458
443
459
444
stop .set (true );
460
445
thread .join ();
@@ -463,7 +448,8 @@ public void testPublishingOrderOnPromotion() throws IOException, BrokenBarrierEx
463
448
464
449
465
450
public void testPrimaryFillsSeqNoGapsOnPromotion () throws Exception {
466
- final IndexShard indexShard = newStartedShard (false );
451
+ final IndexShard indexShard = newShard (false );
452
+ recoveryEmptyReplica (indexShard , randomBoolean ());
467
453
468
454
// most of the time this is large enough that most of the time there will be at least one gap
469
455
final int operations = 1024 - scaledRandomIntBetween (0 , 1024 );
@@ -474,17 +460,8 @@ public void testPrimaryFillsSeqNoGapsOnPromotion() throws Exception {
474
460
475
461
// promote the replica
476
462
final ShardRouting replicaRouting = indexShard .routingEntry ();
477
- final ShardRouting primaryRouting =
478
- newShardRouting (
479
- replicaRouting .shardId (),
480
- replicaRouting .currentNodeId (),
481
- null ,
482
- true ,
483
- ShardRoutingState .STARTED ,
484
- replicaRouting .allocationId ());
485
- indexShard .updateShardState (primaryRouting , indexShard .getPrimaryTerm () + 1 , (shard , listener ) -> {},
486
- 0L , Collections .singleton (primaryRouting .allocationId ().getId ()),
487
- new IndexShardRoutingTable .Builder (primaryRouting .shardId ()).addShard (primaryRouting ).build (), Collections .emptySet ());
463
+ promoteReplica (indexShard , Collections .singleton (replicaRouting .allocationId ().getId ()),
464
+ new IndexShardRoutingTable .Builder (replicaRouting .shardId ()).addShard (replicaRouting ).build ());
488
465
489
466
/*
490
467
* This operation completing means that the delay operation executed as part of increasing the primary term has completed and the
@@ -501,7 +478,7 @@ public void onResponse(Releasable releasable) {
501
478
502
479
@ Override
503
480
public void onFailure (Exception e ) {
504
- throw new RuntimeException (e );
481
+ throw new AssertionError (e );
505
482
}
506
483
},
507
484
ThreadPool .Names .GENERIC , "" );
@@ -840,7 +817,7 @@ public void testGlobalCheckpointSync() throws IOException {
840
817
// add a replica
841
818
recoverShardFromStore (primaryShard );
842
819
final IndexShard replicaShard = newShard (shardId , false );
843
- recoverReplica (replicaShard , primaryShard );
820
+ recoverReplica (replicaShard , primaryShard , true );
844
821
final int maxSeqNo = randomIntBetween (0 , 128 );
845
822
for (int i = 0 ; i <= maxSeqNo ; i ++) {
846
823
primaryShard .getEngine ().getLocalCheckpointTracker ().generateSeqNo ();
@@ -1619,7 +1596,7 @@ public void testPrimaryHandOffUpdatesLocalCheckpoint() throws IOException {
1619
1596
IndexShardTestCase .updateRoutingEntry (primarySource , primarySource .routingEntry ().relocate (randomAlphaOfLength (10 ), -1 ));
1620
1597
final IndexShard primaryTarget = newShard (primarySource .routingEntry ().getTargetRelocatingShard ());
1621
1598
updateMappings (primaryTarget , primarySource .indexSettings ().getIndexMetaData ());
1622
- recoverReplica (primaryTarget , primarySource );
1599
+ recoverReplica (primaryTarget , primarySource , true );
1623
1600
1624
1601
// check that local checkpoint of new primary is properly tracked after primary relocation
1625
1602
assertThat (primaryTarget .getLocalCheckpoint (), equalTo (totalOps - 1L ));
@@ -2055,7 +2032,7 @@ public long indexTranslogOperations(List<Translog.Operation> operations, int tot
2055
2032
assertFalse (replica .isSyncNeeded ());
2056
2033
return localCheckpoint ;
2057
2034
}
2058
- }, true );
2035
+ }, true , true );
2059
2036
2060
2037
closeShards (primary , replica );
2061
2038
}
@@ -2162,7 +2139,7 @@ public long indexTranslogOperations(List<Translog.Operation> operations, int tot
2162
2139
assertTrue (replica .isActive ());
2163
2140
return localCheckpoint ;
2164
2141
}
2165
- }, false );
2142
+ }, false , true );
2166
2143
2167
2144
closeShards (primary , replica );
2168
2145
}
@@ -2214,7 +2191,7 @@ public void finalizeRecovery(long globalCheckpoint) throws IOException {
2214
2191
super .finalizeRecovery (globalCheckpoint );
2215
2192
assertListenerCalled .accept (replica );
2216
2193
}
2217
- }, false );
2194
+ }, false , true );
2218
2195
2219
2196
closeShards (primary , replica );
2220
2197
}
0 commit comments