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 Nov 3, 2023
1 parent 38999b2 commit 54fa050
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 54fa050

Please sign in to comment.