Program: 167235
Project: 167235
Buggy source:
/** 
 * Pull events out of channel and send it to HDFS. Take at most batchSize events per Transaction. Find the corresponding bucket for the event. Ensure the file is open. Serialize the data and write it to the file on HDFS. <br/> This method is not thread safe.
 */
public Status process() throws EventDeliveryException {
  if (!this.switchon) {
    LOG.warn("String_Node_Str");
    try {
      Thread.sleep(500);
    }
 catch (    InterruptedException e) {
    }
    return Status.READY;
  }
  long t1=System.currentTimeMillis();
  long t2=System.currentTimeMillis();
  Channel channel=getChannel();
  Transaction transaction=channel.getTransaction();
  List<BucketWriter> writers=Lists.newArrayList();
  Map<String,HDFSEventSinkMetric> metricMap=new HashMap<String,HDFSEventSinkMetric>();
  Map<String,String> bucketWriter2Category=new HashMap<String,String>();
  transaction.begin();
  long tStart=0;
  long tEnd=0;
  try {
    int txnEventCount=0;
    for (txnEventCount=0; txnEventCount < batchSize; txnEventCount++) {
      tStart=System.currentTimeMillis();
      Event event=channel.take();
      if (event == null) {
        break;
      }
      tEnd=System.currentTimeMillis();
      statTakeTime+=tEnd - tStart;
      String category=event.getHeaders().get("String_Node_Str");
      HDFSEventSinkMetric crtMetric=metricMap.get(category);
      if (crtMetric == null) {
        crtMetric=new HDFSEventSinkMetric(category);
        metricMap.put(category,crtMetric);
      }
      crtMetric.incTake(tEnd - tStart);
      crtMetric.incEventNum(1);
      String realPath=BucketPath.escapeString(filePath,event.getHeaders(),timeZone,needRounding,roundUnit,roundValue,useLocalTime);
      String realName=BucketPath.escapeString(fileName,event.getHeaders(),timeZone,needRounding,roundUnit,roundValue,useLocalTime);
      String lookupPath=realPath + DIRECTORY_DELIMITER + realName;
      BucketWriter bucketWriter=sfWriters.get(lookupPath);
      if (bucketWriter == null) {
        HDFSWriter hdfsWriter=writerFactory.getWriter(fileType);
        WriterCallback idleCallback=null;
        if (idleTimeout != 0) {
          idleCallback=new WriterCallback(){
            @Override public void run(            String bucketPath){
              sfWriters.remove(bucketPath);
            }
          }
;
        }
        bucketWriter=new BucketWriter(rollInterval,rollSize,rollCount,batchSize,context,realPath,realName,inUsePrefix,inUseSuffix,suffix,codeC,compType,hdfsWriter,timedRollerPool,proxyTicket,sinkCounter,idleTimeout,idleCallback,lookupPath,callTimeout,callTimeoutPool);
        sfWriters.put(lookupPath,bucketWriter);
        bucketWriter2Category.put(bucketWriter.toString(),category);
      }
      if (!writers.contains(bucketWriter)) {
        writers.add(bucketWriter);
      }
      tStart=System.currentTimeMillis();
      bucketWriter.append(event);
      tEnd=System.currentTimeMillis();
      statAppendTime+=tEnd - tStart;
      crtMetric.incAppend(tEnd - tStart);
    }
    if (txnEventCount == 0) {
      sinkCounter.incrementBatchEmptyCount();
    }
 else     if (txnEventCount == batchSize) {
      sinkCounter.incrementBatchCompleteCount();
    }
 else {
      sinkCounter.incrementBatchUnderflowCount();
    }
    statEventCount+=txnEventCount;
    tStart=System.currentTimeMillis();
    for (    BucketWriter bucketWriter : writers) {
      long begin=System.currentTimeMillis();
      bucketWriter.flush();
      long end=System.currentTimeMillis();
      String category=bucketWriter2Category.get(bucketWriter.toString());
      HDFSEventSinkMetric crtMetric=metricMap.get(category);
      if (crtMetric != null) {
        crtMetric.incSync(end - begin);
      }
 else {
        LOG.error("String_Node_Str" + bucketWriter.toString());
      }
    }
    tEnd=System.currentTimeMillis();
    statSyncTime+=tEnd - tStart;
    transaction.commit();
    t2=System.currentTimeMillis();
    statAllTime+=t2 - t1;
    if (statEventCount >= STAT_EVENT_COUNT_THRESHOLD) {
      LOG.info("String_Node_Str" + writers.size() + "String_Node_Str"+ statEventCount+ "String_Node_Str"+ statAllTime+ "String_Node_Str"+ "String_Node_Str"+ statTakeTime+ "String_Node_Str"+ statAppendTime+ "String_Node_Str"+ statSyncTime+ "String_Node_Str");
      statEventCount=0;
      statAllTime=0;
      statTakeTime=0;
      statAppendTime=0;
      statSyncTime=0;
      for (      Map.Entry<String,HDFSEventSinkMetric> crtEntry : metricMap.entrySet()) {
        HDFSEventSinkMetric crtMetric=crtEntry.getValue();
        crtMetric.sum();
        LOG.info("String_Node_Str" + crtMetric.toString());
      }
    }
    if (txnEventCount < 1) {
      return Status.BACKOFF;
    }
 else {
      sinkCounter.addToEventDrainSuccessCount(txnEventCount);
      return Status.READY;
    }
  }
 catch (  IOException eIO) {
    transaction.rollback();
    LOG.warn("String_Node_Str",eIO);
    return Status.BACKOFF;
  }
catch (  Throwable th) {
    transaction.rollback();
    LOG.error("String_Node_Str",th);
    if (th instanceof Error) {
      throw (Error)th;
    }
 else {
      throw new EventDeliveryException(th);
    }
  }
 finally {
    transaction.close();
  }
}

