Skip to content

Commit

Permalink
Bubble up exception when processing NoOp (#39338)
Browse files Browse the repository at this point in the history
Today we do not bubble up exceptions when processing NoOps but always
treat them as document-level failures. This incorrect treatment causes
the assert_no_failure being tripped in peer-recovery if IndexWriter was
closed exceptionally before.

Closes #38898
  • Loading branch information
dnhatn committed Feb 26, 2019
1 parent b1b885d commit ddb20f1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public Condition newCondition() {
*/
public abstract DeleteResult delete(Delete delete) throws IOException;

public abstract NoOpResult noOp(NoOp noOp);
public abstract NoOpResult noOp(NoOp noOp) throws IOException;

/**
* Base class for index and delete operation results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1538,13 +1538,19 @@ public void maybePruneDeletes() {
}

@Override
public NoOpResult noOp(final NoOp noOp) {
NoOpResult noOpResult;
public NoOpResult noOp(final NoOp noOp) throws IOException {
final NoOpResult noOpResult;
try (ReleasableLock ignored = readLock.acquire()) {
ensureOpen();
markSeqNoAsSeen(noOp.seqNo());
noOpResult = innerNoOp(noOp);
} catch (final Exception e) {
noOpResult = new NoOpResult(getPrimaryTerm(), noOp.seqNo(), e);
try {
maybeFailEngine("noop", e);
} catch (Exception inner) {
e.addSuppressed(inner);
}
throw e;
}
return noOpResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ private Engine.NoOpResult markSeqNoAsNoop(Engine engine, long seqNo, long opPrim
return noOp(engine, noOp);
}

private Engine.NoOpResult noOp(Engine engine, Engine.NoOp noOp) {
private Engine.NoOpResult noOp(Engine engine, Engine.NoOp noOp) throws IOException {
active.set(true);
if (logger.isTraceEnabled()) {
logger.trace("noop (seq# [{}])", noOp.seqNo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3252,7 +3252,7 @@ public void testHandleDocumentFailure() throws Exception {
final ParsedDocument doc3 = testParsedDocument("3", null, testDocumentWithTextField(), B_1, null);

AtomicReference<ThrowingIndexWriter> throwingIndexWriter = new AtomicReference<>();
try (Engine engine = createEngine(defaultSettings, store, createTempDir(), NoMergePolicy.INSTANCE,
try (InternalEngine engine = createEngine(defaultSettings, store, createTempDir(), NoMergePolicy.INSTANCE,
(directory, iwc) -> {
throwingIndexWriter.set(new ThrowingIndexWriter(directory, iwc));
return throwingIndexWriter.get();
Expand Down Expand Up @@ -3317,16 +3317,13 @@ public BytesRef binaryValue() {
engine.close();
}
// now the engine is closed check we respond correctly
try {
if (randomBoolean()) {
engine.index(indexForDoc(doc1));
} else {
engine.delete(new Engine.Delete("test", "", newUid(doc1), primaryTerm.get()));
}
fail("engine should be closed");
} catch (Exception e) {
assertThat(e, instanceOf(AlreadyClosedException.class));
}
expectThrows(AlreadyClosedException.class, () -> engine.index(indexForDoc(doc1)));
expectThrows(AlreadyClosedException.class,
() -> engine.delete(new Engine.Delete("test", "", newUid(doc1), primaryTerm.get())));
expectThrows(AlreadyClosedException.class, () -> engine.noOp(
new Engine.NoOp(engine.getLocalCheckpointTracker().generateSeqNo(),
engine.config().getPrimaryTermSupplier().getAsLong(),
randomFrom(Engine.Operation.Origin.values()), randomNonNegativeLong(), "test")));
}
}
}
Expand Down

0 comments on commit ddb20f1

Please sign in to comment.