-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Backport 2.x] [Segment Replication] Backport PR's : #3525 #3533 #3540 #3943 #3963 From main branch #4181
Merged
Rishikesh1159
merged 9 commits into
opensearch-project:2.x
from
Rishikesh1159:backport/backport-3525-3533-3540
Aug 11, 2022
Merged
[Backport 2.x] [Segment Replication] Backport PR's : #3525 #3533 #3540 #3943 #3963 From main branch #4181
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
48e8ade
Resolving import conflict in Node.java and mergining PR https://githu…
mch2 6cffde4
Resolving conflicts and merging PR https://github.com/opensearch-proj…
Poojita-Raj 9b83b52
Resolving conflicts and Merging PR https://github.com/opensearch-proj…
Rishikesh1159 d979fd2
Applying spotlesscheck and fixing wildcard imports.
Rishikesh1159 8ea270f
[Segment Replication] Fixing flaky test failure happening for testSha…
Rishikesh1159 24c2e0b
Fix possible flaky test for testBeforeIndexShardClosed_CancelsOngoing…
Rishikesh1159 4b60a68
Removing assert segrep() in getProcessedLocalCheckpoint() of Index.sh…
Rishikesh1159 8c5753b
Adding back assert statement and make index setting to segment replic…
Rishikesh1159 7f6da3f
Revert "Adding back assert statement and make index setting to segmen…
Rishikesh1159 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
72 changes: 72 additions & 0 deletions
72
server/src/main/java/org/opensearch/indices/RunUnderPrimaryPermit.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,72 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.action.ActionListener; | ||
import org.opensearch.common.lease.Releasable; | ||
import org.opensearch.common.util.CancellableThreads; | ||
import org.opensearch.common.util.concurrent.FutureUtils; | ||
import org.opensearch.index.shard.IndexShard; | ||
import org.opensearch.index.shard.IndexShardRelocatedException; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Execute a Runnable after acquiring the primary's operation permit. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public final class RunUnderPrimaryPermit { | ||
|
||
public static void run( | ||
CancellableThreads.Interruptible runnable, | ||
String reason, | ||
IndexShard primary, | ||
CancellableThreads cancellableThreads, | ||
Logger logger | ||
) { | ||
cancellableThreads.execute(() -> { | ||
CompletableFuture<Releasable> permit = new CompletableFuture<>(); | ||
final ActionListener<Releasable> onAcquired = new ActionListener<>() { | ||
@Override | ||
public void onResponse(Releasable releasable) { | ||
if (permit.complete(releasable) == false) { | ||
releasable.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
permit.completeExceptionally(e); | ||
} | ||
}; | ||
primary.acquirePrimaryOperationPermit(onAcquired, ThreadPool.Names.SAME, reason); | ||
try (Releasable ignored = FutureUtils.get(permit)) { | ||
// check that the IndexShard still has the primary authority. This needs to be checked under operation permit to prevent | ||
// races, as IndexShard will switch its authority only when it holds all operation permits, see IndexShard.relocated() | ||
if (primary.isRelocatedPrimary()) { | ||
throw new IndexShardRelocatedException(primary.shardId()); | ||
} | ||
runnable.run(); | ||
} finally { | ||
// just in case we got an exception (likely interrupted) while waiting for the get | ||
permit.whenComplete((r, e) -> { | ||
if (r != null) { | ||
r.close(); | ||
} | ||
if (e != null) { | ||
logger.trace("suppressing exception on completion (it was already bubbled up or the operation was aborted)", e); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
server/src/main/java/org/opensearch/indices/recovery/FileChunkWriter.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,31 @@ | ||
/* | ||
* 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.recovery; | ||
|
||
import org.opensearch.action.ActionListener; | ||
import org.opensearch.common.bytes.BytesReference; | ||
import org.opensearch.index.store.StoreFileMetadata; | ||
|
||
/** | ||
* Writes a partial file chunk to the target store. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
@FunctionalInterface | ||
public interface FileChunkWriter { | ||
|
||
void writeFileChunk( | ||
StoreFileMetadata fileMetadata, | ||
long position, | ||
BytesReference content, | ||
boolean lastChunk, | ||
int totalTranslogOps, | ||
ActionListener<Void> listener | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 assert has been removed because it is failing many unit tests in SegmentReplicationTargetServiceTests.java and SegmentReplicationIndexShardTests.java. The unit tests in these classes don't use index setting as SEGMENT, so when an assert is done on if segRepEnabled() all of the shards fails the assert and don't perform necessary unit tests.
This assert has been added to 2.x branch in this backport PR. As the original PR had method getProcessedLocalCheckpoint() in Engine.java as abstract which is a breaking. To avoid breaking breaking changes we made few changes to original PR while backporting. And this assert is part of those changes. It is not necessary to have this assert as it will any how be removed in 3.0 opensearch
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 added the
SEGMENT
index setting in test classes. Can we backport #4163 if it helps ?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 it might help actually, but let me check by backporting your PR locally and add back assert statement to see if all of the unit tests pass
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 tried adding back assert and use SEGMENT replication as index setting in unit tests. But got this error:
so there are multiple places we have to makes changes to make this work and I don't think this PR is right place to do all changes. We can do them while backporting other PR's. So for now I am removing assert statement