Skip to content

Commit

Permalink
Optimize method call in method 'moveBlockMeta' in BlockMetadataManage…
Browse files Browse the repository at this point in the history
…r.java
  • Loading branch information
fanshiqing committed Jul 21, 2015
1 parent 8e12c0d commit afb3559
Showing 1 changed file with 6 additions and 5 deletions.
Expand Up @@ -353,31 +353,32 @@ public synchronized BlockMeta moveBlockMeta(BlockMeta blockMeta, BlockStoreLocat
return blockMeta;
}

long blockSize = blockMeta.getBlockSize();
int newTierAlias = newLocation.tierAlias();
StorageTier newTier = getTier(newTierAlias);
StorageDir newDir = null;
if (newLocation.equals(BlockStoreLocation.anyDirInTier(newTierAlias))) {
for (StorageDir dir : newTier.getStorageDirs()) {
if (dir.getAvailableBytes() >= blockMeta.getBlockSize()) {
if (dir.getAvailableBytes() >= blockSize) {
newDir = dir;
break;
break;
}
}
} else {
StorageDir dir = newTier.getDir(newLocation.dir());
if (dir.getAvailableBytes() >= blockMeta.getBlockSize()) {
if (dir.getAvailableBytes() >= blockSize) {
newDir = dir;
}
}

if (newDir == null) {
throw new OutOfSpaceException("Failed to move BlockMeta: newLocation " + newLocation
+ " does not have enough space for " + blockMeta.getBlockSize() + " bytes");
+ " does not have enough space for " + blockSize + " bytes");
}
StorageDir oldDir = blockMeta.getParentDir();
oldDir.removeBlockMeta(blockMeta);
BlockMeta newBlockMeta =
new BlockMeta(blockMeta.getBlockId(), blockMeta.getBlockSize(), newDir);
new BlockMeta(blockMeta.getBlockId(), blockSize, newDir);
newDir.addBlockMeta(newBlockMeta);
return newBlockMeta;
}
Expand Down

0 comments on commit afb3559

Please sign in to comment.