Skip to content

Commit 8fedee6

Browse files
committed
Addressing PR comments
Signed-off-by: Ankit Kala <[email protected]>
1 parent 0b58668 commit 8fedee6

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
2929
- Plugin ZIP publication groupId value is configurable ([#4156](https://github.com/opensearch-project/OpenSearch/pull/4156))
3030
- Add index specific setting for remote repository ([#4253](https://github.com/opensearch-project/OpenSearch/pull/4253))
3131
- [Segment Replication] Update replicas to commit SegmentInfos instead of relying on SIS files from primary shards. ([#4402](https://github.com/opensearch-project/OpenSearch/pull/4402))
32+
- [CCR] Add getHistoryOperationsFromTranslog method to fetch the history snapshot from translogs ([#3948](https://github.com/opensearch-project/OpenSearch/pull/3948))
3233

3334
### Deprecated
3435

@@ -78,4 +79,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
7879

7980

8081
[Unreleased]: https://github.com/opensearch-project/OpenSearch/compare/2.2.0...HEAD
81-
[2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.2.0...2.x
82+
[2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.2.0...2.x

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,10 +2360,12 @@ public Translog.Snapshot getHistoryOperations(String reason, long startingSeqNo,
23602360
/**
23612361
* Creates a new history snapshot from the translog instead of the lucene index. Required for cross cluster replication.
23622362
* Use the recommended {@link #getHistoryOperations(String, long, long, boolean)} method for other cases.
2363-
* Depending on how translog durability is configured, this method might/might not return the snapshot. For e.g,
2364-
* If the translog has been configured with no-durability, it'll return UnsupportedOperationException.
2363+
* This method should only be invoked if Segment Replication or Remote Store is not enabled.
23652364
*/
23662365
public Translog.Snapshot getHistoryOperationsFromTranslog(long startingSeqNo, long endSeqNo) throws IOException {
2366+
if (indexSettings.isSegRepEnabled() || indexSettings.isRemoteStoreEnabled()) {
2367+
throw new AssertionError("unsupported operation for segment replication enabled indices or remote store backed indices");
2368+
}
23672369
return getEngine().translogManager().newChangesSnapshot(startingSeqNo, endSeqNo, true);
23682370
}
23692371

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

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

1199+
public void testGetChangesSnapshotThrowsAssertForSegRep() throws IOException {
1200+
final ShardId shardId = new ShardId("index", "_na_", 0);
1201+
final ShardRouting shardRouting = TestShardRouting.newShardRouting(
1202+
shardId,
1203+
randomAlphaOfLength(8),
1204+
true,
1205+
ShardRoutingState.INITIALIZING,
1206+
RecoverySource.EmptyStoreRecoverySource.INSTANCE
1207+
);
1208+
final Settings settings = Settings.builder()
1209+
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
1210+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2)
1211+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
1212+
.put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT.toString())
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+
expectThrows(AssertionError.class, () -> primaryShard.getHistoryOperationsFromTranslog(0, 1));
1226+
closeShard(primaryShard, false);
1227+
}
1228+
1229+
public void testGetChangesSnapshotThrowsAssertForRemoteStore() throws IOException {
1230+
final ShardId shardId = new ShardId("index", "_na_", 0);
1231+
final ShardRouting shardRouting = TestShardRouting.newShardRouting(
1232+
shardId,
1233+
randomAlphaOfLength(8),
1234+
true,
1235+
ShardRoutingState.INITIALIZING,
1236+
RecoverySource.EmptyStoreRecoverySource.INSTANCE
1237+
);
1238+
final Settings settings = Settings.builder()
1239+
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT)
1240+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2)
1241+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
1242+
.put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, true)
1243+
.build();
1244+
final IndexMetadata.Builder indexMetadata = IndexMetadata.builder(shardRouting.getIndexName()).settings(settings).primaryTerm(0, 1);
1245+
final AtomicBoolean synced = new AtomicBoolean();
1246+
final IndexShard primaryShard = newShard(
1247+
shardRouting,
1248+
indexMetadata.build(),
1249+
null,
1250+
new InternalEngineFactory(),
1251+
() -> synced.set(true),
1252+
RetentionLeaseSyncer.EMPTY,
1253+
null
1254+
);
1255+
expectThrows(AssertionError.class, () -> primaryShard.getHistoryOperationsFromTranslog(0, 1));
1256+
closeShard(primaryShard, false);
1257+
}
1258+
11991259
public void testGlobalCheckpointSync() throws IOException {
12001260
// create the primary shard with a callback that sets a boolean when the global checkpoint sync is invoked
12011261
final ShardId shardId = new ShardId("index", "_na_", 0);

0 commit comments

Comments
 (0)