Beispiel #1
0
 @Override
 public void beginIterator(Iterator<?> iter) {
   synchronized (this) {
     if (activeIterators.contains(iter)) error(BeginIter, "Iterator already active: " + iter);
     activeIterators.add(iter);
   }
   blockMgr.beginIterator(iter);
 }
Beispiel #2
0
 @Override
 public synchronized void beginRead() {
   synchronized (this) {
     if (inUpdate) error(BeginRead, "beginRead when already in update");
     inRead++;
     inUpdate = false;
   }
   blockMgr.beginRead();
 }
Beispiel #3
0
 @Override
 public void beginUpdate() {
   synchronized (this) {
     if (inRead > 0) error(BeginUpdate, "beginUpdate when already in read");
     if (inUpdate) error(BeginUpdate, "beginUpdate when already in update");
     inUpdate = true;
   }
   blockMgr.beginUpdate();
 }
Beispiel #4
0
 @Override
 public void endIterator(Iterator<?> iter) {
   synchronized (this) {
     if (!activeIterators.contains(iter)) error(EndIter, "Iterator not active: " + iter);
     activeIterators.remove(iter);
     if (activeIterators.size() == 0)
       checkEmpty("Outstanding iterator read blocks", activeIterBlocks);
   }
   blockMgr.endIterator(iter);
 }
Beispiel #5
0
 @Override
 public Block getWrite(long id) {
   synchronized (this) {
     checkUpdate(GetWrite);
     Long x = id;
     add(GetWrite, x);
     activeWriteBlocks.add(x);
   }
   return blockMgr.getWrite(id);
 }
Beispiel #6
0
 @Override
 public Block getReadIterator(long id) {
   synchronized (this) {
     checkReadOrIter(IterRead);
     Long x = id;
     add(IterRead, x);
     activeIterBlocks.add(x);
   }
   return blockMgr.getReadIterator(id);
 }
Beispiel #7
0
 @Override
 public void free(Block block) {
   synchronized (this) {
     checkUpdate(Free);
     Long id = block.getId();
     add(Free, id);
     if (activeReadBlocks.contains(id)) error(Free, id + " is a read block");
     else if (!activeWriteBlocks.contains(id)) error(Free, id + " is not a write block");
     activeWriteBlocks.remove(id);
   }
   blockMgr.free(block);
 }
Beispiel #8
0
 @Override
 public Block allocate(int blockSize) {
   Block block;
   synchronized (this) {
     checkUpdate(Alloc);
     block = blockMgr.allocate(blockSize);
     Long id = block.getId();
     activeWriteBlocks.add(id);
     add(Alloc, id);
   }
   return block;
 }
Beispiel #9
0
  @Override
  public Block getRead(long id) {
    // What if this is a write block already?
    synchronized (this) {
      checkRead(GetRead);
      Long x = id;
      add(GetRead, x);

      if (activeWriteBlocks.contains(x)) activeWriteBlocks.add(x);
      else activeReadBlocks.add(x);
    }
    return blockMgr.getRead(id);
  }
Beispiel #10
0
  @Override
  public void endUpdate() {
    synchronized (this) {
      if (!inUpdate) error(EndUpdate, "endUpdate but not in update");
      if (inRead > 0) error(EndUpdate, "endUpdate when in read");

      checkEmpty("Outstanding read blocks at end of update operations", activeReadBlocks);

      checkEmpty("Outstanding write blocks at end of update operations", activeWriteBlocks);

      inUpdate = false;
      inRead = 0;
      clearInternalRW();
    }
    blockMgr.endUpdate();
  }
Beispiel #11
0
  @Override
  public void release(Block block) {
    synchronized (this) {
      checkReadOrIter(Release);
      Long id = block.getId();
      add(Release, id);

      if (!activeReadBlocks.contains(id)
          && !activeIterBlocks.contains(id)
          && !activeWriteBlocks.contains(id)) error(Release, id + " is not an active block");

      // May have been promoted.
      if (activeWriteBlocks.contains(id)) activeWriteBlocks.remove(id);
      else activeReadBlocks.remove(block.getId());

      activeIterBlocks.remove(block.getId());
    }
    blockMgr.release(block);
  }
Beispiel #12
0
  @Override
  public synchronized void endRead() {
    synchronized (this) {
      if (inRead == 0) error(EndRead, "endRead but not in read");
      if (inUpdate) error(EndRead, "endRead when in update");

      checkEmpty("Outstanding write blocks at end of read operations!", activeWriteBlocks);

      if (inRead == 0) {
        // Check at end of multiple reads or a write
        checkEmpty("Outstanding read blocks at end of read operations", activeReadBlocks);
        clearInternalRW();
      }

      inUpdate = false;
      inRead--;
    }
    blockMgr.endRead();
  }
Beispiel #13
0
  @Override
  public Block promote(Block block) {
    synchronized (this) {
      checkUpdate(Promote);
      Long id = block.getId();
      add(Promote, id);

      if (!activeWriteBlocks.contains(id) && !activeReadBlocks.contains(id))
        error(Promote, id + " is not an active block");

      if (activeReadBlocks.contains(id))
        // Remove one read count
        // Really, do this if obtained via "getRead" and not "getWrite"
        activeReadBlocks.remove(id);

      // Double promotion results in only one entry.
      if (!activeWriteBlocks.contains(id)) activeWriteBlocks.add(id);
    }
    return blockMgr.promote(block);
  }
Beispiel #14
0
 @Override
 public void syncForce() {
   blockMgr.syncForce();
 }
Beispiel #15
0
 @Override
 public synchronized void overwrite(Block block) {
   writeTracker(block);
   blockMgr.overwrite(block);
 }
Beispiel #16
0
 @Override
 public void write(Block block) {
   writeTracker(block);
   blockMgr.write(block);
 }
Beispiel #17
0
 @Override
 public boolean isClosed() {
   return blockMgr.isClosed();
 }
Beispiel #18
0
 @Override
 public boolean valid(int id) {
   return blockMgr.valid(id);
 }
Beispiel #19
0
 @Override
 public boolean isEmpty() {
   return blockMgr.isEmpty();
 }
Beispiel #20
0
 @Override
 public void sync() {
   blockMgr.sync();
 }
Beispiel #21
0
 public static BlockMgr track(BlockMgr blkMgr) {
   return track(blkMgr.getLabel(), blkMgr);
 }
Beispiel #22
0
 public BlockMgrTracker(Logger logger, String label, BlockMgr blockMgr) {
   this.blockMgr = blockMgr;
   this.log = logger;
   this.label = blockMgr.getLabel();
 }
Beispiel #23
0
 @Override
 public void close() {
   blockMgr.close();
 }