Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CHUKWA-668. Fix infinite loop in FileTailingAdaptor. (Sourygna Luangs…
…ay via Eric Yang)

git-svn-id: https://svn.apache.org/repos/asf/incubator/chukwa/trunk@1411818 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
macroadster committed Nov 20, 2012
1 parent 941c721 commit b58a0520f368438b9857b12db1fe435f2c06d2d7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
@@ -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)
@@ -203,8 +203,8 @@ public synchronized boolean tailFile()
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) {
@@ -166,6 +166,7 @@ protected boolean slurp(long len, RandomAccessFile reader) throws IOException,

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 synchronized boolean tailFile()
handleShrunkenFile(len);
} else if(len > fileReadOffset) {
RandomAccessFile reader = new RandomAccessFile(toWatch, "r");
slurp(len, reader);
hasMoreData = slurp(len, reader);
reader.close();
}
} catch(IOException e) {
@@ -122,5 +122,43 @@ public void testOffsetInAdaptorName() throws IOException, ChukwaAgent.AlreadyRun
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();
}
}

0 comments on commit b58a052

Please sign in to comment.