flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject git commit: FLUME-1683: Fix Time Granularity Bug in SpoolingFileLineReader
Date Tue, 06 Nov 2012 17:21:30 GMT
Updated Branches:
  refs/heads/flume.1.4 2bc828e87 -> d7dc14295


FLUME-1683: Fix Time Granularity Bug in SpoolingFileLineReader

(Patrick Wendell via Brock Noland)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/d7dc1429
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/d7dc1429
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/d7dc1429

Branch: refs/heads/flume.1.4
Commit: d7dc14295f08c33444c8996d348bc059f607414b
Parents: 2bc828e
Author: Brock Noland <brock@apache.org>
Authored: Tue Nov 6 11:20:59 2012 -0600
Committer: Brock Noland <brock@apache.org>
Committed: Tue Nov 6 11:21:11 2012 -0600

----------------------------------------------------------------------
 .../flume/client/avro/SpoolingFileLineReader.java  |   13 ++++++++++---
 .../client/avro/TestSpoolingFileLineReader.java    |    2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/d7dc1429/flume-ng-core/src/main/java/org/apache/flume/client/avro/SpoolingFileLineReader.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/main/java/org/apache/flume/client/avro/SpoolingFileLineReader.java
b/flume-ng-core/src/main/java/org/apache/flume/client/avro/SpoolingFileLineReader.java
index abd2f61..b37b730 100644
--- a/flume-ng-core/src/main/java/org/apache/flume/client/avro/SpoolingFileLineReader.java
+++ b/flume-ng-core/src/main/java/org/apache/flume/client/avro/SpoolingFileLineReader.java
@@ -285,8 +285,9 @@ public class SpoolingFileLineReader implements LineReader {
   }
 
   /**
-   * Find and open the oldest file in the chosen directory. If the directory is
-   * empty, this will return an absent option.
+   * Find and open the oldest file in the chosen directory. If two or more
+   * files are equally old, the file name with lower lexicographical value is
+   * returned. If the directory is empty, this will return an absent option.
    */
   private Optional<FileInfo> getNextFile() {
     /* Filter to exclude finished or hidden files */
@@ -305,8 +306,14 @@ public class SpoolingFileLineReader implements LineReader {
     } else {
       Collections.sort(candidateFiles, new Comparator<File>() {
         public int compare(File a, File b) {
-          return new Long(a.lastModified()).compareTo(
+          int timeComparison = new Long(a.lastModified()).compareTo(
               new Long(b.lastModified()));
+          if (timeComparison != 0) {
+            return timeComparison;
+          }
+          else {
+            return a.getName().compareTo(b.getName());
+          }
         }
       });
       File nextFile = candidateFiles.get(0);

http://git-wip-us.apache.org/repos/asf/flume/blob/d7dc1429/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestSpoolingFileLineReader.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestSpoolingFileLineReader.java
b/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestSpoolingFileLineReader.java
index 9f84d9f..8463176 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestSpoolingFileLineReader.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestSpoolingFileLineReader.java
@@ -399,7 +399,7 @@ public class TestSpoolingFileLineReader {
     List<File> outFiles = Lists.newArrayList(tmpDir.listFiles());
     assertEquals(2, outFiles.size());
     assertTrue(outFiles.contains(
-        new File(tmpDir + "/file1")));
+        new File(tmpDir + "/file1" + completedSuffix)));
     assertTrue(outFiles.contains(
         new File(tmpDir + "/file2" + completedSuffix)));
   }


Mime
View raw message