Skip to content

Commit

Permalink
Refactor SegmentReplicationTargetService to only hold completed targe…
Browse files Browse the repository at this point in the history
…t state instead of the entire target. (opensearch-project#11043)

Signed-off-by: Marc Handalian <[email protected]>
  • Loading branch information
mch2 authored and rayshrey committed Mar 18, 2024
1 parent aff8b1a commit 600231d
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class SegmentReplicationTargetService implements IndexEventListener {

private final ReplicationCollection<SegmentReplicationTarget> onGoingReplications;

private final Map<ShardId, SegmentReplicationTarget> completedReplications = ConcurrentCollections.newConcurrentMap();
private final Map<ShardId, SegmentReplicationState> completedReplications = ConcurrentCollections.newConcurrentMap();

private final SegmentReplicationSourceFactory sourceFactory;

Expand Down Expand Up @@ -192,7 +192,7 @@ public SegmentReplicationState getOngoingEventSegmentReplicationState(ShardId sh
*/
@Nullable
public SegmentReplicationState getlatestCompletedEventSegmentReplicationState(ShardId shardId) {
return Optional.ofNullable(completedReplications.get(shardId)).map(SegmentReplicationTarget::state).orElse(null);
return completedReplications.get(shardId);
}

/**
Expand Down Expand Up @@ -525,7 +525,7 @@ public void onResponse(Void o) {
logger.debug(() -> new ParameterizedMessage("Finished replicating {} marking as done.", target.description()));
onGoingReplications.markAsDone(replicationId);
if (target.state().getIndex().recoveredFileCount() != 0 && target.state().getIndex().recoveredBytes() != 0) {
completedReplications.put(target.shardId(), target);
completedReplications.put(target.shardId(), target.state());
}
}

Expand Down

0 comments on commit 600231d

Please sign in to comment.