Skip to content

Commit

Permalink
[Cherry Pick #29979] Fix race condition in Dataflow sampler. (#30144)
Browse files Browse the repository at this point in the history
* make getProcessingDistributionsForWorkId synchronized to avoid race conditions with remove tracker

* correctly access the concurrent hashmap to avoid race conditions

---------

Co-authored-by: Claire McCarthy <[email protected]>
  • Loading branch information
lostluck and clmccart authored Jan 30, 2024
1 parent d1d3457 commit 1c974aa
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,10 @@ public Optional<ActiveMessageMetadata> getActiveMessageMetadataForWorkId(String
}

public Map<String, IntSummaryStatistics> getProcessingDistributionsForWorkId(String workId) {
if (!activeTrackersByWorkId.containsKey(workId)) {
if (completedProcessingMetrics.containsKey(workId)) {
return completedProcessingMetrics.get(workId);
}
return new HashMap<>();
}
DataflowExecutionStateTracker tracker = activeTrackersByWorkId.get(workId);
if (tracker == null) {
return completedProcessingMetrics.getOrDefault(workId, new HashMap<>());
}
return mergeStepStatsMaps(
completedProcessingMetrics.getOrDefault(workId, new HashMap<>()),
tracker.getProcessingTimesByStepCopy());
Expand Down

0 comments on commit 1c974aa

Please sign in to comment.