提交 89d79012 编写于 作者: 彭勇升 pengys 提交者: wu-sheng

#1162 (#1163)

Delete buffer directory when collector restart.
上级 5f302288
......@@ -43,7 +43,7 @@ public class ApplicationComponentSpanListener implements EntrySpanListener, Exit
}
@Override public boolean containsPoint(Point point) {
return Point.Entry.equals(point) || Point.Exit.equals(point) || Point.First.equals(point);
return Point.Entry.equals(point) || Point.Exit.equals(point);
}
@Override
......
......@@ -28,6 +28,7 @@ public class AnalysisSegmentParserModuleConfig extends ModuleConfig {
private String bufferFilePath;
private String bufferOffsetMaxFileSize;
private String bufferSegmentMaxFileSize;
private boolean bufferFileCleanWhenRestart;
public String getBufferFilePath() {
return bufferFilePath;
......@@ -52,4 +53,12 @@ public class AnalysisSegmentParserModuleConfig extends ModuleConfig {
public void setBufferSegmentMaxFileSize(String bufferSegmentMaxFileSize) {
this.bufferSegmentMaxFileSize = bufferSegmentMaxFileSize;
}
public boolean isBufferFileCleanWhenRestart() {
return bufferFileCleanWhenRestart;
}
public void setBufferFileCleanWhenRestart(boolean bufferFileCleanWhenRestart) {
this.bufferFileCleanWhenRestart = bufferFileCleanWhenRestart;
}
}
......@@ -28,6 +28,7 @@ public class BufferFileConfig {
static int BUFFER_OFFSET_MAX_FILE_SIZE = 10 * 1024 * 1024;
static int BUFFER_SEGMENT_MAX_FILE_SIZE = 10 * 1024 * 1024;
static String BUFFER_PATH = "../buffer/";
static boolean BUFFER_FILE_CLEAN_WHEN_RESTART = false;
public static class Parser {
......@@ -77,6 +78,8 @@ public class BufferFileConfig {
} else {
BUFFER_SEGMENT_MAX_FILE_SIZE = 1024 * 1024;
}
BUFFER_FILE_CLEAN_WHEN_RESTART = config.isBufferFileCleanWhenRestart();
}
}
}
......@@ -18,16 +18,11 @@
package org.apache.skywalking.apm.collector.analysis.segment.parser.provider.buffer;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.apache.skywalking.apm.collector.core.util.*;
import org.apache.skywalking.apm.network.proto.UpstreamSegment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.*;
/**
* @author peng-yongsheng
......@@ -46,6 +41,9 @@ public enum SegmentBufferManager {
OffsetManager.INSTANCE.initialize();
if (new File(BufferFileConfig.BUFFER_PATH).mkdirs()) {
newDataFile();
} else if (BufferFileConfig.BUFFER_FILE_CLEAN_WHEN_RESTART) {
deleteFiles();
newDataFile();
} else {
String writeFileName = OffsetManager.INSTANCE.getWriteFileName();
if (StringUtils.isNotEmpty(writeFileName)) {
......@@ -84,7 +82,11 @@ public enum SegmentBufferManager {
String timeBucket = String.valueOf(TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis()));
String writeFileName = DATA_FILE_PREFIX + "_" + timeBucket + "." + Const.FILE_SUFFIX;
File dataFile = new File(BufferFileConfig.BUFFER_PATH + writeFileName);
dataFile.createNewFile();
boolean created = dataFile.createNewFile();
if (!created) {
logger.info("The file named {} already exists.", writeFileName);
}
OffsetManager.INSTANCE.setWriteOffset(writeFileName, 0);
try {
if (outputStream != null) {
......@@ -97,6 +99,16 @@ public enum SegmentBufferManager {
}
}
private void deleteFiles() {
File bufferDirectory = new File(BufferFileConfig.BUFFER_PATH);
boolean delete = bufferDirectory.delete();
if (delete) {
logger.info("Buffer directory is successfully deleted");
} else {
logger.info("Buffer directory is not deleted");
}
}
public synchronized void flush() {
}
}
......@@ -54,6 +54,7 @@ analysis_segment_parser:
bufferFilePath: ../buffer/
bufferOffsetMaxFileSize: 10M
bufferSegmentMaxFileSize: 500M
bufferFileCleanWhenRestart: true
ui:
jetty:
host: localhost
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册