return COMMIT_OK;
}
protected void rotate() {
Tracer t = Tracer.startNewTracer("honu.server." + group +".rotateDataSink");
isRunning = true;
calendar.setTimeInMillis(System.currentTimeMillis());
log.info(group +"- start Date [" + calendar.getTime() + "]");
log.info(group +"- Rotate from " + Thread.currentThread().getName());
String newName = day.format(calendar.getTime());
newName += localHostAddr + new java.rmi.server.UID().toString();
newName = newName.replace("-", "");
newName = newName.replace(":", "");
// newName = newName.replace(".", "");
newName = localOutputDir + "/" + newName.trim();
try {
FSDataOutputStream previousOutputStr = currentOutputStr;
Path previousPath = currentPath;
String previousFileName = currentFileName;
if (previousOutputStr != null) {
seqFileWriter.close();
previousOutputStr.close();
if (chunksWrittenThisRotate) {
fs.rename(previousPath, new Path(previousFileName + ".done"));
fileQueue.add(previousFileName + ".done");
} else {
log.info(group+"- no chunks written to " + previousPath + ", deleting");
fs.delete(previousPath, false);
}
}
Path newOutputPath = new Path(newName + ".chukwa");
FSDataOutputStream newOutputStr = fs.create(newOutputPath);
currentOutputStr = newOutputStr;
currentPath = newOutputPath;
currentFileName = newName;
chunksWrittenThisRotate = false;
if (codec != null) {
seqFileWriter = SequenceFile.createWriter(conf, newOutputStr,
ChukwaArchiveKey.class, ChunkImpl.class,
SequenceFile.CompressionType.BLOCK, codec);
} else {
seqFileWriter = SequenceFile.createWriter(conf, newOutputStr,
ChukwaArchiveKey.class, ChunkImpl.class,
SequenceFile.CompressionType.NONE, codec);
}
} catch (Throwable e) {
if (t!= null) {
t.stopAndLogTracer();
}
log.fatal(group+"- Throwable Exception in rotate. Exiting!", e);
// Shutting down the collector
// Watchdog will re-start it automatically
DaemonWatcher.bailout(-1);
}
// Check for disk space
File directory4Space = new File(localOutputDir);
long totalSpace = directory4Space.getTotalSpace();
long freeSpace = directory4Space.getFreeSpace();
long minFreeAvailable = (totalSpace * minPercentFreeDisk) /100;
if (log.isDebugEnabled()) {
log.debug( group +"- Directory: " + localOutputDir + ", totalSpace: " + totalSpace
+ ", freeSpace: " + freeSpace + ", minFreeAvailable: " + minFreeAvailable
+ ", percentFreeDisk: " + minPercentFreeDisk);
}
if (freeSpace < minFreeAvailable) {
log.fatal( group +"- No space left on device, Bail out!");
DaemonWatcher.bailout(-1);
}
nextRotate = System.currentTimeMillis() + rotateInterval;
if (t!= null) {
t.stopAndLogTracer();
}
}