Example #1
0
 /**
  * Notify all of the writers that they should check their memory usage.
  *
  * @throws IOException
  */
 void notifyWriters() throws IOException {
   LOG.debug("Notifying writers after " + rowsAddedSinceCheck);
   for (WriterInfo writer : writerList.values()) {
     boolean flushed = writer.callback.checkMemory(currentScale);
     if (LOG.isDebugEnabled() && flushed) {
       LOG.debug("flushed " + writer.toString());
     }
   }
   rowsAddedSinceCheck = 0;
 }
Example #2
0
 /**
  * Add a new writer's memory allocation to the pool. We use the path as a unique key to ensure
  * that we don't get duplicates.
  *
  * @param path the file that is being written
  * @param requestedAllocation the requested buffer size
  */
 synchronized void addWriter(Path path, long requestedAllocation, Callback callback)
     throws IOException {
   WriterInfo oldVal = writerList.get(path);
   // this should always be null, but we handle the case where the memory
   // manager wasn't told that a writer wasn't still in use and the task
   // starts writing to the same path.
   if (oldVal == null) {
     oldVal = new WriterInfo(requestedAllocation, callback);
     writerList.put(path, oldVal);
     totalAllocation += requestedAllocation;
   } else {
     // handle a new writer that is writing to the same path
     totalAllocation += requestedAllocation - oldVal.allocation;
     oldVal.allocation = requestedAllocation;
     oldVal.callback = callback;
   }
   updateScale(true);
 }