Beispiel #1
0
  /**
   * Locate all writers past idle timeout and retire them
   *
   * @return number of writers retired
   */
  private int retireIdleWriters() {
    int count = 0;
    long now = System.currentTimeMillis();
    ArrayList<HiveEndPoint> retirees = new ArrayList<HiveEndPoint>();

    // 1) Find retirement candidates
    for (Entry<HiveEndPoint, HiveWriter> entry : allWriters.entrySet()) {
      if (now - entry.getValue().getLastUsed() > options.getIdleTimeout()) {
        ++count;
        retirees.add(entry.getKey());
      }
    }
    // 2) Retire them
    for (HiveEndPoint ep : retirees) {
      try {
        LOG.info("Closing idle Writer to Hive end point : {}", ep);
        allWriters.remove(ep).close();
      } catch (IOException e) {
        LOG.warn("Failed to close writer for end point: {}. Error: " + ep, e);
      } catch (InterruptedException e) {
        LOG.warn("Interrupted when attempting to close writer for end point: " + ep, e);
        Thread.currentThread().interrupt();
      }
    }
    return count;
  }
Beispiel #2
0
  @Override
  public void cleanup() {
    for (Entry<HiveEndPoint, HiveWriter> entry : allWriters.entrySet()) {
      try {
        HiveWriter w = entry.getValue();
        LOG.info("Flushing writer to {}", w);
        w.flush(false);
        LOG.info("Closing writer to {}", w);
        w.close();
      } catch (Exception ex) {
        LOG.warn("Error while closing writer to " + entry.getKey() + ". Exception follows.", ex);
        if (ex instanceof InterruptedException) {
          Thread.currentThread().interrupt();
        }
      }
    }

    ExecutorService toShutdown[] = {callTimeoutPool};
    for (ExecutorService execService : toShutdown) {
      execService.shutdown();
      try {
        while (!execService.isTerminated()) {
          execService.awaitTermination(options.getCallTimeOut(), TimeUnit.MILLISECONDS);
        }
      } catch (InterruptedException ex) {
        LOG.warn("shutdown interrupted on " + execService, ex);
      }
    }
    callTimeoutPool = null;
    super.cleanup();
    LOG.info("Hive Bolt stopped");
  }
Beispiel #3
0
 /** Locate writer that has not been used for longest time and retire it */
 private void retireEldestWriter() {
   long oldestTimeStamp = System.currentTimeMillis();
   HiveEndPoint eldest = null;
   for (Entry<HiveEndPoint, HiveWriter> entry : allWriters.entrySet()) {
     if (entry.getValue().getLastUsed() < oldestTimeStamp) {
       eldest = entry.getKey();
       oldestTimeStamp = entry.getValue().getLastUsed();
     }
   }
   try {
     LOG.info("Closing least used Writer to Hive end point : " + eldest);
     allWriters.remove(eldest).close();
   } catch (IOException e) {
     LOG.warn("Failed to close writer for end point: " + eldest, e);
   } catch (InterruptedException e) {
     LOG.warn("Interrupted when attempting to close writer for end point: " + eldest, e);
     Thread.currentThread().interrupt();
   }
 }