chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r1411818 - in /incubator/chukwa/trunk: ./ src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/ src/test/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/
Date Tue, 20 Nov 2012 19:46:36 GMT
Author: eyang
Date: Tue Nov 20 19:46:34 2012
New Revision: 1411818

URL: http://svn.apache.org/viewvc?rev=1411818&view=rev
Log:
CHUKWA-668. Fix infinite loop in FileTailingAdaptor. (Sourygna Luangsay via Eric Yang)

Modified:
    incubator/chukwa/trunk/CHANGES.txt
    incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/FileTailingAdaptor.java
    incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/LWFTAdaptor.java
    incubator/chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/TestFileTailingAdaptors.java

Modified: incubator/chukwa/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/CHANGES.txt?rev=1411818&r1=1411817&r2=1411818&view=diff
==============================================================================
--- incubator/chukwa/trunk/CHANGES.txt (original)
+++ incubator/chukwa/trunk/CHANGES.txt Tue Nov 20 19:46:34 2012
@@ -26,6 +26,8 @@ Trunk (unreleased changes)
 
   BUGS
 
+    CHUKWA-668. Fix infinite loop in FileTailingAdaptor. (Sourygna Luangsay via Eric Yang)
+
     CHUKWA-653. Added pre-compile JSP code profile for build process. (Jie Huang via Eric
Yang)
 
     CHUKWA-642. Added regular expression validation. (Eric Spishak via Eric Yang)

Modified: incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/FileTailingAdaptor.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/FileTailingAdaptor.java?rev=1411818&r1=1411817&r2=1411818&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/FileTailingAdaptor.java
(original)
+++ incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/FileTailingAdaptor.java
Tue Nov 20 19:46:34 2012
@@ -203,8 +203,8 @@ public class FileTailingAdaptor extends 
             log.debug("Adaptor|" + adaptorID 
                 + "| File size mismatched, rotating: " 
                 + toWatch.getAbsolutePath());
-          }
-          hasMoreData = slurp(len, reader);
+            hasMoreData = slurp(len, reader);
+          } 
         } else if (len < fileReadOffset) {
           // file has rotated and no detection
           if (reader != null) {

Modified: incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/LWFTAdaptor.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/LWFTAdaptor.java?rev=1411818&r1=1411817&r2=1411818&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/LWFTAdaptor.java
(original)
+++ incubator/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/LWFTAdaptor.java
Tue Nov 20 19:46:34 2012
@@ -166,6 +166,7 @@ public class LWFTAdaptor extends Abstrac
 
     long curOffset = fileReadOffset;
 
+    lastSlurpTime = System.currentTimeMillis();
     int bufferRead = reader.read(buf);
     assert reader.getFilePointer() == fileReadOffset + bufSize : " event size arithmetic
is broken: "
         + " pointer is "
@@ -214,7 +215,7 @@ public class LWFTAdaptor extends Abstrac
         handleShrunkenFile(len);
       } else if(len > fileReadOffset) {
         RandomAccessFile reader = new RandomAccessFile(toWatch, "r");
-        slurp(len, reader);
+        hasMoreData = slurp(len, reader);
         reader.close();
       }
     } catch(IOException e) {

Modified: incubator/chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/TestFileTailingAdaptors.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/TestFileTailingAdaptors.java?rev=1411818&r1=1411817&r2=1411818&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/TestFileTailingAdaptors.java
(original)
+++ incubator/chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/adaptor/filetailer/TestFileTailingAdaptors.java
Tue Nov 20 19:46:34 2012
@@ -122,5 +122,43 @@ public class TestFileTailingAdaptors ext
     chunks.clear();
     agent.shutdown();
   }
+  
+  /**
+   * Test that LWFTAdaptor updates lastSlurpTime so that FileTailingAdaptor
+   * does not trigger an infinite loop and that slurp() is not called by
+   * FileTailingAdaptor if file is not updated (see CHUKWA-668)
+   * @throws IOException
+   * @throws ChukwaAgent.AlreadyRunningException
+   * @throws InterruptedException
+   */
+  public void testSlurpTimeUpdated() throws IOException, ChukwaAgent.AlreadyRunningException,
+  InterruptedException{
+	  ChukwaAgent agent = new ChukwaAgent(conf);
+	  File testFile = makeTestFile("fooSlurp", 0,baseDir);
+	  long startTime = System.currentTimeMillis();
+	  String adaptorId = agent.processAddCommand("add adaptor_test =" +
+	  		"filetailer.FileTailingAdaptor slurp " +testFile.getCanonicalPath() + " 0");
+	  FileTailingAdaptor fta = (FileTailingAdaptor)agent.getAdaptor( adaptorId);
+	  Thread.sleep(500);
+	  long initializedSlurpTimeValue = fta.lastSlurpTime; 
+	  assertTrue( initializedSlurpTimeValue > startTime); // initialized to current time
+	  
+	  makeTestFile("fooSlurp", 2,baseDir);
+	  Chunk c = chunks.waitForAChunk();
 
+	  Thread.sleep(2000);
+	  // lastSlurpTime has been updated because a slurp was done
+	  long secondSlurpTimeValue = fta.lastSlurpTime;
+	  assertTrue( secondSlurpTimeValue > initializedSlurpTimeValue);
+	  assertEquals( fta.fileReadOffset, c.getData().length);
+	  assertEquals( fta.fileReadOffset, fta.reader.length());
+	  
+	  Thread.sleep(2000);
+	  // ensure we don't try to slurp if file is not updated
+	  assertEquals( fta.lastSlurpTime, secondSlurpTimeValue);
+	  
+	  if(agent.adaptorCount() > 0)
+	        agent.stopAdaptor("adaptor_test", false);
+	    agent.shutdown();
+  }
 }



Mime
View raw message