Procházet zdrojové kódy

Renamed to MetricsReader

master
Shalti 李豪 před 6 roky
rodič
revize
dc0a7086b5
2 změnil soubory, kde provedl 16 přidání a 17 odebrání
  1. +4
    -15
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricSearcher.java
  2. +12
    -2
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricsReader.java

+ 4
- 15
sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricSearcher.java Zobrazit soubor

@@ -20,7 +20,6 @@ import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.csp.sentinel.config.SentinelConfig;
@@ -35,7 +34,7 @@ import com.alibaba.csp.sentinel.config.SentinelConfig;
public class MetricSearcher {

private static final Charset defaultCharset = Charset.forName(SentinelConfig.charset());
private final ExtractedMetricSearcher extractedMetricSearcher;
private final MetricsReader metricsReader;

private String baseDir;
private String baseFileName;
@@ -70,7 +69,7 @@ public class MetricSearcher {
this.baseDir += File.separator;
}
this.baseFileName = baseFileName;
extractedMetricSearcher = new ExtractedMetricSearcher(charset);
metricsReader = new MetricsReader(charset);
}

/**
@@ -100,7 +99,7 @@ public class MetricSearcher {
MetricWriter.formIndexFileName(fileName), offsetInIndex);
offsetInIndex = 0;
if (offset != -1) {
return readMetrics(fileNames, i, offset, recommendLines);
return metricsReader.readMetrics(fileNames, i, offset, recommendLines);
}
}
return null;
@@ -135,7 +134,7 @@ public class MetricSearcher {
fileName + MetricWriter.METRIC_FILE_INDEX_SUFFIX, offsetInIndex);
offsetInIndex = 0;
if (offset != -1) {
return extractedMetricSearcher.readMetricsByEndTime(fileNames, i, offset, endTimeMs, identity);
return metricsReader.readMetricsByEndTime(fileNames, i, offset, endTimeMs, identity);
}
}
return null;
@@ -191,16 +190,6 @@ public class MetricSearcher {
}
}

private List<MetricNode> readMetrics(List<String> fileNames, int pos,
long offset, int recommendLines) throws Exception {
List<MetricNode> list = new ArrayList<MetricNode>(recommendLines);
extractedMetricSearcher.readMetricsInOneFile(list, fileNames.get(pos++), offset, recommendLines);
while (list.size() < recommendLines && pos < fileNames.size()) {
extractedMetricSearcher.readMetricsInOneFile(list, fileNames.get(pos++), 0, recommendLines);
}
return list;
}

private long findOffset(long beginTime, String metricFileName,
String idxFileName, long offsetInIndex) throws Exception {
lastPosition.metricFileName = null;


sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/ExtractedMetricSearcher.java → sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricsReader.java Zobrazit soubor

@@ -7,14 +7,14 @@ import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

class ExtractedMetricSearcher {
class MetricsReader {
/**
* avoid OOM in any case
*/
private static final int maxLinesReturn = 100000;
private Charset charset;

public ExtractedMetricSearcher(Charset charset) {
public MetricsReader(Charset charset) {
this.charset = charset;
}

@@ -104,4 +104,14 @@ class ExtractedMetricSearcher {
}
return list;
}

List<MetricNode> readMetrics(List<String> fileNames, int pos,
long offset, int recommendLines) throws Exception {
List<MetricNode> list = new ArrayList<MetricNode>(recommendLines);
readMetricsInOneFile(list, fileNames.get(pos++), offset, recommendLines);
while (list.size() < recommendLines && pos < fileNames.size()) {
readMetricsInOneFile(list, fileNames.get(pos++), 0, recommendLines);
}
return list;
}
}

Načítá se…
Zrušit
Uložit