Skip to content

Commit 4d18017

Browse files
authored
Revert translog changes introduced for CCR (#31947)
We introduced these changes in #26708 because for CCR. However, CCR now uses Lucene instead of translog. This commit reverts these changes so that we can minimize differences between the ccr and the master branch. Relates ##26708
1 parent 815faf3 commit 4d18017

File tree

5 files changed

+19
-65
lines changed

5 files changed

+19
-65
lines changed

server/src/main/java/org/elasticsearch/index/engine/Engine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public enum SearcherScope {
588588
* Creates a new translog snapshot from this engine for reading translog operations whose seq# in the provided range.
589589
* The caller has to close the returned snapshot after finishing the reading.
590590
*/
591-
public abstract Translog.Snapshot newTranslogSnapshotBetween(long minSeqNo, long maxSeqNo) throws IOException;
591+
public abstract Translog.Snapshot newSnapshotFromMinSeqNo(long minSeqNo) throws IOException;
592592

593593
public abstract TranslogStats getTranslogStats();
594594

server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public void restoreLocalCheckpointFromTranslog() throws IOException {
344344
try (ReleasableLock ignored = writeLock.acquire()) {
345345
ensureOpen();
346346
final long localCheckpoint = localCheckpointTracker.getCheckpoint();
347-
try (Translog.Snapshot snapshot = getTranslog().newSnapshotFrom(localCheckpoint + 1)) {
347+
try (Translog.Snapshot snapshot = getTranslog().newSnapshotFromMinSeqNo(localCheckpoint + 1)) {
348348
Translog.Operation operation;
349349
while ((operation = snapshot.next()) != null) {
350350
if (operation.seqNo() > localCheckpoint) {
@@ -480,8 +480,8 @@ public void syncTranslog() throws IOException {
480480
}
481481

482482
@Override
483-
public Translog.Snapshot newTranslogSnapshotBetween(long minSeqNo, long maxSeqNo) throws IOException {
484-
return getTranslog().getSnapshotBetween(minSeqNo, maxSeqNo);
483+
public Translog.Snapshot newSnapshotFromMinSeqNo(long minSeqNo) throws IOException {
484+
return getTranslog().newSnapshotFromMinSeqNo(minSeqNo);
485485
}
486486

487487
/**
@@ -493,7 +493,7 @@ public Translog.Snapshot readHistoryOperations(String source, MapperService mapp
493493
if (engineConfig.getIndexSettings().isSoftDeleteEnabled()) {
494494
return newLuceneChangesSnapshot(source, mapperService, Math.max(0, startingSeqNo), Long.MAX_VALUE, false);
495495
} else {
496-
return getTranslog().getSnapshotBetween(startingSeqNo, Long.MAX_VALUE);
496+
return getTranslog().newSnapshotFromMinSeqNo(startingSeqNo);
497497
}
498498
}
499499

@@ -2483,7 +2483,7 @@ public boolean hasCompleteOperationHistory(String source, MapperService mapperSe
24832483
} else {
24842484
final long currentLocalCheckpoint = getLocalCheckpointTracker().getCheckpoint();
24852485
final LocalCheckpointTracker tracker = new LocalCheckpointTracker(startingSeqNo, startingSeqNo - 1);
2486-
try (Translog.Snapshot snapshot = getTranslog().getSnapshotBetween(startingSeqNo, Long.MAX_VALUE)) {
2486+
try (Translog.Snapshot snapshot = getTranslog().newSnapshotFromMinSeqNo(startingSeqNo)) {
24872487
Translog.Operation operation;
24882488
while ((operation = snapshot.next()) != null) {
24892489
if (operation.seqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) {

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ public Closeable acquireRetentionLockForPeerRecovery() {
16051605
*/
16061606
public Translog.Snapshot newTranslogSnapshotFromMinSeqNo(long minSeqNo) throws IOException {
16071607
// TODO: Remove this method after primary-replica resync use soft-deletes
1608-
return getEngine().newTranslogSnapshotBetween(minSeqNo, Long.MAX_VALUE);
1608+
return getEngine().newSnapshotFromMinSeqNo(minSeqNo);
16091609
}
16101610

16111611
/**

server/src/main/java/org/elasticsearch/index/translog/Translog.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,7 @@ public int totalOperationsByMinGen(long minGeneration) {
411411
public int estimateTotalOperationsFromMinSeq(long minSeqNo) {
412412
try (ReleasableLock ignored = readLock.acquire()) {
413413
ensureOpen();
414-
return readersBetweenMinAndMaxSeqNo(minSeqNo, Long.MAX_VALUE)
415-
.mapToInt(BaseTranslogReader::totalOperations)
416-
.sum();
414+
return readersAboveMinSeqNo(minSeqNo).mapToInt(BaseTranslogReader::totalOperations).sum();
417415
}
418416
}
419417

@@ -602,23 +600,11 @@ public Operation readOperation(Location location) throws IOException {
602600
return null;
603601
}
604602

605-
/**
606-
* Returns a snapshot with operations having a sequence number equal to or greater than <code>minSeqNo</code>.
607-
*/
608-
public Snapshot newSnapshotFrom(long minSeqNo) throws IOException {
609-
return getSnapshotBetween(minSeqNo, Long.MAX_VALUE);
610-
}
611-
612-
/**
613-
* Returns a snapshot with operations having a sequence number equal to or greater than <code>minSeqNo</code> and
614-
* equal to or lesser than <code>maxSeqNo</code>.
615-
*/
616-
public Snapshot getSnapshotBetween(long minSeqNo, long maxSeqNo) throws IOException {
603+
public Snapshot newSnapshotFromMinSeqNo(long minSeqNo) throws IOException {
617604
try (ReleasableLock ignored = readLock.acquire()) {
618605
ensureOpen();
619-
TranslogSnapshot[] snapshots = readersBetweenMinAndMaxSeqNo(minSeqNo, maxSeqNo)
620-
.map(BaseTranslogReader::newSnapshot)
621-
.toArray(TranslogSnapshot[]::new);
606+
TranslogSnapshot[] snapshots = readersAboveMinSeqNo(minSeqNo).map(BaseTranslogReader::newSnapshot)
607+
.toArray(TranslogSnapshot[]::new);
622608
return newMultiSnapshot(snapshots);
623609
}
624610
}
@@ -644,14 +630,14 @@ private Snapshot newMultiSnapshot(TranslogSnapshot[] snapshots) throws IOExcepti
644630
}
645631
}
646632

647-
private Stream<? extends BaseTranslogReader> readersBetweenMinAndMaxSeqNo(long minSeqNo, long maxSeqNo) {
648-
assert readLock.isHeldByCurrentThread() || writeLock.isHeldByCurrentThread() ;
649-
633+
private Stream<? extends BaseTranslogReader> readersAboveMinSeqNo(long minSeqNo) {
634+
assert readLock.isHeldByCurrentThread() || writeLock.isHeldByCurrentThread() :
635+
"callers of readersAboveMinSeqNo must hold a lock: readLock ["
636+
+ readLock.isHeldByCurrentThread() + "], writeLock [" + readLock.isHeldByCurrentThread() + "]";
650637
return Stream.concat(readers.stream(), Stream.of(current))
651638
.filter(reader -> {
652-
final Checkpoint checkpoint = reader.getCheckpoint();
653-
return checkpoint.maxSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO ||
654-
checkpoint.minSeqNo <= maxSeqNo && checkpoint.maxSeqNo >= minSeqNo;
639+
final long maxSeqNo = reader.getCheckpoint().maxSeqNo;
640+
return maxSeqNo == SequenceNumbers.UNASSIGNED_SEQ_NO || maxSeqNo >= minSeqNo;
655641
});
656642
}
657643

server/src/test/java/org/elasticsearch/index/translog/TranslogTests.java

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ protected void doRun() throws Exception {
998998
// these are what we expect the snapshot to return (and potentially some more).
999999
Set<Translog.Operation> expectedOps = new HashSet<>(writtenOps.keySet());
10001000
expectedOps.removeIf(op -> op.seqNo() <= committedLocalCheckpointAtView);
1001-
try (Translog.Snapshot snapshot = translog.newSnapshotFrom(committedLocalCheckpointAtView + 1L)) {
1001+
try (Translog.Snapshot snapshot = translog.newSnapshotFromMinSeqNo(committedLocalCheckpointAtView + 1L)) {
10021002
Translog.Operation op;
10031003
while ((op = snapshot.next()) != null) {
10041004
expectedOps.remove(op);
@@ -2814,7 +2814,7 @@ public void testMinSeqNoBasedAPI() throws IOException {
28142814
}
28152815
assertThat(translog.estimateTotalOperationsFromMinSeq(seqNo), equalTo(expectedSnapshotOps));
28162816
int readFromSnapshot = 0;
2817-
try (Translog.Snapshot snapshot = translog.newSnapshotFrom(seqNo)) {
2817+
try (Translog.Snapshot snapshot = translog.newSnapshotFromMinSeqNo(seqNo)) {
28182818
assertThat(snapshot.totalOperations(), equalTo(expectedSnapshotOps));
28192819
Translog.Operation op;
28202820
while ((op = snapshot.next()) != null) {
@@ -2831,38 +2831,6 @@ public void testMinSeqNoBasedAPI() throws IOException {
28312831
}
28322832
}
28332833

2834-
public void testGetSnapshotBetween() throws IOException {
2835-
final int numOperations = randomIntBetween(2, 8196);
2836-
final List<Integer> sequenceNumbers = IntStream.range(0, numOperations).boxed().collect(Collectors.toList());
2837-
Collections.shuffle(sequenceNumbers, random());
2838-
for (Integer sequenceNumber : sequenceNumbers) {
2839-
translog.add(new Translog.NoOp(sequenceNumber, 0, "test"));
2840-
if (rarely()) {
2841-
translog.rollGeneration();
2842-
}
2843-
}
2844-
translog.rollGeneration();
2845-
2846-
final int iters = randomIntBetween(8, 32);
2847-
for (int iter = 0; iter < iters; iter++) {
2848-
int min = randomIntBetween(0, numOperations - 1);
2849-
int max = randomIntBetween(min, numOperations);
2850-
try (Translog.Snapshot snapshot = translog.getSnapshotBetween(min, max)) {
2851-
final List<Translog.Operation> operations = new ArrayList<>();
2852-
for (Translog.Operation operation = snapshot.next(); operation != null; operation = snapshot.next()) {
2853-
if (operation.seqNo() >= min && operation.seqNo() <= max) {
2854-
operations.add(operation);
2855-
}
2856-
}
2857-
operations.sort(Comparator.comparingLong(Translog.Operation::seqNo));
2858-
Iterator<Translog.Operation> iterator = operations.iterator();
2859-
for (long expectedSeqNo = min; expectedSeqNo < max; expectedSeqNo++) {
2860-
assertThat(iterator.next().seqNo(), equalTo(expectedSeqNo));
2861-
}
2862-
}
2863-
}
2864-
}
2865-
28662834
public void testSimpleCommit() throws IOException {
28672835
final int operations = randomIntBetween(1, 4096);
28682836
long seqNo = 0;

0 commit comments

Comments
 (0)