-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setting to enable segment replication as default replication type.
Signed-off-by: Rishikesh1159 <[email protected]>
- Loading branch information
1 parent
e6a3700
commit 5065732
Showing
5 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...ernalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationDefaultIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.indices.replication; | ||
|
||
import org.opensearch.action.admin.indices.replication.SegmentReplicationStatsResponse; | ||
import org.opensearch.cluster.ClusterInfoServiceIT; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.index.IndexModule; | ||
import org.opensearch.indices.SystemIndexDescriptor; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.plugins.SystemIndexPlugin; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.opensearch.test.transport.MockTransportService; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Arrays; | ||
|
||
import static org.opensearch.cluster.metadata.IndexMetadata.DEFAULT_REPLICATION_TYPE_SETTING_SEGMENT; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class SegmentReplicationDefaultIT extends OpenSearchIntegTestCase { | ||
|
||
protected static final String INDEX_NAME = "test-idx-1"; | ||
protected static final String SYSTEM_INDEX_NAME = ".test-cluster-info-system-index"; | ||
protected static final int SHARD_COUNT = 1; | ||
protected static final int REPLICA_COUNT = 1; | ||
|
||
@Override | ||
public Settings indexSettings() { | ||
return Settings.builder() | ||
.put(super.indexSettings()) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, SHARD_COUNT) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, REPLICA_COUNT) | ||
.put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), false) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected Settings featureFlagSettings() { | ||
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.REPLICATION_TYPE, "true").build(); | ||
} | ||
|
||
@Override | ||
protected boolean addMockInternalEngine() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put(DEFAULT_REPLICATION_TYPE_SETTING_SEGMENT.getKey(), true).build(); | ||
} | ||
|
||
public static class TestPlugin extends Plugin implements SystemIndexPlugin { | ||
@Override | ||
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) { | ||
return Collections.singletonList( | ||
new SystemIndexDescriptor(SYSTEM_INDEX_NAME, "System index for [" + getTestClass().getName() + ']') | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Arrays.asList(ClusterInfoServiceIT.TestPlugin.class, MockTransportService.TestPlugin.class); | ||
} | ||
|
||
public void testReplicationWithDefaultSegmentReplicationSetting() throws Exception { | ||
|
||
boolean isSystemIndex = randomBoolean(); | ||
String indexName = isSystemIndex ? SYSTEM_INDEX_NAME : INDEX_NAME; | ||
|
||
// Starting two nodes with primary and replica shards respectively. | ||
final String primaryNode = internalCluster().startNode(); | ||
createIndex(indexName); | ||
ensureYellowAndNoInitializingShards(indexName); | ||
final String replicaNode = internalCluster().startNode(); | ||
ensureGreen(indexName); | ||
|
||
final int initialDocCount = scaledRandomIntBetween(20, 30); | ||
for (int i = 0; i < initialDocCount; i++) { | ||
client().prepareIndex(indexName).setId(Integer.toString(i)).setSource("field", "value" + i).execute().actionGet(); | ||
} | ||
|
||
refresh(indexName); | ||
assertBusy(() -> { | ||
assertHitCount(client(replicaNode).prepareSearch(indexName).setSize(0).setPreference("_only_local").get(), initialDocCount); | ||
}); | ||
|
||
SegmentReplicationStatsResponse segmentReplicationStatsResponse = client().admin() | ||
.indices() | ||
.prepareSegmentReplicationStats(indexName) | ||
.execute() | ||
.actionGet(); | ||
if (isSystemIndex) { | ||
// Verify that Segment Replication did not happen on the replica shard. | ||
assertNull(segmentReplicationStatsResponse.getReplicationStats().get(indexName)); | ||
} else { | ||
// Verify that Segment Replication happened on the replica shard. | ||
assertFalse(segmentReplicationStatsResponse.getReplicationStats().get(indexName).get(0).getReplicaStats().isEmpty()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters