Delete buffer directory when collector restart.
This commit is contained in:
彭勇升 pengys 2018-05-04 14:40:11 +08:00 committed by 吴晟 Wu Sheng
parent 5f3022889b
commit 89d79012da
5 changed files with 35 additions and 10 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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();
}
}
}

View File

@ -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() {
}
}

View File

@ -54,6 +54,7 @@ analysis_segment_parser:
bufferFilePath: ../buffer/
bufferOffsetMaxFileSize: 10M
bufferSegmentMaxFileSize: 500M
bufferFileCleanWhenRestart: true
ui:
jetty:
host: localhost