Skip to content

Commit

Permalink
Add deprecated API for creating History Ops Snapshot from translog (#…
Browse files Browse the repository at this point in the history
…2886)

* Add deprecated API for creating History Ops Snapshot from translog

Adds a deprecated API to create a history operations snapshot from the translog.
This was superseded by always using the lucene index for peer recovery since the
index saves on costly storage but this API enables plugins to selectively use
the uncompressed xlog file for speed over disk savings. Note: this API will be
either completely removed or refactored in the next release.

Signed-off-by: Nicholas Walter Knize <[email protected]>
Signed-off-by: Sai Kumar <[email protected]>

* fix javadoc casing for deprecated

Signed-off-by: Nicholas Walter Knize <[email protected]>

Co-authored-by: Nicholas Walter Knize <[email protected]>
  • Loading branch information
saikaranam-amazon and nknize authored Apr 15, 2022
1 parent 7bd7f2f commit 2069aa3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
13 changes: 13 additions & 0 deletions server/src/main/java/org/opensearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,19 @@ public abstract Translog.Snapshot newChangesSnapshot(
boolean accurateCount
) throws IOException;

/**
* Reads history operations from the translog file instead of the lucene index
*
* @deprecated reading history operations from the translog file is deprecated and will be removed in the next release
*/
@Deprecated
public abstract Translog.Snapshot newChangesSnapshotFromTranslogFile(
String source,
long fromSeqNo,
long toSeqNo,
boolean requiredFullRange
) throws IOException;

/**
* Counts the number of history operations in the given sequence number range
* @param source source of the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2821,6 +2821,20 @@ public Translog.Snapshot newChangesSnapshot(
}
}

/**
* Creates a new history snapshot from the translog file instead of the lucene index
*
* @deprecated reading history operations from the translog file is deprecated and will be removed in the next release
*
* Use {@link Engine#newChangesSnapshot(String, long, long, boolean, boolean)} instead
*/
@Deprecated
@Override
public Translog.Snapshot newChangesSnapshotFromTranslogFile(String source, long fromSeqNo, long toSeqNo, boolean requiredFullRange)
throws IOException {
return getTranslog().newSnapshot(fromSeqNo, toSeqNo, requiredFullRange);
}

public int countNumberOfHistoryOperations(String source, long fromSeqNo, long toSeqNo) throws IOException {
ensureOpen();
refreshIfNeeded(source, toSeqNo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ public Translog.Snapshot newChangesSnapshot(
return newEmptySnapshot();
}

/**
* Creates a new history snapshot from the translog file instead of the lucene index
*
* @deprecated reading history operations from the translog file is deprecated and will be removed in the next release
*
* Use {@link Engine#newChangesSnapshot(String, long, long, boolean, boolean)} instead
*/
@Deprecated
@Override
public Translog.Snapshot newChangesSnapshotFromTranslogFile(String source, long fromSeqNo, long toSeqNo, boolean requiredFullRange)
throws IOException {
return newEmptySnapshot();
}

@Override
public int countNumberOfHistoryOperations(String source, long fromSeqNo, long toSeqNo) throws IOException {
try (Translog.Snapshot snapshot = newChangesSnapshot(source, fromSeqNo, toSeqNo, false, true)) {
Expand Down
14 changes: 13 additions & 1 deletion server/src/main/java/org/opensearch/index/shard/IndexShard.java
Original file line number Diff line number Diff line change
Expand Up @@ -2233,13 +2233,25 @@ public Closeable acquireHistoryRetentionLock() {
/**
* Creates a new history snapshot for reading operations since
* the provided starting seqno (inclusive) and ending seqno (inclusive)
* The returned snapshot can be retrieved from either Lucene index or translog files.
* The returned snapshot is retrieved from a Lucene index.
*/
public Translog.Snapshot getHistoryOperations(String reason, long startingSeqNo, long endSeqNo, boolean accurateCount)
throws IOException {
return getEngine().newChangesSnapshot(reason, startingSeqNo, endSeqNo, true, accurateCount);
}

/**
* Creates a new history snapshot from the translog file instead of the lucene index
*
* @deprecated reading history operations from the translog file is deprecated and will be removed in the next release
*
* Use {@link IndexShard#getHistoryOperations(String, long, long, boolean)} instead
*/
@Deprecated
public Translog.Snapshot getHistoryOperationsFromTranslogFile(String reason, long startingSeqNo, long endSeqNo) throws IOException {
return getEngine().newChangesSnapshotFromTranslogFile(reason, startingSeqNo, endSeqNo, true);
}

/**
* Checks if we have a completed history of operations since the given starting seqno (inclusive).
* This method should be called after acquiring the retention lock; See {@link #acquireHistoryRetentionLock()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6318,10 +6318,30 @@ public void testHistoryBasedOnSource() throws Exception {
}
}
List<Translog.Operation> luceneOps = readAllOperationsBasedOnSource(engine);
// todo remove in next release
List<Translog.Operation> translogOps = readAllOperationsBasedOnTranslog(engine);
assertThat(luceneOps.stream().map(o -> o.seqNo()).collect(Collectors.toList()), containsInAnyOrder(expectedSeqNos.toArray()));
assertThat(translogOps.stream().map(o -> o.seqNo()).collect(Collectors.toList()), containsInAnyOrder(expectedSeqNos.toArray()));
}
}

/**
* Test creating new snapshot from translog file
*
* @deprecated reading history operations from the translog file is deprecated and will be removed in the next release
*/
@Deprecated
private static List<Translog.Operation> readAllOperationsBasedOnTranslog(Engine engine) throws IOException {
final List<Translog.Operation> operations = new ArrayList<>();
try (Translog.Snapshot snapshot = engine.newChangesSnapshotFromTranslogFile("test", 0, Long.MAX_VALUE, false)) {
Translog.Operation op;
while ((op = snapshot.next()) != null) {
operations.add(op);
}
}
return operations;
}

public void testLuceneHistoryOnPrimary() throws Exception {
final List<Engine.Operation> operations = generateSingleDocHistory(
false,
Expand Down

0 comments on commit 2069aa3

Please sign in to comment.