Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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