Fixed version (ground truth):
/** 
 * Pull events out of channel and send it to HDFS. Take at most batchSize events per Transaction. Find the corresponding bucket for the event. Ensure the file is open. Serialize the data and write it to the file on HDFS. <br/> This method is not thread safe.
 */
public Status process() throws EventDeliveryException {
  if (!this.switchon) {
    LOG.warn("String_Node_Str");
    try {
      Thread.sleep(500);
    }
 catch (    InterruptedException e) {
    }
    return Status.READY;
  }
  long t1=System.currentTimeMillis();
  long t2=System.currentTimeMillis();
  long tStart=t1;
  long tEnd=t1;
  Channel channel=getChannel();
  Transaction transaction=channel.getTransaction();
  List<BucketWriter> writers=Lists.newArrayList();
  Map<String,HDFSEventSinkMetric> metricMap=new HashMap<String,HDFSEventSinkMetric>();
  Map<BucketWriter,String> bucketWriter2Category=new HashMap<BucketWriter,String>();
  transaction.begin();
  long getFilenameTime=0;
  try {
    int txnEventCount=0;
    for (txnEventCount=0; txnEventCount < batchSize; txnEventCount++) {
      tStart=System.currentTimeMillis();
      Event event=channel.take();
      tEnd=System.currentTimeMillis();
      statTakeTime+=tEnd - tStart;
      if (event == null) {
        break;
      }
      String category=event.getHeaders().get("String_Node_Str");
      HDFSEventSinkMetric crtMetric=metricMap.get(category);
      if (crtMetric == null) {
        crtMetric=new HDFSEventSinkMetric(category);
        metricMap.put(category,crtMetric);
      }
      crtMetric.incTake(tEnd - tStart);
      crtMetric.incEventNum(1);
      tStart=System.currentTimeMillis();
      String realPath=BucketPath.escapeString(filePath,event.getHeaders(),timeZone,needRounding,roundUnit,roundValue,useLocalTime);
      String realName=BucketPath.escapeString(fileName,event.getHeaders(),timeZone,needRounding,roundUnit,roundValue,useLocalTime);
      getFilenameTime+=System.currentTimeMillis() - tStart;
      String lookupPath=realPath + DIRECTORY_DELIMITER + realName;
      BucketWriter bucketWriter=sfWriters.get(lookupPath);
      if (bucketWriter == null) {
        HDFSWriter hdfsWriter=writerFactory.getWriter(fileType);
        WriterCallback idleCallback=null;
        if (idleTimeout != 0) {
          idleCallback=new WriterCallback(){
            @Override public void run(            String bucketPath){
              sfWriters.remove(bucketPath);
            }
          }
;
        }
        bucketWriter=new BucketWriter(rollInterval,rollSize,rollCount,batchSize,context,realPath,realName,inUsePrefix,inUseSuffix,suffix,codeC,compType,hdfsWriter,timedRollerPool,proxyTicket,sinkCounter,idleTimeout,idleCallback,lookupPath,callTimeout,callTimeoutPool);
        sfWriters.put(lookupPath,bucketWriter);
      }
      if (!writers.contains(bucketWriter)) {
        writers.add(bucketWriter);
        bucketWriter2Category.put(bucketWriter,category);
      }
      tStart=System.currentTimeMillis();
      bucketWriter.append(event);
      tEnd=System.currentTimeMillis();
      statAppendTime+=tEnd - tStart;
      crtMetric.incAppend(tEnd - tStart);
    }
    if (txnEventCount == 0) {
      sinkCounter.incrementBatchEmptyCount();
    }
 else     if (txnEventCount == batchSize) {
      sinkCounter.incrementBatchCompleteCount();
    }
 else {
      sinkCounter.incrementBatchUnderflowCount();
    }
    statEventCount+=txnEventCount;
    tStart=System.currentTimeMillis();
    for (    BucketWriter bucketWriter : writers) {
      long begin=System.currentTimeMillis();
      bucketWriter.flush();
      long end=System.currentTimeMillis();
      String category=bucketWriter2Category.get(bucketWriter);
      HDFSEventSinkMetric crtMetric=metricMap.get(category);
      if (crtMetric != null) {
        crtMetric.incSync(end - begin);
      }
 else {
        LOG.error("String_Node_Str" + bucketWriter.toString());
      }
    }
    tEnd=System.currentTimeMillis();
    statSyncTime+=tEnd - tStart;
    transaction.commit();
    t2=System.currentTimeMillis();
    statAllTime+=t2 - t1;
    LOG.info("String_Node_Str" + this.getName() + "String_Node_Str"+ writers.size()+ "String_Node_Str"+ statEventCount+ "String_Node_Str"+ statAllTime+ "String_Node_Str"+ "String_Node_Str"+ statTakeTime+ "String_Node_Str"+ statAppendTime+ "String_Node_Str"+ statSyncTime+ "String_Node_Str"+ getFilenameTime+ "String_Node_Str");
    statEventCount=0;
    statAllTime=0;
    statTakeTime=0;
    statAppendTime=0;
    statSyncTime=0;
    for (    Map.Entry<String,HDFSEventSinkMetric> crtEntry : metricMap.entrySet()) {
      HDFSEventSinkMetric crtMetric=crtEntry.getValue();
      crtMetric.sum();
      LOG.info("String_Node_Str" + this.getName() + "String_Node_Str"+ crtMetric.toString());
    }
    if (txnEventCount < 1) {
      return Status.BACKOFF;
    }
 else {
      sinkCounter.addToEventDrainSuccessCount(txnEventCount);
      return Status.READY;
    }
  }
 catch (  IOException eIO) {
    transaction.rollback();
    LOG.warn("String_Node_Str",eIO);
    return Status.BACKOFF;
  }
catch (  Throwable th) {
    transaction.rollback();
    LOG.error("String_Node_Str",th);
    if (th instanceof Error) {
      throw (Error)th;
    }
 else {
      throw new EventDeliveryException(th);
    }
  }
 finally {
    transaction.close();
  }
}