-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move segment replication setting to IndexMetadata so that it can be s…
…et during index creation. (#2284) This change also adds an integration test - SegmentReplicationIT. Signed-off-by: Marc Handalian <[email protected]>
- Loading branch information
Showing
5 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.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,59 @@ | ||
/* | ||
* 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.cluster.metadata.IndexMetadata; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.test.BackgroundIndexer; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope; | ||
|
||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount; | ||
|
||
@ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class SegmentReplicationIT extends OpenSearchIntegTestCase { | ||
|
||
private static final String INDEX_NAME = "test-idx-1"; | ||
private static final int SHARD_COUNT = 1; | ||
private static final int REPLICA_COUNT = 1; | ||
|
||
public void testReplicationAfterPrimaryRefreshAndFlush() throws Exception { | ||
final String nodeA = internalCluster().startNode(); | ||
final String nodeB = internalCluster().startNode(); | ||
createIndex( | ||
INDEX_NAME, | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, SHARD_COUNT) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, REPLICA_COUNT) | ||
.put(IndexMetadata.SETTING_SEGMENT_REPLICATION, true) | ||
.build() | ||
); | ||
ensureGreen(INDEX_NAME); | ||
|
||
final int initialDocCount = scaledRandomIntBetween(0, 200); | ||
try (BackgroundIndexer indexer = new BackgroundIndexer(INDEX_NAME, "_doc", client(), initialDocCount)) { | ||
waitForDocs(initialDocCount, indexer); | ||
} | ||
refresh(INDEX_NAME); | ||
// wait a short amount of time to give replication a chance to complete. | ||
Thread.sleep(1000); | ||
assertHitCount(client(nodeA).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount); | ||
assertHitCount(client(nodeB).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), initialDocCount); | ||
|
||
final int additionalDocCount = scaledRandomIntBetween(0, 200); | ||
final int totalDocs = initialDocCount + additionalDocCount; | ||
try (BackgroundIndexer indexer = new BackgroundIndexer(INDEX_NAME, "_doc", client(), additionalDocCount)) { | ||
waitForDocs(additionalDocCount, indexer); | ||
} | ||
flush(INDEX_NAME); | ||
Thread.sleep(1000); | ||
assertHitCount(client(nodeA).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), totalDocs); | ||
assertHitCount(client(nodeB).prepareSearch(INDEX_NAME).setSize(0).setPreference("_only_local").get(), totalDocs); | ||
} | ||
} |
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