Use calculateTimeIdx to calculate array idx in LeapArray#getPreviousWindow (#723)

* also some code cleanup
This commit is contained in:
kexianjun 2019-06-06 06:02:44 +08:00 committed by Eric Zhao
parent ee38587a6e
commit 0176f0ead3
3 changed files with 6 additions and 8 deletions

View File

@ -147,8 +147,7 @@ public class StatisticNode implements Node {
@Override
public long totalRequest() {
long totalRequest = rollingCounterInMinute.pass() + rollingCounterInMinute.block();
return totalRequest;
return rollingCounterInMinute.pass() + rollingCounterInMinute.block();
}
@Override

View File

@ -209,8 +209,7 @@ public abstract class LeapArray<T> {
if (timeMillis < 0) {
return null;
}
long timeId = (timeMillis - windowLengthInMs) / windowLengthInMs;
int idx = (int)(timeId % array.length());
int idx = calculateTimeIdx(timeMillis - windowLengthInMs);
timeMillis = timeMillis - windowLengthInMs;
WindowWrap<T> wrap = array.get(idx);

View File

@ -234,8 +234,8 @@ public class ArrayMetric implements Metric {
@Override
public long previousWindowBlock() {
WindowWrap<MetricBucket> wrap = data.currentWindow();
wrap = data.getPreviousWindow();
data.currentWindow();
WindowWrap<MetricBucket> wrap = data.getPreviousWindow();
if (wrap == null) {
return 0;
}
@ -244,8 +244,8 @@ public class ArrayMetric implements Metric {
@Override
public long previousWindowPass() {
WindowWrap<MetricBucket> wrap = data.currentWindow();
wrap = data.getPreviousWindow();
data.currentWindow();
WindowWrap<MetricBucket> wrap = data.getPreviousWindow();
if (wrap == null) {
return 0;
}