Skip to content

Commit

Permalink
Add IndexShard#getLatestReplicationCheckpoint behind segrep enable fe…
Browse files Browse the repository at this point in the history
…ature flag

Signed-off-by: Suraj Singh <surajrider@gmail.com>
  • Loading branch information
dreamer-89 committed Aug 8, 2022
1 parent 6993ac9 commit a1baa7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1396,10 +1396,13 @@ public GatedCloseable<IndexCommit> acquireSafeIndexCommit() throws EngineExcepti
}

/**
* Returns the lastest Replication Checkpoint that shard received. Shards will return an EMPTY checkpoint before
* the engine is opened.
* Returns the latest ReplicationCheckpoint that shard received.
* @return EMPTY checkpoint before the engine is opened and null for non-segrep enabled indices
*/
public ReplicationCheckpoint getLatestReplicationCheckpoint() {
if (indexSettings.isSegRepEnabled() == false) {
return null;
}
if (getEngineOrNull() == null) {
return ReplicationCheckpoint.empty(shardId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
import org.opensearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.opensearch.indices.recovery.RecoveryState;
import org.opensearch.indices.recovery.RecoveryTarget;
import org.opensearch.indices.replication.checkpoint.ReplicationCheckpoint;
import org.opensearch.indices.replication.checkpoint.SegmentReplicationCheckpointPublisher;
import org.opensearch.indices.replication.common.ReplicationLuceneIndex;
import org.opensearch.indices.replication.common.ReplicationType;
Expand Down Expand Up @@ -3500,6 +3501,27 @@ public void testReadSnapshotConcurrently() throws IOException, InterruptedExcept
closeShards(newShard);
}

/**
* Test that latestReplicationCheckpoint returns null only for docrep enabled indices
*/
public void testReplicationCheckpointNullForDocRep() throws IOException {
Settings indexSettings = Settings.builder().put(IndexMetadata.SETTING_REPLICATION_TYPE, "DOCUMENT").put(Settings.EMPTY).build();
final IndexShard indexShard = newStartedShard(false, indexSettings);
assertNull(indexShard.getLatestReplicationCheckpoint());
closeShards(indexShard);
}

/**
* Test that latestReplicationCheckpoint returns ReplicationCheckpoint for segrep enabled indices
*/
public void testReplicationCheckpointNotNullForSegReb() throws IOException {
Settings indexSettings = Settings.builder().put(IndexMetadata.SETTING_REPLICATION_TYPE, "SEGMENT").put(Settings.EMPTY).build();
final IndexShard indexShard = newStartedShard(indexSettings);
final ReplicationCheckpoint replicationCheckpoint = indexShard.getLatestReplicationCheckpoint();
assertNotNull(replicationCheckpoint);
closeShards(indexShard);
}

/**
* here we are mocking a SegmentReplicationcheckpointPublisher and testing on index shard if CheckpointRefreshListener is added to the InternalrefreshListerners List
*/
Expand Down

0 comments on commit a1baa7a

Please sign in to comment.