You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/05/04 06:40:13 UTC

[GitHub] wu-sheng closed pull request #1163: Delete buffer directory when collector restart.

wu-sheng closed pull request #1163: Delete buffer directory when collector restart.
URL: https://github.com/apache/incubator-skywalking/pull/1163
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentSpanListener.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentSpanListener.java
index 395bb58d6..dc095c5ac 100644
--- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentSpanListener.java
+++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentSpanListener.java
@@ -43,7 +43,7 @@ private ApplicationComponentSpanListener(ModuleManager moduleManager) {
     }
 
     @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
diff --git a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/AnalysisSegmentParserModuleConfig.java b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/AnalysisSegmentParserModuleConfig.java
index c8c7886d2..8c277177b 100644
--- a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/AnalysisSegmentParserModuleConfig.java
+++ b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/AnalysisSegmentParserModuleConfig.java
@@ -28,6 +28,7 @@
     private String bufferFilePath;
     private String bufferOffsetMaxFileSize;
     private String bufferSegmentMaxFileSize;
+    private boolean bufferFileCleanWhenRestart;
 
     public String getBufferFilePath() {
         return bufferFilePath;
@@ -52,4 +53,12 @@ public String getBufferSegmentMaxFileSize() {
     public void setBufferSegmentMaxFileSize(String bufferSegmentMaxFileSize) {
         this.bufferSegmentMaxFileSize = bufferSegmentMaxFileSize;
     }
+
+    public boolean isBufferFileCleanWhenRestart() {
+        return bufferFileCleanWhenRestart;
+    }
+
+    public void setBufferFileCleanWhenRestart(boolean bufferFileCleanWhenRestart) {
+        this.bufferFileCleanWhenRestart = bufferFileCleanWhenRestart;
+    }
 }
diff --git a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/BufferFileConfig.java b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/BufferFileConfig.java
index 8708e393e..f1f7ee613 100644
--- a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/BufferFileConfig.java
+++ b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/BufferFileConfig.java
@@ -28,6 +28,7 @@
     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 void parse(AnalysisSegmentParserModuleConfig config) {
             } else {
                 BUFFER_SEGMENT_MAX_FILE_SIZE = 1024 * 1024;
             }
+
+            BUFFER_FILE_CLEAN_WHEN_RESTART = config.isBufferFileCleanWhenRestart();
         }
     }
 }
diff --git a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/SegmentBufferManager.java b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/SegmentBufferManager.java
index d4e066724..d7add8e48 100644
--- a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/SegmentBufferManager.java
+++ b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/SegmentBufferManager.java
@@ -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 synchronized void initialize(ModuleManager moduleManager) {
             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 @@ private void newDataFile() throws IOException {
         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 @@ private void newDataFile() throws IOException {
         }
     }
 
+    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() {
     }
 }
diff --git a/apm-collector/apm-collector-boot/src/main/resources/application.yml b/apm-collector/apm-collector-boot/src/main/resources/application.yml
index b5fa4b849..33995cd97 100644
--- a/apm-collector/apm-collector-boot/src/main/resources/application.yml
+++ b/apm-collector/apm-collector-boot/src/main/resources/application.yml
@@ -54,6 +54,7 @@ analysis_segment_parser:
     bufferFilePath: ../buffer/
     bufferOffsetMaxFileSize: 10M
     bufferSegmentMaxFileSize: 500M
+    bufferFileCleanWhenRestart: true
 ui:
   jetty:
     host: localhost


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services