Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecated API for creating History Ops Snapshot from translog #2886

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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