-
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.
Browse files
Browse the repository at this point in the history
…#3943 #3963 From main branch (#4181) * Resolving import conflict in Node.java and mergining PR #3525. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Resolving conflicts and merging PR #3533. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Resolving conflicts and Merging PR #3540. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Applying spotlesscheck and fixing wildcard imports. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * [Segment Replication] Fixing flaky test failure happening for testShardAlreadyReplicating() (#3943) * Fixing flaky test failure happening for testShardAlreadyReplicating() Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Fix possible flaky test for testBeforeIndexShardClosed_CancelsOngoingReplications() (#3963) * Fixing flaky test failure happening for testShardAlreadyReplicating() Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Removing assert segrep() in getProcessedLocalCheckpoint() of Index.shard class. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Adding back assert statement and make index setting to segment replication in SegmentReplicationSourceHandlerTests and SegmentReplicationTargetServiceTests. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> * Revert "Adding back assert statement and make index setting to segment replication in SegmentReplicationSourceHandlerTests and SegmentReplicationTargetServiceTests." Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> This reverts commit 8c5753b. Signed-off-by: Rishikesh1159 <rishireddy1159@gmail.com> Co-authored-by: Marc Handalian <handalm@amazon.com> Co-authored-by: Poojita Raj <poojiraj@amazon.com>
- Loading branch information
1 parent
7062283
commit 97113b9
Showing
42 changed files
with
2,791 additions
and
514 deletions.
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.