Skip to content

Commit 3a3da4f

Browse files
[Segment Replication] [Remote Store] Replace overriding mockInternalEngine() in test classes with NRTReplicationEngine. (#11716)
* Replace overriding mockInternalEngine() in test classes with NRTReplicationEngine. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * remove unused comment. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Add comment for explaining the conditional logic. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Update comment with exact reason for conditional logic. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> --------- Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com>
1 parent 714fa73 commit 3a3da4f

File tree

7 files changed

+8
-31
lines changed

7 files changed

+8
-31
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationBaseIT.java

-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
6060
return asList(MockTransportService.TestPlugin.class);
6161
}
6262

63-
@Override
64-
protected boolean addMockInternalEngine() {
65-
return false;
66-
}
67-
6863
@Override
6964
public Settings indexSettings() {
7065
return Settings.builder()

server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationClusterSettingIT.java

-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ public Settings indexSettings() {
5252
.build();
5353
}
5454

55-
@Override
56-
protected boolean addMockInternalEngine() {
57-
return false;
58-
}
59-
6055
public void testIndexReplicationSettingOverridesSegRepClusterSetting() throws Exception {
6156
Settings settings = Settings.builder().put(CLUSTER_SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT).build();
6257
final String ANOTHER_INDEX = "test-index";

server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteIndexPrimaryRelocationIT.java

-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ protected Settings nodeSettings(int nodeOrdinal) {
3535
.build();
3636
}
3737

38-
@Override
39-
protected boolean addMockInternalEngine() {
40-
return false;
41-
}
42-
4338
public Settings indexSettings() {
4439
return Settings.builder()
4540
.put(super.indexSettings())

server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteStoreBaseIntegTestCase.java

-5
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@ protected Map<String, Long> indexData(int numberOfIterations, boolean invokeFlus
121121
return indexingStats;
122122
}
123123

124-
@Override
125-
protected boolean addMockInternalEngine() {
126-
return false;
127-
}
128-
129124
@Override
130125
protected Settings nodeSettings(int nodeOrdinal) {
131126
if (segmentRepoPath == null || translogRepoPath == null) {

server/src/internalClusterTest/java/org/opensearch/remotestore/SegmentReplicationUsingRemoteStoreDisruptionIT.java

-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ public Settings indexSettings() {
4444
return remoteStoreIndexSettings(1);
4545
}
4646

47-
@Override
48-
protected boolean addMockInternalEngine() {
49-
return false;
50-
}
51-
5247
public void testCancelReplicationWhileSyncingSegments() throws Exception {
5348
Path location = randomRepoPath().toAbsolutePath();
5449
setup(location, 0d, "metadata", Long.MAX_VALUE, 1);

server/src/internalClusterTest/java/org/opensearch/snapshots/SegmentReplicationSnapshotIT.java

-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ public Settings restoreIndexDocRepSettings() {
7474
return Settings.builder().put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.DOCUMENT).build();
7575
}
7676

77-
@Override
78-
protected boolean addMockInternalEngine() {
79-
return false;
80-
}
81-
8277
public void ingestData(int docCount, String indexName) throws Exception {
8378
for (int i = 0; i < docCount; i++) {
8479
client().prepareIndex(indexName).setId(Integer.toString(i)).setSource("field", "value" + i).execute().actionGet();

test/framework/src/main/java/org/opensearch/test/engine/MockEngineFactory.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.opensearch.index.engine.Engine;
3636
import org.opensearch.index.engine.EngineConfig;
3737
import org.opensearch.index.engine.EngineFactory;
38+
import org.opensearch.index.engine.NRTReplicationEngine;
3839

3940
public final class MockEngineFactory implements EngineFactory {
4041

@@ -46,6 +47,12 @@ public MockEngineFactory(Class<? extends FilterDirectoryReader> wrapper) {
4647

4748
@Override
4849
public Engine newReadWriteEngine(EngineConfig config) {
49-
return new MockInternalEngine(config, wrapper);
50+
51+
/**
52+
* Segment replication enabled replicas (i.e. read only replicas) do not use an InternalEngine so a MockInternalEngine
53+
* will not work and an NRTReplicationEngine must be used instead. The primary shards for these indexes will
54+
* still use a MockInternalEngine.
55+
*/
56+
return config.isReadOnlyReplica() ? new NRTReplicationEngine(config) : new MockInternalEngine(config, wrapper);
5057
}
5158
}

0 commit comments

Comments
 (0)