Renamed to MetricsReader
This commit is contained in:
parent
ac8698ed9f
commit
dc0a7086b5
|
|
@ -20,7 +20,6 @@ import java.io.EOFException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.config.SentinelConfig;
|
import com.alibaba.csp.sentinel.config.SentinelConfig;
|
||||||
|
|
@ -35,7 +34,7 @@ import com.alibaba.csp.sentinel.config.SentinelConfig;
|
||||||
public class MetricSearcher {
|
public class MetricSearcher {
|
||||||
|
|
||||||
private static final Charset defaultCharset = Charset.forName(SentinelConfig.charset());
|
private static final Charset defaultCharset = Charset.forName(SentinelConfig.charset());
|
||||||
private final ExtractedMetricSearcher extractedMetricSearcher;
|
private final MetricsReader metricsReader;
|
||||||
|
|
||||||
private String baseDir;
|
private String baseDir;
|
||||||
private String baseFileName;
|
private String baseFileName;
|
||||||
|
|
@ -70,7 +69,7 @@ public class MetricSearcher {
|
||||||
this.baseDir += File.separator;
|
this.baseDir += File.separator;
|
||||||
}
|
}
|
||||||
this.baseFileName = baseFileName;
|
this.baseFileName = baseFileName;
|
||||||
extractedMetricSearcher = new ExtractedMetricSearcher(charset);
|
metricsReader = new MetricsReader(charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -100,7 +99,7 @@ public class MetricSearcher {
|
||||||
MetricWriter.formIndexFileName(fileName), offsetInIndex);
|
MetricWriter.formIndexFileName(fileName), offsetInIndex);
|
||||||
offsetInIndex = 0;
|
offsetInIndex = 0;
|
||||||
if (offset != -1) {
|
if (offset != -1) {
|
||||||
return readMetrics(fileNames, i, offset, recommendLines);
|
return metricsReader.readMetrics(fileNames, i, offset, recommendLines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -135,7 +134,7 @@ public class MetricSearcher {
|
||||||
fileName + MetricWriter.METRIC_FILE_INDEX_SUFFIX, offsetInIndex);
|
fileName + MetricWriter.METRIC_FILE_INDEX_SUFFIX, offsetInIndex);
|
||||||
offsetInIndex = 0;
|
offsetInIndex = 0;
|
||||||
if (offset != -1) {
|
if (offset != -1) {
|
||||||
return extractedMetricSearcher.readMetricsByEndTime(fileNames, i, offset, endTimeMs, identity);
|
return metricsReader.readMetricsByEndTime(fileNames, i, offset, endTimeMs, identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
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,
|
private long findOffset(long beginTime, String metricFileName,
|
||||||
String idxFileName, long offsetInIndex) throws Exception {
|
String idxFileName, long offsetInIndex) throws Exception {
|
||||||
lastPosition.metricFileName = null;
|
lastPosition.metricFileName = null;
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@ import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class ExtractedMetricSearcher {
|
class MetricsReader {
|
||||||
/**
|
/**
|
||||||
* avoid OOM in any case
|
* avoid OOM in any case
|
||||||
*/
|
*/
|
||||||
private static final int maxLinesReturn = 100000;
|
private static final int maxLinesReturn = 100000;
|
||||||
private Charset charset;
|
private Charset charset;
|
||||||
|
|
||||||
public ExtractedMetricSearcher(Charset charset) {
|
public MetricsReader(Charset charset) {
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,4 +104,14 @@ class ExtractedMetricSearcher {
|
||||||
}
|
}
|
||||||
return list;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue