Skip to content

Commit

Permalink
Adjust translog after versionType removed in 7.0 (#32020)
Browse files Browse the repository at this point in the history
With the presence of sequence number, we no longer use versionType to
resolve out of order collision and remove it in 7.0.

This PR adjusts translog to adapt that change.

Relates #31945
  • Loading branch information
dnhatn authored Jul 17, 2018
1 parent da949fa commit 3c11b4e
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.LongSupplier;

Expand Down Expand Up @@ -202,9 +203,27 @@ private synchronized boolean assertNoSeqNumberConflict(long seqNo, BytesReferenc
if (previous.v1().equals(data) == false) {
Translog.Operation newOp = Translog.readOperation(new BufferedChecksumStreamInput(data.streamInput()));
Translog.Operation prvOp = Translog.readOperation(new BufferedChecksumStreamInput(previous.v1().streamInput()));
throw new AssertionError(
"seqNo [" + seqNo + "] was processed twice in generation [" + generation + "], with different data. " +
"prvOp [" + prvOp + "], newOp [" + newOp + "]", previous.v2());
// we need to exclude versionType from this check because it's removed in 7.0
final boolean sameOp;
if (prvOp instanceof Translog.Index && newOp instanceof Translog.Index) {
final Translog.Index o1 = (Translog.Index) prvOp;
final Translog.Index o2 = (Translog.Index) newOp;
sameOp = Objects.equals(o1.id(), o2.id()) && Objects.equals(o1.type(), o2.type())
&& Objects.equals(o1.source(), o2.source()) && Objects.equals(o1.routing(), o2.routing())
&& o1.primaryTerm() == o2.primaryTerm() && o1.seqNo() == o2.seqNo() && o1.version() == o2.version();
} else if (prvOp instanceof Translog.Delete && newOp instanceof Translog.Delete) {
final Translog.Delete o1 = (Translog.Delete) prvOp;
final Translog.Delete o2 = (Translog.Delete) newOp;
sameOp = Objects.equals(o1.id(), o2.id()) && Objects.equals(o1.type(), o2.type())
&& o1.primaryTerm() == o2.primaryTerm() && o1.seqNo() == o2.seqNo() && o1.version() == o2.version();
} else {
sameOp = false;
}
if (sameOp == false) {
throw new AssertionError(
"seqNo [" + seqNo + "] was processed twice in generation [" + generation + "], with different data. " +
"prvOp [" + prvOp + "], newOp [" + newOp + "]", previous.v2());
}
}
} else {
seenSequenceNumbers.put(seqNo,
Expand Down

0 comments on commit 3c11b4e

Please sign in to comment.