Skip to content

Commit

Permalink
Simplify relocation block and rename to move block to be consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinjia committed Jun 27, 2015
1 parent 3ab4b0b commit 49ec1ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
24 changes: 5 additions & 19 deletions servers/src/main/java/tachyon/worker/CoreWorker.java
Expand Up @@ -138,31 +138,17 @@ public BlockReader readBlockRemote(long userId, long blockId, long lockId)
throw new FileDoesNotExistException("Block " + blockId + " does not exist on this worker.");
}

public boolean relocateBlock(long userId, long blockId, int destination) throws IOException {
public boolean moveBlock(long userId, long blockId, int tier) throws IOException {
Optional<Long> optLock = mBlockStore.lockBlock(userId, blockId, BlockLock.BlockLockType.WRITE);
// TODO: Define this behavior
if (!optLock.isPresent()) {
return false;
}
Long lockId = optLock.get();
Optional<BlockMeta> optMeta = mBlockStore.getBlockMeta(userId, blockId, lockId);
// TODO: Define this behavior
if (!optMeta.isPresent()) {
// TODO: what if this fails?
mBlockStore.unlockBlock(lockId);
return false;
}
// TODO: Add this to the BlockMeta API
BlockStoreLocation newLoc = BlockStoreLocation.anyDirInTier(destination);
if (mBlockStore.copyBlock(userId, blockId, lockId, newLoc)) {
// TODO: What if this fails?
mBlockStore.removeBlock(userId, blockId, lockId);
mBlockStore.unlockBlock(lockId);
return true;
} else {
mBlockStore.unlockBlock(lockId);
return false;
}
BlockStoreLocation dst = BlockStoreLocation.anyDirInTier(tier);
boolean result = mBlockStore.moveBlock(userId, blockId, lockId, dst);
mBlockStore.unlockBlock(lockId);
return result;
}

public boolean requestSpace(long userId, long blockId, long bytesRequested) throws IOException {
Expand Down
Expand Up @@ -74,7 +74,7 @@ public void completeBlock(long userId, long blockId) {
* @return true if the block is freed successfully, false otherwise
*/
public boolean freeBlock(long blockId) throws FileNotFoundException {
return mWorker.relocateBlock(-1L, blockId, -1);
return mWorker.freeBlock(-1L, blockId, -1);
}

/**
Expand Down Expand Up @@ -185,7 +185,7 @@ public String lockBlock(long blockId, long userId) throws FileDoesNotExistExcept
* @param blockId
*/
public boolean promoteBlock(long blockId) throws org.apache.thrift.TException {
return mWorker.relocateBlock(-1, blockId, 1);
return mWorker.moveBlock(-1, blockId, 1);
}

/**
Expand Down

0 comments on commit 49ec1ce

Please sign in to comment.