@Test public void requestSpace() throws Exception { TieredBlockStoreTestUtils.createTempBlock(SESSION_ID1, TEMP_BLOCK_ID, 1, mTestDir1); mBlockStore.requestSpace(SESSION_ID1, TEMP_BLOCK_ID, BLOCK_SIZE - 1); assertTrue(mTestDir1.hasTempBlockMeta(TEMP_BLOCK_ID)); assertEquals(BLOCK_SIZE, mTestDir1.getTempBlockMeta(TEMP_BLOCK_ID).getBlockSize()); assertEquals(mTestDir1.getCapacityBytes() - BLOCK_SIZE, mTestDir1.getAvailableBytes()); }
@Override public void requestSpace(long sessionId, long blockId, long additionalBytes) throws BlockDoesNotExistException, WorkerOutOfSpaceException, IOException { LOG.debug("requestSpace: sessionId={}, blockId={}, additionalBytes={}", sessionId, blockId, additionalBytes); try (LockResource r = new LockResource(mMetadataWriteLock)) { TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId); StorageDirView allocationDir = allocateSpace(sessionId, AllocateOptions.forRequestSpace(additionalBytes, tempBlockMeta.getBlockLocation())); if (allocationDir == null) { throw new WorkerOutOfSpaceException(String.format( "Can't reserve more space for block: %d under session: %d.", blockId, sessionId)); } if (!allocationDir.toBlockStoreLocation().equals(tempBlockMeta.getBlockLocation())) { throw new IllegalStateException( String.format("Allocation error: location enforcement failed for location: %s", allocationDir.toBlockStoreLocation())); } try { mMetaManager.resizeTempBlockMeta( tempBlockMeta, tempBlockMeta.getBlockSize() + additionalBytes); } catch (InvalidWorkerStateException e) { throw Throwables.propagate(e); } } }
TieredBlockStore implements BlockStore { @Override public void requestSpace(long sessionId, long blockId, long additionalBytes) throws BlockDoesNotExistException, WorkerOutOfSpaceException, IOException { LOG.debug("requestSpace: sessionId={}, blockId={}, additionalBytes={}", sessionId, blockId, additionalBytes); try (LockResource r = new LockResource(mMetadataWriteLock)) { TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId); StorageDirView allocationDir = allocateSpace(sessionId, AllocateOptions.forRequestSpace(additionalBytes, tempBlockMeta.getBlockLocation())); if (allocationDir == null) { throw new WorkerOutOfSpaceException(String.format( "Can't reserve more space for block: %d under session: %d.", blockId, sessionId)); } if (!allocationDir.toBlockStoreLocation().equals(tempBlockMeta.getBlockLocation())) { throw new IllegalStateException( String.format("Allocation error: location enforcement failed for location: %s", allocationDir.toBlockStoreLocation())); } try { mMetaManager.resizeTempBlockMeta( tempBlockMeta, tempBlockMeta.getBlockSize() + additionalBytes); } catch (InvalidWorkerStateException e) { throw Throwables.propagate(e); } } } }
TieredBlockStore implements BlockStore { @Override public void requestSpace(long sessionId, long blockId, long additionalBytes) throws BlockDoesNotExistException, WorkerOutOfSpaceException, IOException { LOG.debug("requestSpace: sessionId={}, blockId={}, additionalBytes={}", sessionId, blockId, additionalBytes); try (LockResource r = new LockResource(mMetadataWriteLock)) { TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId); StorageDirView allocationDir = allocateSpace(sessionId, AllocateOptions.forRequestSpace(additionalBytes, tempBlockMeta.getBlockLocation())); if (allocationDir == null) { throw new WorkerOutOfSpaceException(String.format( "Can't reserve more space for block: %d under session: %d.", blockId, sessionId)); } if (!allocationDir.toBlockStoreLocation().equals(tempBlockMeta.getBlockLocation())) { throw new IllegalStateException( String.format("Allocation error: location enforcement failed for location: %s", allocationDir.toBlockStoreLocation())); } try { mMetaManager.resizeTempBlockMeta( tempBlockMeta, tempBlockMeta.getBlockSize() + additionalBytes); } catch (InvalidWorkerStateException e) { throw Throwables.propagate(e); } } } TieredBlockStore(); }
TieredBlockStore implements BlockStore { @Override public void requestSpace(long sessionId, long blockId, long additionalBytes) throws BlockDoesNotExistException, WorkerOutOfSpaceException, IOException { LOG.debug("requestSpace: sessionId={}, blockId={}, additionalBytes={}", sessionId, blockId, additionalBytes); try (LockResource r = new LockResource(mMetadataWriteLock)) { TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId); StorageDirView allocationDir = allocateSpace(sessionId, AllocateOptions.forRequestSpace(additionalBytes, tempBlockMeta.getBlockLocation())); if (allocationDir == null) { throw new WorkerOutOfSpaceException(String.format( "Can't reserve more space for block: %d under session: %d.", blockId, sessionId)); } if (!allocationDir.toBlockStoreLocation().equals(tempBlockMeta.getBlockLocation())) { throw new IllegalStateException( String.format("Allocation error: location enforcement failed for location: %s", allocationDir.toBlockStoreLocation())); } try { mMetaManager.resizeTempBlockMeta( tempBlockMeta, tempBlockMeta.getBlockSize() + additionalBytes); } catch (InvalidWorkerStateException e) { throw Throwables.propagate(e); } } } TieredBlockStore(); @Override long lockBlock(long sessionId, long blockId); @Override long lockBlockNoException(long sessionId, long blockId); @Override void unlockBlock(long lockId); @Override boolean unlockBlock(long sessionId, long blockId); @Override BlockWriter getBlockWriter(long sessionId, long blockId); @Override BlockReader getBlockReader(long sessionId, long blockId, long lockId); @Override TempBlockMeta createBlock(long sessionId, long blockId, AllocateOptions options); @Override BlockMeta getVolatileBlockMeta(long blockId); @Override BlockMeta getBlockMeta(long sessionId, long blockId, long lockId); @Override TempBlockMeta getTempBlockMeta(long sessionId, long blockId); @Override void commitBlock(long sessionId, long blockId, boolean pinOnCreate); @Override long commitBlockLocked(long sessionId, long blockId, boolean pinOnCreate); @Override void abortBlock(long sessionId, long blockId); @Override void requestSpace(long sessionId, long blockId, long additionalBytes); @Override void moveBlock(long sessionId, long blockId, AllocateOptions moveOptions); @Override void moveBlock(long sessionId, long blockId, BlockStoreLocation oldLocation,
      AllocateOptions moveOptions); @Override void removeBlock(long sessionId, long blockId); @Override void removeBlock(long sessionId, long blockId, BlockStoreLocation location); @Override void accessBlock(long sessionId, long blockId); @Override synchronized void freeSpace(long sessionId, long minContiguousBytes,
      long minAvailableBytes, BlockStoreLocation location); @Override void cleanupSession(long sessionId); @Override boolean hasBlockMeta(long blockId); @Override BlockStoreMeta getBlockStoreMeta(); @Override BlockStoreMeta getBlockStoreMetaFull(); @Override void registerBlockStoreEventListener(BlockStoreEventListener listener); @Override void updatePinnedInodes(Set<Long> inodes); @Override boolean checkStorage(); void removeDir(StorageDir dir); @Override void close(); }
