Skip to content

Commit

Permalink
Renamed to MetricsReader
Browse files Browse the repository at this point in the history
  • Loading branch information
talshalti authored and CarpenterLee committed Aug 29, 2018
1 parent ac8698e commit dc0a708
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -100,7 +99,7 @@ public synchronized List<MetricNode> 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;
Expand Down Expand Up @@ -135,7 +134,7 @@ public synchronized List<MetricNode> 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;
Expand Down Expand Up @@ -191,16 +190,6 @@ private boolean validPosition(long beginTimeMs) {
}
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -104,4 +104,14 @@ && readMetricsInOneFileByEndTime(list, fileNames.get(pos++), 0, endTimeMs, ident
}
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;
}
}

0 comments on commit dc0a708

Please sign in to comment.