Skip to content

Commit 6984436

Browse files
committed
Addressing PR comments
Signed-off-by: Ankit Kala <[email protected]>
1 parent f3a18b8 commit 6984436

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

server/src/main/java/org/opensearch/index/shard/IndexShard.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,10 +2355,12 @@ public Translog.Snapshot getHistoryOperations(String reason, long startingSeqNo,
23552355
/**
23562356
* Creates a new history snapshot from the translog instead of the lucene index. Required for cross cluster replication.
23572357
* Use the recommended {@link #getHistoryOperations(String, long, long, boolean)} method for other cases.
2358-
* Depending on how translog durability is configured, this method might/might not return the snapshot. For e.g,
2359-
* If the translog has been configured with no-durability, it'll return UnsupportedOperationException.
2358+
* This method should only be invoked if Segment Replication is not enabled.
23602359
*/
23612360
public Translog.Snapshot getHistoryOperationsFromTranslog(long startingSeqNo, long endSeqNo) throws IOException {
2361+
if (indexSettings.isSegRepEnabled()) {
2362+
throw new AssertionError("newChangesSnapshot should not be invoked for Segment Replication enabled indices");
2363+
}
23622364
return getEngine().translogManager().newChangesSnapshot(startingSeqNo, endSeqNo, true);
23632365
}
23642366

server/src/test/java/org/opensearch/index/shard/IndexShardTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,36 @@ public void testAcquireReplicaPermitAdvanceMaxSeqNoOfUpdates() throws Exception
11961196
closeShards(replica);
11971197
}
11981198

1199+
1200+
public void testGetChangesSnapshotThrowsAssertForSegRep() throws IOException {
1201+
final ShardId shardId = new ShardId("index", "_na_", 0);
1202+
final ShardRouting shardRouting = TestShardRouting.newShardRouting(
1203+
shardId,
1204+
randomAlphaOfLength(8),
1205+
true,
1206+
ShardRoutingState.INITIALIZING,
1207+
RecoverySource.EmptyStoreRecoverySource.INSTANCE
1208+
);
1209+
final Settings settings = Settings.builder()
1210+
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
1211+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2)
1212+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
1213+
.build();
1214+
final IndexMetadata.Builder indexMetadata = IndexMetadata.builder(shardRouting.getIndexName()).settings(settings).primaryTerm(0, 1);
1215+
final AtomicBoolean synced = new AtomicBoolean();
1216+
final IndexShard primaryShard = newShard(
1217+
shardRouting,
1218+
indexMetadata.build(),
1219+
null,
1220+
new InternalEngineFactory(),
1221+
() -> synced.set(true),
1222+
RetentionLeaseSyncer.EMPTY,
1223+
null
1224+
);
1225+
1226+
expectThrows(AssertionError.class, () -> primaryShard.getHistoryOperationsFromTranslog(0, 1));
1227+
}
1228+
11991229
public void testGlobalCheckpointSync() throws IOException {
12001230
// create the primary shard with a callback that sets a boolean when the global checkpoint sync is invoked
12011231
final ShardId shardId = new ShardId("index", "_na_", 0);

0 commit comments

Comments
 (0)