コード例 #1
0
 /** @return true if all of the blocks in this file are marked as completed. */
 private boolean allBlocksComplete() throws StorageException, TransactionContextException {
   for (BlockInfo b : getBlocks()) {
     if (!b.isComplete()) {
       return false;
     }
   }
   return true;
 }
コード例 #2
0
 /**
  * Update the length for the last block
  *
  * @param lastBlockLength The length of the last block reported from client
  * @throws IOException
  */
 void updateLengthOfLastBlock(long lastBlockLength) throws IOException, StorageException {
   BlockInfo lastBlock = this.getLastBlock();
   assert (lastBlock != null)
       : "The last block for path " + this.getFullPathName() + " is null when updating its length";
   assert (lastBlock instanceof BlockInfoUnderConstruction)
       : "The last block for path "
           + this.getFullPathName()
           + " is not a BlockInfoUnderConstruction when updating its length";
   lastBlock.setNumBytes(lastBlockLength);
 }
コード例 #3
0
  public void removeBlock(BlockInfo block) throws StorageException, TransactionContextException {
    BlockInfo[] blks = getBlocks();
    int index = block.getBlockIndex();

    block.setBlockCollection(null);

    if (index != blks.length) {
      for (int i = index + 1; i < blks.length; i++) {
        blks[i].setBlockIndex(i - 1);
      }
    }
  }
コード例 #4
0
 /** Convert the last block of the file to an under-construction block. Set its locations. */
 @Override
 public BlockInfoUnderConstruction setLastBlock(BlockInfo lastBlock, DatanodeDescriptor[] targets)
     throws IOException, StorageException {
   if (numBlocks() == 0) {
     throw new IOException("Failed to set last block: File is empty.");
   }
   BlockInfoUnderConstruction ucBlock =
       lastBlock.convertToBlockUnderConstruction(BlockUCState.UNDER_CONSTRUCTION, targets);
   ucBlock.setBlockCollection(this);
   setBlock(numBlocks() - 1, ucBlock);
   return ucBlock;
 }