Skip to content

Commit 8cedaf8

Browse files
committed
fix copyOf bug
1 parent 8764f08 commit 8cedaf8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

presto-common/src/main/java/com/facebook/presto/common/RuntimeMetric.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,15 @@ private static long determineBucketWidth(RuntimeUnit unit)
226226
}
227227

228228
public static RuntimeMetric copyOf(RuntimeMetric metric)
229+
{
230+
return copyOf(metric, metric.getName());
231+
}
232+
233+
public static RuntimeMetric copyOf(RuntimeMetric metric, String newName)
229234
{
230235
requireNonNull(metric, "metric is null");
231-
RuntimeMetric copy = new RuntimeMetric(metric.getName(), metric.getUnit(),
236+
requireNonNull(newName, "newName is null");
237+
RuntimeMetric copy = new RuntimeMetric(newName, metric.getUnit(),
232238
metric.percentileTrackingEnabled, metric.bucketWidth, metric.numBuckets);
233239
copy.set(metric.getSum(), metric.getCount(), metric.getMax(), metric.getMin());
234240
if (metric.histogramBuckets != null) {

presto-common/src/main/java/com/facebook/presto/common/RuntimeStats.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void mergeMetric(String name, RuntimeMetric metric)
116116
RuntimeMetric existing = metrics.get(name);
117117
if (existing == null) {
118118
// First time seeing this metric - create a copy to preserve configuration
119-
metrics.put(name, RuntimeMetric.copyOf(metric));
119+
metrics.put(name, RuntimeMetric.copyOf(metric, name));
120120
}
121121
else {
122122
// Metric already exists - merge into it
@@ -157,13 +157,11 @@ public void update(RuntimeStats stats)
157157
stats.getMetrics().forEach((name, newMetric) -> {
158158
RuntimeMetric existing = metrics.get(name);
159159
if (existing == null) {
160-
// First time seeing this metric - create with matching configuration to avoid set() validation errors
161-
// Use basic constructor without percentile tracking (update is for stats only, not config)
162-
RuntimeMetric created = new RuntimeMetric(name, newMetric.getUnit(), false, newMetric.getBucketWidth(), newMetric.getNumBuckets());
163-
created.set(newMetric);
164-
metrics.put(name, created);
160+
// First time seeing this metric - copy it entirely to establish configuration
161+
metrics.put(name, RuntimeMetric.copyOf(newMetric));
165162
}
166163
else {
164+
// Metric exists - update values only (set() validates matching configurations)
167165
existing.set(newMetric);
168166
}
169167
});

0 commit comments

Comments
 (0)