Skip to content

Commit

Permalink
[Segment Replication] [Remote Store] Replace overriding mockInternalE…
Browse files Browse the repository at this point in the history
…ngine() in test classes with NRTReplicationEngine. (opensearch-project#11716) (opensearch-project#11761)

* Replace overriding mockInternalEngine() in test classes with NRTReplicationEngine.



* remove unused comment.



* Add comment for explaining the conditional logic.



* Update comment with exact reason for conditional logic.



---------


(cherry picked from commit 3a3da4f)

Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 0cb2c6d commit 9426ee3
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
return asList(MockTransportService.TestPlugin.class);
}

@Override
protected boolean addMockInternalEngine() {
return false;
}

@Override
public Settings indexSettings() {
return Settings.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public Settings indexSettings() {
.build();
}

@Override
protected boolean addMockInternalEngine() {
return false;
}

public void testIndexReplicationSettingOverridesSegRepClusterSetting() throws Exception {
Settings settings = Settings.builder().put(CLUSTER_SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT).build();
final String ANOTHER_INDEX = "test-index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ protected Settings nodeSettings(int nodeOrdinal) {
.build();
}

@Override
protected boolean addMockInternalEngine() {
return false;
}

public Settings indexSettings() {
return Settings.builder()
.put(super.indexSettings())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ protected Map<String, Long> indexData(int numberOfIterations, boolean invokeFlus
return indexingStats;
}

@Override
protected boolean addMockInternalEngine() {
return false;
}

@Override
protected Settings nodeSettings(int nodeOrdinal) {
if (segmentRepoPath == null || translogRepoPath == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public Settings indexSettings() {
return remoteStoreIndexSettings(1);
}

@Override
protected boolean addMockInternalEngine() {
return false;
}

public void testCancelReplicationWhileSyncingSegments() throws Exception {
Path location = randomRepoPath().toAbsolutePath();
setup(location, 0d, "metadata", Long.MAX_VALUE, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ public Settings restoreIndexDocRepSettings() {
return Settings.builder().put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.DOCUMENT).build();
}

@Override
protected boolean addMockInternalEngine() {
return false;
}

public void ingestData(int docCount, String indexName) throws Exception {
for (int i = 0; i < docCount; i++) {
client().prepareIndex(indexName).setId(Integer.toString(i)).setSource("field", "value" + i).execute().actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opensearch.index.engine.Engine;
import org.opensearch.index.engine.EngineConfig;
import org.opensearch.index.engine.EngineFactory;
import org.opensearch.index.engine.NRTReplicationEngine;

public final class MockEngineFactory implements EngineFactory {

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

@Override
public Engine newReadWriteEngine(EngineConfig config) {
return new MockInternalEngine(config, wrapper);

/**
* Segment replication enabled replicas (i.e. read only replicas) do not use an InternalEngine so a MockInternalEngine
* will not work and an NRTReplicationEngine must be used instead. The primary shards for these indexes will
* still use a MockInternalEngine.
*/
return config.isReadOnlyReplica() ? new NRTReplicationEngine(config) : new MockInternalEngine(config, wrapper);
}
}

0 comments on commit 9426ee3

Please sign in to comment.