Skip to content

Commit f3a18b8

Browse files
committed
Add getHistoryOperationsFromTranslog method to fetch the hostory snapshot from translogs
Signed-off-by: Ankit Kala <[email protected]>
1 parent 6d7a152 commit f3a18b8

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,16 @@ public Translog.Snapshot getHistoryOperations(String reason, long startingSeqNo,
23522352
return getEngine().newChangesSnapshot(reason, startingSeqNo, endSeqNo, true, accurateCount);
23532353
}
23542354

2355+
/**
2356+
* Creates a new history snapshot from the translog instead of the lucene index. Required for cross cluster replication.
2357+
* Use the recommended {@link #getHistoryOperations(String, long, long, boolean)} method for other cases.
2358+
* Depending on how translog durability is configured, this method might/might not return the snapshot. For e.g,
2359+
* If the translog has been configured with no-durability, it'll return UnsupportedOperationException.
2360+
*/
2361+
public Translog.Snapshot getHistoryOperationsFromTranslog(long startingSeqNo, long endSeqNo) throws IOException {
2362+
return getEngine().translogManager().newChangesSnapshot(startingSeqNo, endSeqNo, true);
2363+
}
2364+
23552365
/**
23562366
* Checks if we have a completed history of operations since the given starting seqno (inclusive).
23572367
* This method should be called after acquiring the retention lock; See {@link #acquireHistoryRetentionLock()}

server/src/main/java/org/opensearch/index/translog/InternalTranslogManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public void rollTranslogGeneration() throws TranslogException {
9797
}
9898
}
9999

100+
@Override
101+
public Translog.Snapshot newChangesSnapshot(long fromSeqNo, long toSeqNo, boolean requiredFullRange) throws IOException {
102+
return translog.newSnapshot(fromSeqNo, toSeqNo, requiredFullRange);
103+
}
104+
100105
/**
101106
* Performs recovery from the transaction log up to {@code recoverUpToSeqNo} (inclusive).
102107
* This operation will close the engine if the recovery fails.

server/src/main/java/org/opensearch/index/translog/NoOpTranslogManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,9 @@ public Translog.Operation readOperation(Translog.Location location) throws IOExc
112112
public Translog.Location add(Translog.Operation operation) throws IOException {
113113
return new Translog.Location(0, 0, 0);
114114
}
115+
116+
@Override
117+
public Translog.Snapshot newChangesSnapshot(long fromSeqNo, long toSeqNo, boolean requiredFullRange) throws IOException {
118+
throw new UnsupportedOperationException("Translog snapshot unsupported with no-op translogs");
119+
}
115120
}

server/src/main/java/org/opensearch/index/translog/TranslogManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public interface TranslogManager {
3333
*/
3434
int recoverFromTranslog(TranslogRecoveryRunner translogRecoveryRunner, long localCheckpoint, long recoverUpToSeqNo) throws IOException;
3535

36+
/**
37+
* Creates a new history snapshot from the translog file instead of the lucene index.
38+
*/
39+
Translog.Snapshot newChangesSnapshot(long fromSeqNo, long toSeqNo, boolean requiredFullRange) throws IOException;
40+
3641
/**
3742
* Checks if the underlying storage sync is required.
3843
*/

server/src/main/java/org/opensearch/index/translog/WriteOnlyTranslogManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,9 @@ public int recoverFromTranslog(TranslogRecoveryRunner translogRecoveryRunner, lo
6666
public void skipTranslogRecovery() {
6767
// Do nothing.
6868
}
69+
70+
@Override
71+
public Translog.Snapshot newChangesSnapshot(long fromSeqNo, long toSeqNo, boolean requiredFullRange) throws IOException {
72+
throw new UnsupportedOperationException("Translog snapshot unsupported with no-op translogs");
73+
}
6974
}

0 commit comments

Comments
 (0)