Quellcode durchsuchen

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

* also some code cleanup
master
kexianjun Eric Zhao vor 5 Jahren
Ursprung
Commit
0176f0ead3
3 geänderte Dateien mit 6 neuen und 8 gelöschten Zeilen
  1. +1
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/StatisticNode.java
  2. +1
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/LeapArray.java
  3. +4
    -4
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/metric/ArrayMetric.java

+ 1
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/StatisticNode.java Datei anzeigen

@@ -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


+ 1
- 2
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/LeapArray.java Datei anzeigen

@@ -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);



+ 4
- 4
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/metric/ArrayMetric.java Datei anzeigen

@@ -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;
}


Laden…
Abbrechen
Speichern