Skip to content

Commit ee0f52c

Browse files
huizhilujiajunwang
authored andcommitted
Implement increment() method in CountMetric class. (apache#537)
Abstract method increaseCount() in CountMetric is a generic method used in inherited classes. We should implement this method in CountMetric to reduce duplicate code in inherited classes. Change list: 1. Move increaseCount() to CountMetric. 2. Change the name to increment() and implement the method.
1 parent 1d58d2b commit ee0f52c

4 files changed

Lines changed: 27 additions & 15 deletions

File tree

helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public Map<String, IdealState> computeNewIdealStates(ResourceControllerDataProvi
185185
CountMetric rebalanceFailureCount = _metricCollector.getMetric(
186186
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.RebalanceFailureCounter.name(),
187187
CountMetric.class);
188-
rebalanceFailureCount.increaseCount(1L);
188+
rebalanceFailureCount.increment(1L);
189189

190190
HelixRebalanceException.Type failureType = ex.getFailureType();
191191
if (failureType.equals(HelixRebalanceException.Type.INVALID_REBALANCER_STATUS) || failureType
@@ -332,7 +332,7 @@ private void refreshBaseline(ResourceControllerDataProvider clusterData,
332332
CountMetric globalBaselineCalcCounter = _metricCollector.getMetric(
333333
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.GlobalBaselineCalcCounter.name(),
334334
CountMetric.class);
335-
globalBaselineCalcCounter.increaseCount(1L);
335+
globalBaselineCalcCounter.increment(1L);
336336

337337
LatencyMetric globalBaselineCalcLatency = _metricCollector.getMetric(
338338
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.GlobalBaselineCalcLatencyGauge
@@ -379,7 +379,7 @@ private Map<String, ResourceAssignment> partialRebalance(
379379
CountMetric partialRebalanceCounter = _metricCollector.getMetric(
380380
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.PartialRebalanceCounter.name(),
381381
CountMetric.class);
382-
partialRebalanceCounter.increaseCount(1L);
382+
partialRebalanceCounter.increment(1L);
383383

384384
LatencyMetric partialRebalanceLatency = _metricCollector.getMetric(
385385
WagedRebalancerMetricCollector.WagedRebalancerMetricNames.PartialRebalanceLatencyGauge

helix-core/src/main/java/org/apache/helix/monitoring/metrics/implementation/RebalanceCounter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,10 @@
2727
*/
2828
public class RebalanceCounter extends CountMetric {
2929
/**
30-
* Instantiates a new count metric.
30+
* Instantiates a new rebalance count metric.
3131
* @param metricName the metric name
3232
*/
3333
public RebalanceCounter(String metricName) {
3434
super(metricName, 0L);
3535
}
36-
37-
@Override
38-
public void increaseCount(long count) {
39-
updateValue(getValue() + count);
40-
}
4136
}
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
package org.apache.helix.monitoring.metrics.implementation;
22

3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
322
import org.apache.helix.monitoring.metrics.model.CountMetric;
423

24+
525
public class RebalanceFailureCount extends CountMetric {
626
/**
727
* Instantiates a new Simple dynamic metric.
@@ -11,9 +31,4 @@ public class RebalanceFailureCount extends CountMetric {
1131
public RebalanceFailureCount(String metricName) {
1232
super(metricName, 0L);
1333
}
14-
15-
@Override
16-
public void increaseCount(long count) {
17-
updateValue(getValue() + count);
18-
}
1934
}

helix-core/src/main/java/org/apache/helix/monitoring/metrics/model/CountMetric.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public CountMetric(String metricName, long initCount) {
4343
*
4444
* @param count
4545
*/
46-
public abstract void increaseCount(long count);
46+
public void increment(long count) {
47+
updateValue(getValue() + count);
48+
}
4749

4850
@Override
4951
public String getMetricName() {

0 commit comments

Comments
 (0)