Skip to content

Commit

Permalink
Handle close index on getLatestReplicationCheckpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <surajrider@gmail.com>
  • Loading branch information
dreamer-89 committed Sep 15, 2022
1 parent 629d5ce commit 0690605
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import org.opensearch.index.engine.EngineFactory;
import org.opensearch.index.engine.NRTReplicationEngine;
import org.opensearch.index.engine.InternalEngine;
import org.opensearch.index.engine.NoOpEngine;
import org.opensearch.index.engine.ReadOnlyEngine;
import org.opensearch.index.engine.RefreshFailedEngineException;
import org.opensearch.index.engine.SafeCommitInfo;
Expand Down Expand Up @@ -1397,7 +1398,8 @@ public ReplicationCheckpoint getLatestReplicationCheckpoint() {
if (indexSettings.isSegRepEnabled() == false) {
return null;
}
if (getEngineOrNull() == null) {
final IndexMetadata indexMetadata = indexSettings.getIndexMetadata();
if (getEngineOrNull() == null || (indexMetadata != null && indexMetadata.getState() == IndexMetadata.State.CLOSE)) {
return ReplicationCheckpoint.empty(shardId);
}
try (final GatedCloseable<SegmentInfos> snapshot = getSegmentInfosSnapshot()) {
Expand Down Expand Up @@ -2728,7 +2730,6 @@ public long getLocalCheckpoint() {
*/
public long getProcessedLocalCheckpoint() {
// Returns checkpoint only if the current engine is an instance of NRTReplicationEngine or InternalEngine
logger.info("--> getProcessedLocalCheckpoint {}", this.getEngine().getClass());
return getReplicationEngine().map(NRTReplicationEngine::getProcessedLocalCheckpoint).orElseGet(() -> {
final Engine engine = getEngine();
assert engine instanceof InternalEngine;
Expand All @@ -2737,7 +2738,6 @@ public long getProcessedLocalCheckpoint() {
}

private Optional<NRTReplicationEngine> getReplicationEngine() {
logger.info("--> getEngine() instanceof NRTReplicationEngine {}", getEngine() instanceof NRTReplicationEngine);
if (getEngine() instanceof NRTReplicationEngine) {
return Optional.of((NRTReplicationEngine) getEngine());
} else {
Expand Down

0 comments on commit 0690605

Please sign in to comment.