Skip to content
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

Conversation

Poojita-Raj
Copy link
Contributor

@Poojita-Raj Poojita-Raj commented Mar 3, 2022

Description

Docrep and segrep should be able to work in parallel with this change. Previously, commented code was breaking docrep

  • test docrep by running IndexRecoveryIT

Resolves #2197

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

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.

@opensearch-ci-bot
Copy link
Collaborator

Can one of the admins verify this patch?

Copy link
Member

@mch2 mch2 left a 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()) {
Copy link
Member

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.*;
Copy link
Member

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()) {
Copy link
Member

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.

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 6b3809d751aa6ddb8fce85fb52259e7c10652152
Log 2949

Reports 2949

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 7f8e55dd04fd56375a7f99562e6f5bd44644d81f
Log 3035

Reports 3035

@Poojita-Raj Poojita-Raj force-pushed the feature/segment-replication branch from 7f8e55d to 5950974 Compare March 5, 2022 01:44
@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 5950974c5a2d3f93290f82052469054a4331db8c
Log 3069

Reports 3069

@Poojita-Raj Poojita-Raj marked this pull request as ready for review March 7, 2022 17:48
@Poojita-Raj Poojita-Raj requested a review from a team as a code owner March 7, 2022 17:48
@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 7ff8fa8f5aed46bc988e83d67e44684cef749d3e
Log 3119

Reports 3119

@Poojita-Raj Poojita-Raj changed the title Feature/segment replication Toggle replication strategy based on segrep index setting Mar 7, 2022
@@ -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";
Copy link
Member

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) {
Copy link
Member

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())) {
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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();
Copy link
Member

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();
Copy link
Member

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]>
@Poojita-Raj Poojita-Raj force-pushed the feature/segment-replication branch from 7ff8fa8 to e8437bd Compare March 7, 2022 23:20
@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure e8437bd
Log 3147

Reports 3147

@@ -883,7 +883,7 @@ public int getNumberOfReplicas() {
}

public boolean isSegrepEnabled() {
return isSegrepEnabled;
return Boolean.TRUE.equals(isSegrepEnabled);
Copy link
Member

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);

Copy link
Contributor Author

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";
Copy link
Member

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'

@Poojita-Raj Poojita-Raj merged commit 9341099 into opensearch-project:feature/segment-replication Mar 8, 2022
@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 3d0124e
Log 3186

Reports 3186

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants