Skip to content

Commit

Permalink
Removing default implementation of getProcessedLocalCheckpoint
Browse files Browse the repository at this point in the history
This now requires implementations in child classes. NRTReplicationEngine already has an implementation, so an @OverRide annotation has been added. For ReadOnlyEngine, where no processing occurs, the processed local checkpoint is expected to be equal to the persisted local checkpoint. Unit test for ReadOnlyEngine have been updated.

Signed-off-by: Kartik Ganesh <[email protected]>
  • Loading branch information
kartg committed Jun 2, 2022
1 parent caca533 commit 91372c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions server/src/main/java/org/opensearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,7 @@ public final CommitStats commitStats() {
* @return the latest checkpoint that has been processed but not necessarily persisted.
* Also see {@link #getPersistedLocalCheckpoint()}
*/
public long getProcessedLocalCheckpoint() {
// default implementation
return 0L;
}
public abstract long getProcessedLocalCheckpoint();

/**
* @return a {@link SeqNoStats} object, using local state and the supplied global checkpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public long getPersistedLocalCheckpoint() {
return localCheckpointTracker.getPersistedCheckpoint();
}

@Override
public long getProcessedLocalCheckpoint() {
return localCheckpointTracker.getProcessedCheckpoint();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ public long getPersistedLocalCheckpoint() {
return seqNoStats.getLocalCheckpoint();
}

@Override
public long getProcessedLocalCheckpoint() {
// the read-only engine does not process checkpoints, so its
// processed checkpoint is identical to its persisted one.
return getPersistedLocalCheckpoint();
}

@Override
public SeqNoStats getSeqNoStats(long globalCheckpoint) {
return new SeqNoStats(seqNoStats.getMaxSeqNo(), seqNoStats.getLocalCheckpoint(), globalCheckpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void testReadOnlyEngine() throws Exception {
lastSeqNoStats = engine.getSeqNoStats(globalCheckpoint.get());
lastDocIds = getDocIds(engine, true);
assertThat(readOnlyEngine.getPersistedLocalCheckpoint(), equalTo(lastSeqNoStats.getLocalCheckpoint()));
assertThat(readOnlyEngine.getProcessedLocalCheckpoint(), equalTo(readOnlyEngine.getPersistedLocalCheckpoint()));
assertThat(readOnlyEngine.getSeqNoStats(globalCheckpoint.get()).getMaxSeqNo(), equalTo(lastSeqNoStats.getMaxSeqNo()));
assertThat(getDocIds(readOnlyEngine, false), equalTo(lastDocIds));
for (int i = 0; i < numDocs; i++) {
Expand All @@ -131,6 +132,7 @@ public void testReadOnlyEngine() throws Exception {
IOUtils.close(external, internal);
// the locked down engine should still point to the previous commit
assertThat(readOnlyEngine.getPersistedLocalCheckpoint(), equalTo(lastSeqNoStats.getLocalCheckpoint()));
assertThat(readOnlyEngine.getProcessedLocalCheckpoint(), equalTo(readOnlyEngine.getPersistedLocalCheckpoint()));
assertThat(readOnlyEngine.getSeqNoStats(globalCheckpoint.get()).getMaxSeqNo(), equalTo(lastSeqNoStats.getMaxSeqNo()));
assertThat(getDocIds(readOnlyEngine, false), equalTo(lastDocIds));
try (Engine.GetResult getResult = readOnlyEngine.get(get, readOnlyEngine::acquireSearcher)) {
Expand All @@ -142,6 +144,7 @@ public void testReadOnlyEngine() throws Exception {
recoveringEngine.recoverFromTranslog(translogHandler, Long.MAX_VALUE);
// the locked down engine should still point to the previous commit
assertThat(readOnlyEngine.getPersistedLocalCheckpoint(), equalTo(lastSeqNoStats.getLocalCheckpoint()));
assertThat(readOnlyEngine.getProcessedLocalCheckpoint(), equalTo(readOnlyEngine.getPersistedLocalCheckpoint()));
assertThat(readOnlyEngine.getSeqNoStats(globalCheckpoint.get()).getMaxSeqNo(), equalTo(lastSeqNoStats.getMaxSeqNo()));
assertThat(getDocIds(readOnlyEngine, false), equalTo(lastDocIds));
}
Expand Down

0 comments on commit 91372c6

Please sign in to comment.