-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move segment replication setting to IndexMetadata so that it can be set during index creation. #2284
Move segment replication setting to IndexMetadata so that it can be set during index creation. #2284
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this sleep to wait for flush operation to complete? And do we need to explicitly call flush? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sleep is to wait for the segment files to be copied over before we check the doc counts, without this we have a low risk that that process may not be complete. Yes, we call flush here so that we guarantee the primary is on a new commit point so we can test the replica can read it. |
||
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -503,22 +503,13 @@ public final class IndexSettings { | |
Setting.Property.IndexScope | ||
); | ||
|
||
/** | ||
* Used to specify if the index should use segment replication. If false, document replication is used. | ||
*/ | ||
public static final Setting<Boolean> INDEX_SEGMENT_REPLICATION_SETTING = Setting.boolSetting( | ||
"index.replication.segment_replication", | ||
false, | ||
Property.IndexScope, | ||
Property.Final | ||
); | ||
|
||
private final Index index; | ||
private final Version version; | ||
private final Logger logger; | ||
private final String nodeName; | ||
private final Settings nodeSettings; | ||
private final int numberOfShards; | ||
private final Boolean isSegrepEnabled; | ||
// volatile fields are updated via #updateIndexMetadata(IndexMetadata) under lock | ||
private volatile Settings settings; | ||
private volatile IndexMetadata indexMetadata; | ||
|
@@ -661,7 +652,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti | |
nodeName = Node.NODE_NAME_SETTING.get(settings); | ||
this.indexMetadata = indexMetadata; | ||
numberOfShards = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_SHARDS, null); | ||
|
||
isSegrepEnabled = settings.getAsBoolean(IndexMetadata.SETTING_SEGMENT_REPLICATION, false); | ||
this.searchThrottled = INDEX_SEARCH_THROTTLED.get(settings); | ||
this.queryStringLenient = QUERY_STRING_LENIENT_SETTING.get(settings); | ||
this.queryStringAnalyzeWildcard = QUERY_STRING_ANALYZE_WILDCARD.get(nodeSettings); | ||
|
@@ -891,6 +882,10 @@ public int getNumberOfReplicas() { | |
return settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, null); | ||
} | ||
|
||
public boolean isSegrepEnabled() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick - I'd prefer the method name to be explicit i.e. |
||
return isSegrepEnabled; | ||
} | ||
|
||
/** | ||
* Returns the node settings. The settings returned from {@link #getSettings()} are a merged version of the | ||
* index settings and the node settings where node settings are overwritten by index settings. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is numDataNodes set to 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sets the number of nodes to start the test with. If unset a random number is used.