Exemplo n.º 1
0
 @After
 public void shutdownMemoryManager() throws Exception {
   if (this.memorySize > 0) {
     MemoryManager memMan = getMemoryManager();
     if (memMan != null) {
       Assert.assertTrue(
           "Memory Manager managed memory was not completely freed.", memMan.verifyEmpty());
       memMan.shutdown();
     }
   }
 }
  @Override
  public PactRecord peek() {
    if (readNext) {
      int bytesRead =
          currentReadRecord.deserialize(segments, CURRENT_READ_SEGMENT_INDEX, currentReadOffset);
      while (bytesRead > 0) {
        if (currentReadSegment.size() - currentReadOffset > bytesRead) {
          currentReadOffset += bytesRead;
          bytesRead = 0;
        } else {
          bytesRead -= (currentReadSegment.size() - currentReadOffset);

          // Remove old read segment from list & release in memory manager
          MemorySegment unused = segments.remove(CURRENT_READ_SEGMENT_INDEX);
          memoryManager.release(unused);

          // Update reference to new read segment
          currentReadSegment = segments.get(CURRENT_READ_SEGMENT_INDEX);
          currentReadOffset = 0;
        }
      }
      readNext = false;
    }

    return currentReadRecord;
  }
 @Override
 public int size() {
   if (count == 0) {
     // A memory segment can be left if it was not completely full
     if (segments.size() == 1) {
       currentWriteSegment = null;
       memoryManager.release(segments);
     } else if (segments.size() > 1) {
       throw new RuntimeException("Too many memory segments left");
     }
   }
   return count;
 }
 public SpillingResettableIterator(
     Iterator<T> input,
     TypeSerializer<T> serializer,
     MemoryManager memoryManager,
     IOManager ioManager,
     long availableMemory,
     AbstractInvokable parentTask)
     throws MemoryAllocationException {
   this(
       input,
       serializer,
       memoryManager,
       ioManager,
       memoryManager.allocatePages(parentTask, availableMemory),
       true);
 }
  private SpillingResettableIterator(
      Iterator<T> input,
      TypeSerializer<T> serializer,
      MemoryManager memoryManager,
      IOManager ioManager,
      List<MemorySegment> memory,
      boolean releaseMemOnClose) {
    this.memoryManager = memoryManager;
    this.input = input;
    this.instance = serializer.createInstance();
    this.serializer = serializer;
    this.memorySegments = memory;
    this.releaseMemoryOnClose = releaseMemOnClose;

    if (LOG.isDebugEnabled())
      LOG.debug(
          "Creating spilling resettable iterator with " + memory.size() + " pages of memory.");

    this.buffer =
        new SpillingBuffer(
            ioManager, new ListMemorySegmentSource(memory), memoryManager.getPageSize());
  }
Exemplo n.º 6
0
 /**
  * Unregisters the task from the central memory manager.
  *
  * @param memoryManager the central memory manager
  */
 public void unregisterMemoryManager(final MemoryManager memoryManager) {
   if (memoryManager != null) {
     memoryManager.releaseAll(this.environment.getInvokable());
   }
 }
 @Override
 public void clear() {
   memoryManager.release(segments);
   segments.clear();
   count = 0;
 }