18
18
*/
19
19
package org .elasticsearch .index .replication ;
20
20
21
- import org .apache .lucene .document .Field ;
22
21
import org .apache .lucene .index .IndexWriter ;
23
22
import org .apache .lucene .index .IndexableField ;
24
23
import org .apache .lucene .index .Term ;
38
37
import org .elasticsearch .common .util .iterable .Iterables ;
39
38
import org .elasticsearch .common .xcontent .XContentType ;
40
39
import org .elasticsearch .index .IndexSettings ;
41
- import org .elasticsearch .index .VersionType ;
42
40
import org .elasticsearch .index .engine .Engine ;
43
41
import org .elasticsearch .index .engine .EngineFactory ;
44
42
import org .elasticsearch .index .engine .InternalEngine ;
59
57
import org .hamcrest .Matcher ;
60
58
61
59
import java .io .IOException ;
62
- import java .nio .charset .StandardCharsets ;
63
60
import java .util .ArrayList ;
64
61
import java .util .Collections ;
65
62
import java .util .List ;
@@ -420,10 +417,8 @@ public void testReplicaOperationWithConcurrentPrimaryPromotion() throws Exceptio
420
417
*/
421
418
public void testDocumentFailureReplication () throws Exception {
422
419
final IOException indexException = new IOException ("simulated indexing failure" );
423
- final IOException deleteException = new IOException ("simulated deleting failure" );
424
420
final EngineFactory engineFactory = config -> InternalEngineTests .createInternalEngine ((dir , iwc ) ->
425
421
new IndexWriter (dir , iwc ) {
426
- final AtomicBoolean throwAfterIndexedOneDoc = new AtomicBoolean (); // need one document to trigger delete in IW.
427
422
@ Override
428
423
public long addDocument (Iterable <? extends IndexableField > doc ) throws IOException {
429
424
boolean isTombstone = false ;
@@ -432,20 +427,12 @@ public long addDocument(Iterable<? extends IndexableField> doc) throws IOExcepti
432
427
isTombstone = true ;
433
428
}
434
429
}
435
- if (isTombstone == false && throwAfterIndexedOneDoc . getAndSet ( true ) ) {
436
- throw indexException ;
430
+ if (isTombstone ) {
431
+ return super . addDocument ( doc ); // allow to add Noop
437
432
} else {
438
- return super . addDocument ( doc ) ;
433
+ throw indexException ;
439
434
}
440
435
}
441
- @ Override
442
- public long deleteDocuments (Term ... terms ) throws IOException {
443
- throw deleteException ;
444
- }
445
- @ Override
446
- public long softUpdateDocument (Term term , Iterable <? extends IndexableField > doc , Field ...fields ) throws IOException {
447
- throw deleteException ; // a delete uses softUpdateDocument API if soft-deletes enabled
448
- }
449
436
}, null , null , config );
450
437
try (ReplicationGroup shards = new ReplicationGroup (buildIndexMetaData (0 )) {
451
438
@ Override
@@ -455,23 +442,14 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
455
442
shards .startPrimary ();
456
443
long primaryTerm = shards .getPrimary ().getPendingPrimaryTerm ();
457
444
List <Translog .Operation > expectedTranslogOps = new ArrayList <>();
458
- BulkItemResponse indexResp = shards .index (new IndexRequest (index .getName (), "type" , "1" )
459
- .source ("{}" , XContentType .JSON ).version (1 ).versionType (VersionType .EXTERNAL ));
460
- assertThat (indexResp .isFailed (), equalTo (false ));
461
- expectedTranslogOps .add (new Translog .Index ("type" , "1" , 0 , primaryTerm , 1 , VersionType .EXTERNAL ,
462
- "{}" .getBytes (StandardCharsets .UTF_8 ), null , null , -1 ));
445
+ BulkItemResponse indexResp = shards .index (new IndexRequest (index .getName (), "type" , "1" ).source ("{}" , XContentType .JSON ));
446
+ assertThat (indexResp .isFailed (), equalTo (true ));
447
+ assertThat (indexResp .getFailure ().getCause (), equalTo (indexException ));
448
+ expectedTranslogOps .add (new Translog .NoOp (0 , primaryTerm , indexException .toString ()));
463
449
try (Translog .Snapshot snapshot = getTranslog (shards .getPrimary ()).newSnapshot ()) {
464
450
assertThat (snapshot , SnapshotMatchers .containsOperationsInAnyOrder (expectedTranslogOps ));
465
451
}
466
-
467
- indexResp = shards .index (new IndexRequest (index .getName (), "type" , "any" ).source ("{}" , XContentType .JSON ));
468
- assertThat (indexResp .getFailure ().getCause (), equalTo (indexException ));
469
- expectedTranslogOps .add (new Translog .NoOp (1 , primaryTerm , indexException .toString ()));
470
-
471
- BulkItemResponse deleteResp = shards .delete (new DeleteRequest (index .getName (), "type" , "1" ));
472
- assertThat (deleteResp .getFailure ().getCause (), equalTo (deleteException ));
473
- expectedTranslogOps .add (new Translog .NoOp (2 , primaryTerm , deleteException .toString ()));
474
- shards .assertAllEqual (1 );
452
+ shards .assertAllEqual (0 );
475
453
476
454
int nReplica = randomIntBetween (1 , 3 );
477
455
for (int i = 0 ; i < nReplica ; i ++) {
@@ -486,14 +464,10 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
486
464
assertThat (snapshot , SnapshotMatchers .containsOperationsInAnyOrder (expectedTranslogOps ));
487
465
}
488
466
}
489
- // unlike previous failures, these two failures replicated directly from the replication channel.
467
+ // the failure replicated directly from the replication channel.
490
468
indexResp = shards .index (new IndexRequest (index .getName (), "type" , "any" ).source ("{}" , XContentType .JSON ));
491
469
assertThat (indexResp .getFailure ().getCause (), equalTo (indexException ));
492
- expectedTranslogOps .add (new Translog .NoOp (3 , primaryTerm , indexException .toString ()));
493
-
494
- deleteResp = shards .delete (new DeleteRequest (index .getName (), "type" , "1" ));
495
- assertThat (deleteResp .getFailure ().getCause (), equalTo (deleteException ));
496
- expectedTranslogOps .add (new Translog .NoOp (4 , primaryTerm , deleteException .toString ()));
470
+ expectedTranslogOps .add (new Translog .NoOp (1 , primaryTerm , indexException .toString ()));
497
471
498
472
for (IndexShard shard : shards ) {
499
473
try (Translog .Snapshot snapshot = getTranslog (shard ).newSnapshot ()) {
@@ -503,7 +477,7 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
503
477
assertThat (snapshot , SnapshotMatchers .containsOperationsInAnyOrder (expectedTranslogOps ));
504
478
}
505
479
}
506
- shards .assertAllEqual (1 );
480
+ shards .assertAllEqual (0 );
507
481
}
508
482
}
509
483
0 commit comments