TieredBlockStore implements BlockStore { @Override public void requestSpace(long sessionId, long blockId, long additionalBytes) throws BlockDoesNotExistException, WorkerOutOfSpaceException, IOException { LOG.debug("requestSpace: sessionId={}, blockId={}, additionalBytes={}", sessionId, blockId, additionalBytes); try (LockResource r = new LockResource(mMetadataWriteLock)) { TempBlockMeta tempBlockMeta = mMetaManager.getTempBlockMeta(blockId); StorageDirView allocationDir = allocateSpace(sessionId, AllocateOptions.forRequestSpace(additionalBytes, tempBlockMeta.getBlockLocation())); if (allocationDir == null) { throw new WorkerOutOfSpaceException(String.format( "Can't reserve more space for block: %d under session: %d.", blockId, sessionId)); } if (!allocationDir.toBlockStoreLocation().equals(tempBlockMeta.getBlockLocation())) { throw new IllegalStateException( String.format("Allocation error: location enforcement failed for location: %s", allocationDir.toBlockStoreLocation())); } try { mMetaManager.resizeTempBlockMeta( tempBlockMeta, tempBlockMeta.getBlockSize() + additionalBytes); } catch (InvalidWorkerStateException e) { throw Throwables.propagate(e); } } } TieredBlockStore(); @Override long lockBlock(long sessionId, long blockId); @Override long lockBlockNoException(long sessionId, long blockId); @Override void unlockBlock(long lockId); @Override boolean unlockBlock(long sessionId, long blockId); @Override BlockWriter getBlockWriter(long sessionId, long blockId); @Override BlockReader getBlockReader(long sessionId, long blockId, long lockId); @Override TempBlockMeta createBlock(long sessionId, long blockId, AllocateOptions options); @Override BlockMeta getVolatileBlockMeta(long blockId); @Override BlockMeta getBlockMeta(long sessionId, long blockId, long lockId); @Override TempBlockMeta getTempBlockMeta(long sessionId, long blockId); @Override void commitBlock(long sessionId, long blockId, boolean pinOnCreate); @Override long commitBlockLocked(long sessionId, long blockId, boolean pinOnCreate); @Override void abortBlock(long sessionId, long blockId); @Override void requestSpace(long sessionId, long blockId, long additionalBytes); @Override void moveBlock(long sessionId, long blockId, AllocateOptions moveOptions); @Override void moveBlock(long sessionId, long blockId, BlockStoreLocation oldLocation,
      AllocateOptions moveOptions); @Override void removeBlock(long sessionId, long blockId); @Override void removeBlock(long sessionId, long blockId, BlockStoreLocation location); @Override void accessBlock(long sessionId, long blockId); @Override synchronized void freeSpace(long sessionId, long minContiguousBytes,
      long minAvailableBytes, BlockStoreLocation location); @Override void cleanupSession(long sessionId); @Override boolean hasBlockMeta(long blockId); @Override BlockStoreMeta getBlockStoreMeta(); @Override BlockStoreMeta getBlockStoreMetaFull(); @Override void registerBlockStoreEventListener(BlockStoreEventListener listener); @Override void updatePinnedInodes(Set<Long> inodes); @Override boolean checkStorage(); void removeDir(StorageDir dir); @Override void close();  }