Skip to content

Commit

Permalink
[MINOR] Fix ownership cache update method (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
wynot12 authored and JunhoeKim committed Jul 19, 2017
1 parent 12bac04 commit 4614b61
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,15 @@ public List<Integer> getCurrentLocalBlockIds() {
*/
public void update(final int blockId, final String oldOwnerId, final String newOwnerId) {
ownershipLocks.get(blockId).writeLock().lock();
final String localOldOwnerId;
try {
final String localOldOwnerId = blockOwnerArray.getAndSet(blockId, newOwnerId);
localOldOwnerId = blockOwnerArray.getAndSet(blockId, newOwnerId);
if (!localOldOwnerId.equals(oldOwnerId)) {
LOG.log(Level.WARNING, "Local ownership cache thought block {0} was in store {1}, but it was actually in {2}",
new Object[]{blockId, oldOwnerId, newOwnerId});
new Object[]{blockId, localOldOwnerId, oldOwnerId});
}
LOG.log(Level.FINE, "Ownership of block {0} is updated from {1} to {2}",
new Object[]{blockId, oldOwnerId, newOwnerId});
new Object[]{blockId, localOldOwnerId, newOwnerId});

if (localExecutorId.equals(newOwnerId)) {
// it should be done while holding a write-lock
Expand All @@ -210,10 +211,10 @@ public void update(final int blockId, final String oldOwnerId, final String newO
// decrement numBlocks in old owner
final Long syncOpId;
synchronized (executorIdToNumBlocks) {
final int remainingBlocks = executorIdToNumBlocks.get(oldOwnerId).decrementAndGet();
final int remainingBlocks = executorIdToNumBlocks.get(localOldOwnerId).decrementAndGet();
if (remainingBlocks == 0) {
executorIdToNumBlocks.remove(oldOwnerId);
syncOpId = ongoingSyncs.remove(oldOwnerId);
executorIdToNumBlocks.remove(localOldOwnerId);
syncOpId = ongoingSyncs.remove(localOldOwnerId);
} else {
syncOpId = null;
}
Expand All @@ -231,7 +232,7 @@ public void update(final int blockId, final String oldOwnerId, final String newO

// sync complete
if (syncOpId != null) {
completeSync(syncOpId, oldOwnerId);
completeSync(syncOpId, localOldOwnerId);
}
}

Expand Down

0 comments on commit 4614b61

Please sign in to comment.