Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,17 @@ private Map<String, ResourceAssignment> partialRebalance(

// Asynchronously report baseline divergence metric before persisting to metadata store,
// just in case if persisting fails, we still have the metric.
// To avoid changes of the new assignment and make it safe when being used to measure baseline
// divergence, use a deep copy of the new assignment.
Map<String, ResourceAssignment> newAssignmentCopy = new HashMap<>();
for (Map.Entry<String, ResourceAssignment> entry : newAssignment.entrySet()) {
newAssignmentCopy.put(entry.getKey(), new ResourceAssignment(entry.getValue().getRecord()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Luckily we have

new ResourceAssignment(ZNRecord)

which is creating a deep copy of a resource assignment.

Copy link
Contributor Author

@huizhilu huizhilu Oct 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZNRecord has mapFields which is a nested map: Map<String, Map<String, String>>. Caling putAll doesn't do deep copy. Still have to do deep copy manually.
If we can do deep copy for #549, we can keep this code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a copy constructor works.

}
BaselineDivergenceGauge baselineDivergenceGauge = _metricCollector.getMetric(
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.BaselineDivergenceGauge.name(),
BaselineDivergenceGauge.class);
baselineDivergenceGauge.asyncMeasureAndUpdateValue(clusterData.getAsyncTasksThreadPool(),
currentBaseline, newAssignment);
currentBaseline, newAssignmentCopy);

if (_assignmentMetadataStore != null) {
try {
Expand Down