-
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
Toggle replication strategy based on segrep index setting #2318
Toggle replication strategy based on segrep index setting #2318
Conversation
Can one of the admins verify this patch? |
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.
Looks like a great start!
We will also need to conditionally wire up the CheckpointRefreshListener here so that checkpoints are not published on primary refresh. We should probably also add a condition in IndexShard's onNewCheckpoint method to be safe.
@@ -277,17 +277,25 @@ public InternalEngine(EngineConfig engineConfig) { | |||
); | |||
this.localCheckpointTracker = createLocalCheckpointTracker(localCheckpointTrackerSupplier); | |||
// TODO: Segrep - should have a separate read only engine rather than all this conditional logic. | |||
if (engineConfig.isPrimary()) { | |||
if (engineConfig.getIndexSettings().isSegrepEnabled()) { |
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.
Wiring up primary shards is the same in both cases. We can remove some duplication here with:
if (engineConfig.getIndexSettings().isSegrepEnabled && engineConfig.isPrimary() == false) {
... setup replica
} else {
..setup primary
}
import org.apache.lucene.index.LeafReaderContext; | ||
import org.apache.lucene.index.SegmentInfos; | ||
import org.apache.lucene.index.StandardDirectoryReader; | ||
import org.apache.lucene.index.*; |
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.
we should leave the specific imports as is here. My Intellij sometimes does this by default and had to change in Preferences > code style > java and mark use single class import and change `Class count to use import with '*' to a high number.
@@ -3910,8 +3912,10 @@ ReplicationTracker getReplicationTracker() { | |||
public boolean scheduledRefresh() { | |||
// skip if not primary shard. | |||
// TODO: Segrep - should split into primary/replica classes. | |||
if (shardRouting.primary() == false) { | |||
return false; | |||
if (indexSettings.isSegrepEnabled()) { |
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.
nit - can be on one line.
❌ Gradle Check failure 6b3809d751aa6ddb8fce85fb52259e7c10652152 |
❌ Gradle Check failure 7f8e55dd04fd56375a7f99562e6f5bd44644d81f |
7f8e55d
to
5950974
Compare
❌ Gradle Check failure 5950974c5a2d3f93290f82052469054a4331db8c |
❌ Gradle Check failure 7ff8fa8f5aed46bc988e83d67e44684cef749d3e |
@@ -259,6 +259,17 @@ public void validate(final Integer numRoutingShards, final Map<Setting<?>, Objec | |||
Property.IndexScope | |||
); | |||
|
|||
public static final String SETTING_SEGMENT_REPLICATION = "index.replication.segment_replication"; |
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.
Needs a rebase here, the setting changes were merged.
@@ -277,17 +277,17 @@ public InternalEngine(EngineConfig engineConfig) { | |||
); | |||
this.localCheckpointTracker = createLocalCheckpointTracker(localCheckpointTrackerSupplier); | |||
// TODO: Segrep - should have a separate read only engine rather than all this conditional logic. | |||
if (engineConfig.isPrimary()) { | |||
if ((engineConfig.getIndexSettings().isSegrepEnabled()) && engineConfig.isPrimary() == false) { |
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.
I think we should take this opportunity to rename isPrimary() to isReadOnly(), where replicas are readOnly. This is a stepping stone to further refactoring into a read only engine implementation.
@@ -582,7 +582,8 @@ private void recoverFromTranslogInternal(TranslogRecoveryRunner translogRecovery | |||
translog.currentFileGeneration() | |||
) | |||
); | |||
if (engineConfig.isPrimary()) { | |||
boolean segrep = engineConfig.getIndexSettings().isSegrepEnabled(); | |||
if ((segrep == false) || (segrep && engineConfig.isPrimary())) { |
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 condition shows up ~5 times, lets pull out a small private method, something like isReadOnlyReplica() == false.
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.
Done
@@ -32,10 +32,6 @@ | |||
|
|||
package org.opensearch.index.engine; | |||
|
|||
import java.io.IOException; |
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.
Was this reorder intentional? Think this may be IDE.
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.
I left it in since this seems to be the standard order followed by all other files
@@ -2067,7 +2068,9 @@ private void innerOpenEngineAndTranslog(LongSupplier globalCheckpointSupplier) t | |||
// which settings changes could possibly have happened, so here we forcefully push any config changes to the new engine. | |||
onSettingsChanged(); | |||
// TODO: Segrep - Fix | |||
// assert assertSequenceNumbersInCommit(); |
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.
I think this method call may be ok to uncomment now with segrep enabled. We can take that as a separate change.
@@ -2715,7 +2718,9 @@ public void syncRetentionLeases() { | |||
assert assertPrimaryMode(); | |||
verifyNotClosed(); | |||
// TODO: Segrep - Fix retention leases | |||
// replicationTracker.renewPeerRecoveryRetentionLeases(); |
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.
Leaving a note here similar to the above - I think this may be ok to uncomment now with segrep enabled. This was commented before we were correctly wiring up retention leases for replicas.
Signed-off-by: Poojita Raj <[email protected]> index writer null exception Signed-off-by: Poojita Raj <[email protected]> included conditional logic Signed-off-by: Poojita Raj <[email protected]> internal listener fix Signed-off-by: Poojita Raj <[email protected]>
Signed-off-by: Poojita Raj <[email protected]>
Signed-off-by: Poojita Raj <[email protected]>
7ff8fa8
to
e8437bd
Compare
@@ -883,7 +883,7 @@ public int getNumberOfReplicas() { | |||
} | |||
|
|||
public boolean isSegrepEnabled() { | |||
return isSegrepEnabled; | |||
return Boolean.TRUE.equals(isSegrepEnabled); |
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.
nit - this isn't required bc we always initialize this variable in the constructor.
isSegrepEnabled = settings.getAsBoolean(IndexMetadata.SETTING_SEGMENT_REPLICATION, false);
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.
True but leaving it in to convert to boolean which is faster since we don't need a thread safe implementation.
@@ -346,7 +350,7 @@ public InternalEngine(EngineConfig engineConfig) { | |||
|
|||
@Override | |||
public void updateCurrentInfos(byte[] infosBytes, long gen, long seqNo) throws IOException { | |||
assert engineConfig.isPrimary() == false : "Only replicas should update Infos"; | |||
assert engineConfig.isReadOnly() == true : "Only replicas should update Infos"; |
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.
nit - this failure message is a bit confusing with the rename. Perhaps 'Only read only replicas should update Infos'
Description
Docrep and segrep should be able to work in parallel with this change. Previously, commented code was breaking docrep
Resolves #2197
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.