-
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
Segment Replication - Release incorrectly retained commits on primary shards #6660
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
|
||
package org.opensearch.indices.replication; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||
import org.opensearch.OpenSearchException; | ||
import org.opensearch.action.ActionListener; | ||
import org.opensearch.cluster.node.DiscoveryNode; | ||
|
@@ -26,6 +29,7 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -91,6 +95,8 @@ synchronized CopyState getCachedCopyState(ReplicationCheckpoint checkpoint) thro | |
} | ||
} | ||
|
||
private static final Logger logger = LogManager.getLogger(OngoingSegmentReplications.class); | ||
|
||
/** | ||
* Start sending files to the replica. | ||
* | ||
|
@@ -163,8 +169,8 @@ synchronized void cancel(IndexShard shard, String reason) { | |
/** | ||
* Cancel all Replication events for the given allocation ID, intended to be called when a primary is shutting down. | ||
* | ||
* @param allocationId {@link String} - Allocation ID. | ||
* @param reason {@link String} - Reason for the cancel | ||
* @param allocationId {@link String} - Allocation ID. | ||
* @param reason {@link String} - Reason for the cancel | ||
*/ | ||
synchronized void cancel(String allocationId, String reason) { | ||
final SegmentReplicationSourceHandler handler = allocationIdToHandlers.remove(allocationId); | ||
|
@@ -195,6 +201,11 @@ int size() { | |
return allocationIdToHandlers.size(); | ||
} | ||
|
||
// Visible for tests. | ||
Map<String, SegmentReplicationSourceHandler> getHandlers() { | ||
return allocationIdToHandlers; | ||
} | ||
|
||
int cachedCopyStateSize() { | ||
return copyStateMap.size(); | ||
} | ||
|
@@ -254,8 +265,22 @@ private void cancelHandlers(Predicate<? super SegmentReplicationSourceHandler> p | |
.filter(predicate) | ||
.map(SegmentReplicationSourceHandler::getAllocationId) | ||
.collect(Collectors.toList()); | ||
logger.warn(() -> new ParameterizedMessage("Cancelling replications for allocationIds {}", allocationIds)); | ||
for (String allocationId : allocationIds) { | ||
cancel(allocationId, reason); | ||
} | ||
} | ||
|
||
/** | ||
* Clear copystate and target handlers for any non insync allocationIds. | ||
* @param shardId {@link ShardId} | ||
* @param inSyncAllocationIds {@link List} of in-sync allocation Ids. | ||
*/ | ||
public void clearOutOfSyncIds(ShardId shardId, Set<String> inSyncAllocationIds) { | ||
cancelHandlers( | ||
(handler) -> handler.getCopyState().getShard().shardId().equals(shardId) | ||
&& inSyncAllocationIds.contains(handler.getAllocationId()) == false, | ||
"Shard is no longer in-sync with the primary" | ||
); | ||
Comment on lines
+280
to
+284
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. nit: Can we add a unit test validating cancellation ? 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. added |
||
} | ||
} |
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
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.
I think irrespective of whether replica has different segment files, this test will pass ?. Can we assert on a different allocationID on shard to ensure shard indeed failed on replica ?
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.
added this.