Skip to content

Commit 2098bb2

Browse files
committed
Fix document failure replication test
This fix is needed after changing how we handle document-level failures when indexing no-ops and deletes.
1 parent 7df8dcf commit 2098bb2

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

server/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.elasticsearch.index.replication;
2020

21-
import org.apache.lucene.document.Field;
2221
import org.apache.lucene.index.IndexWriter;
2322
import org.apache.lucene.index.IndexableField;
2423
import org.apache.lucene.index.Term;
@@ -38,7 +37,6 @@
3837
import org.elasticsearch.common.util.iterable.Iterables;
3938
import org.elasticsearch.common.xcontent.XContentType;
4039
import org.elasticsearch.index.IndexSettings;
41-
import org.elasticsearch.index.VersionType;
4240
import org.elasticsearch.index.engine.Engine;
4341
import org.elasticsearch.index.engine.EngineFactory;
4442
import org.elasticsearch.index.engine.InternalEngine;
@@ -59,7 +57,6 @@
5957
import org.hamcrest.Matcher;
6058

6159
import java.io.IOException;
62-
import java.nio.charset.StandardCharsets;
6360
import java.util.ArrayList;
6461
import java.util.Collections;
6562
import java.util.List;
@@ -420,10 +417,8 @@ public void testReplicaOperationWithConcurrentPrimaryPromotion() throws Exceptio
420417
*/
421418
public void testDocumentFailureReplication() throws Exception {
422419
final IOException indexException = new IOException("simulated indexing failure");
423-
final IOException deleteException = new IOException("simulated deleting failure");
424420
final EngineFactory engineFactory = config -> InternalEngineTests.createInternalEngine((dir, iwc) ->
425421
new IndexWriter(dir, iwc) {
426-
final AtomicBoolean throwAfterIndexedOneDoc = new AtomicBoolean(); // need one document to trigger delete in IW.
427422
@Override
428423
public long addDocument(Iterable<? extends IndexableField> doc) throws IOException {
429424
boolean isTombstone = false;
@@ -432,20 +427,12 @@ public long addDocument(Iterable<? extends IndexableField> doc) throws IOExcepti
432427
isTombstone = true;
433428
}
434429
}
435-
if (isTombstone == false && throwAfterIndexedOneDoc.getAndSet(true)) {
436-
throw indexException;
430+
if (isTombstone) {
431+
return super.addDocument(doc); // allow to add Noop
437432
} else {
438-
return super.addDocument(doc);
433+
throw indexException;
439434
}
440435
}
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-
}
449436
}, null, null, config);
450437
try (ReplicationGroup shards = new ReplicationGroup(buildIndexMetaData(0)) {
451438
@Override
@@ -455,23 +442,14 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
455442
shards.startPrimary();
456443
long primaryTerm = shards.getPrimary().getPendingPrimaryTerm();
457444
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()));
463449
try (Translog.Snapshot snapshot = getTranslog(shards.getPrimary()).newSnapshot()) {
464450
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
465451
}
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);
475453

476454
int nReplica = randomIntBetween(1, 3);
477455
for (int i = 0; i < nReplica; i++) {
@@ -486,14 +464,10 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
486464
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
487465
}
488466
}
489-
// unlike previous failures, these two failures replicated directly from the replication channel.
467+
// the failure replicated directly from the replication channel.
490468
indexResp = shards.index(new IndexRequest(index.getName(), "type", "any").source("{}", XContentType.JSON));
491469
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()));
497471

498472
for (IndexShard shard : shards) {
499473
try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshot()) {
@@ -503,7 +477,7 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
503477
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
504478
}
505479
}
506-
shards.assertAllEqual(1);
480+
shards.assertAllEqual(0);
507481
}
508482
}
509483

0 commit comments

Comments
 (0)