Skip to content

Commit

Permalink
\linkedin#63. Dynamometer does not support negative block id's
Browse files Browse the repository at this point in the history
  • Loading branch information
jojochuang committed Oct 7, 2018
1 parent 8072558 commit bfea43b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
*/
class XMLParser {

// Legacy block id can be negative
private static final Pattern BLOCK_PATTERN =
Pattern.compile("<block><id>(\\d+)</id><genstamp>(\\d+)</genstamp><numBytes>(\\d+)</numBytes></block>");
Pattern.compile("<block><id>(-?\\d+)</id><genstamp>(\\d+)</genstamp><numBytes>(\\d+)</numBytes></block>");

private State currentState = State.DEFAULT;
private short currentReplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,26 @@ public synchronized void injectBlocks(String bpid,

for (Block b: injectBlocks) {
BInfo binfo = new BInfo(bpid, b, false);
blockMaps.get((int) (b.getBlockId() % storages.size())).put(binfo.theBlock, binfo);
long indexOfBlock;
if (b.getBlockId() < 0) {
indexOfBlock = (b.getBlockId() * (-1)) % storages.size();
} else {
indexOfBlock = b.getBlockId() % storages.size();
}
blockMaps.get((int) indexOfBlock).put(binfo.theBlock, binfo);
}
}
}

/** Get the storage that a given block lives within. */
private SimulatedStorage getStorage(Block b) {
return storages.get((int) (b.getBlockId() % storages.size()));
long indexOfBlock;
if (b.getBlockId() < 0) {
indexOfBlock = (b.getBlockId() * (-1)) % storages.size();
} else {
indexOfBlock = b.getBlockId() % storages.size();
}
return storages.get((int) indexOfBlock);
}

/**
Expand Down

0 comments on commit bfea43b

Please sign in to comment.