Skip to content

Commit 1a2c70b

Browse files
committed
Incorporating PR comments
Signed-off-by: Kartik Ganesh <[email protected]>
1 parent 6ecb560 commit 1a2c70b

File tree

3 files changed

+11
-62
lines changed

3 files changed

+11
-62
lines changed

server/src/main/java/org/opensearch/index/engine/InternalEngine.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,8 +2307,6 @@ public SegmentInfos getLatestSegmentInfos() {
23072307

23082308
@Override
23092309
public GatedCloseable<SegmentInfos> getSegmentInfosSnapshot() {
2310-
// this should never be called by read-only engines
2311-
assert (engineConfig.isReadOnlyReplica() == false);
23122310
final SegmentInfos segmentInfos = getLatestSegmentInfos();
23132311
try {
23142312
indexWriter.incRefDeleter(segmentInfos);

server/src/main/java/org/opensearch/indices/replication/SegmentReplicationSourceService.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,15 @@ private synchronized CopyState getCachedCopyState(ReplicationCheckpoint checkpoi
121121
final IndexShard indexShard = indexService.getShard(shardId.id());
122122
// build the CopyState object and cache it before returning
123123
final CopyState copyState = new CopyState(indexShard);
124-
// TODO This will add with the latest checkpoint, not the one from the request
125-
addToCopyStateMap(copyState);
124+
125+
/**
126+
* Use the checkpoint from the request as the key in the map, rather than
127+
* the checkpoint from the created CopyState. This maximizes cache hits
128+
* if replication targets make a request with an older checkpoint.
129+
* Replication targets are expected to fetch the checkpoint in the response
130+
* CopyState to bring themselves up to date.
131+
*/
132+
addToCopyStateMap(checkpoint, copyState);
126133
return copyState;
127134
}
128135
}
@@ -131,8 +138,8 @@ private synchronized CopyState getCachedCopyState(ReplicationCheckpoint checkpoi
131138
* Adds the input {@link CopyState} object to {@link #copyStateMap}.
132139
* The key is the CopyState's {@link ReplicationCheckpoint} object.
133140
*/
134-
private void addToCopyStateMap(CopyState copyState) {
135-
copyStateMap.putIfAbsent(copyState.getCheckpoint(), copyState);
141+
private void addToCopyStateMap(ReplicationCheckpoint checkpoint, CopyState copyState) {
142+
copyStateMap.putIfAbsent(checkpoint, copyState);
136143
}
137144

138145
/**

server/src/test/java/org/opensearch/index/engine/InternalEngineTests.java

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@
147147
import org.opensearch.index.translog.TranslogConfig;
148148
import org.opensearch.index.translog.TranslogDeletionPolicyFactory;
149149
import org.opensearch.indices.breaker.NoneCircuitBreakerService;
150-
import org.opensearch.indices.replication.common.ReplicationType;
151150
import org.opensearch.test.IndexSettingsModule;
152151
import org.opensearch.test.VersionUtils;
153152
import org.opensearch.threadpool.ThreadPool;
@@ -7388,61 +7387,6 @@ public void testMaxDocsOnReplica() throws Exception {
73887387
}
73897388
}
73907389

7391-
public void testGetSegmentInfosSnapshot_OnReadReplica() throws IOException {
7392-
engine.close();
7393-
Store store = createStore();
7394-
// create an engine just so we can easily fetch the engine config constructor parameters
7395-
InternalEngine tempEngine = createEngine(store, createTempDir());
7396-
EngineConfig tempConfig = tempEngine.config();
7397-
// read-only engine config requires the replication type setting to be SEGMENT
7398-
final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(
7399-
"test",
7400-
Settings.builder()
7401-
.put(defaultSettings.getSettings())
7402-
.put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT)
7403-
.build()
7404-
);
7405-
// create the read-only engine config
7406-
EngineConfig readOnlyEngineConfig = new EngineConfig(
7407-
tempConfig.getShardId(),
7408-
tempConfig.getThreadPool(),
7409-
indexSettings,
7410-
tempConfig.getWarmer(),
7411-
store,
7412-
tempConfig.getMergePolicy(),
7413-
tempConfig.getAnalyzer(),
7414-
tempConfig.getSimilarity(),
7415-
new CodecService(null, logger),
7416-
tempConfig.getEventListener(),
7417-
tempConfig.getQueryCache(),
7418-
tempConfig.getQueryCachingPolicy(),
7419-
tempConfig.getTranslogConfig(),
7420-
null,
7421-
tempConfig.getFlushMergesAfter(),
7422-
tempConfig.getExternalRefreshListener(),
7423-
tempConfig.getInternalRefreshListener(),
7424-
tempConfig.getIndexSort(),
7425-
tempConfig.getCircuitBreakerService(),
7426-
tempConfig.getGlobalCheckpointSupplier(),
7427-
tempConfig.retentionLeasesSupplier(),
7428-
tempConfig.getPrimaryTermSupplier(),
7429-
tempConfig.getTombstoneDocSupplier(),
7430-
true
7431-
);
7432-
// close engine now that it is no longer needed
7433-
tempEngine.close();
7434-
7435-
SetOnce<IndexWriter> indexWriterHolder = new SetOnce<>();
7436-
IndexWriterFactory indexWriterFactory = (directory, iwc) -> {
7437-
indexWriterHolder.set(new IndexWriter(directory, iwc));
7438-
return indexWriterHolder.get();
7439-
};
7440-
InternalEngine engine = createEngine(readOnlyEngineConfig);
7441-
expectThrows(AssertionError.class, engine::getSegmentInfosSnapshot);
7442-
engine.close();
7443-
store.close();
7444-
}
7445-
74467390
public void testGetSegmentInfosSnapshot() throws IOException {
74477391
IOUtils.close(store, engine);
74487392
Store store = createStore();

0 commit comments

Comments
 (0)