diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricSearcher.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricSearcher.java index 2c6cca7e5e..341103c107 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricSearcher.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricSearcher.java @@ -20,7 +20,6 @@ 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 @@ 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 MetricSearcher(String baseDir, String baseFileName, Charset charset) { this.baseDir += File.separator; } this.baseFileName = baseFileName; - extractedMetricSearcher = new ExtractedMetricSearcher(charset); + metricsReader = new MetricsReader(charset); } /** @@ -100,7 +99,7 @@ public synchronized List find(long beginTimeMs, int recommendLines) 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 synchronized List findByTimeAndResource(long beginTimeMs, lon 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 @@ private boolean validPosition(long beginTimeMs) { } } - private List readMetrics(List fileNames, int pos, - long offset, int recommendLines) throws Exception { - List list = new ArrayList(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; diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/ExtractedMetricSearcher.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricsReader.java similarity index 86% rename from sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/ExtractedMetricSearcher.java rename to sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricsReader.java index 5159ab703c..3dc1e2c975 100644 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/ExtractedMetricSearcher.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricsReader.java @@ -7,14 +7,14 @@ 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 @@ && readMetricsInOneFileByEndTime(list, fileNames.get(pos++), 0, endTimeMs, ident } return list; } + + List readMetrics(List fileNames, int pos, + long offset, int recommendLines) throws Exception { + List list = new ArrayList(recommendLines); + readMetricsInOneFile(list, fileNames.get(pos++), offset, recommendLines); + while (list.size() < recommendLines && pos < fileNames.size()) { + readMetricsInOneFile(list, fileNames.get(pos++), 0, recommendLines); + } + return list; + } } \ No newline at end of file