Index: core/src/main/java/org/apache/hama/bsp/PartitioningRunner.java =================================================================== --- core/src/main/java/org/apache/hama/bsp/PartitioningRunner.java (revision 1481000) +++ core/src/main/java/org/apache/hama/bsp/PartitioningRunner.java (working copy) @@ -196,6 +196,8 @@ peer.sync(); FileStatus[] status = fs.listStatus(partitionDir); + // To avoid race condition, we should store the peer number + int peerNum = peer.getNumPeers(); // Call sync() one more time to avoid concurrent access peer.sync(); @@ -205,15 +207,8 @@ for (FileStatus statu : status) { int partitionID = Integer .parseInt(statu.getPath().getName().split("[-]")[1]); - int denom = desiredNum / peer.getNumPeers(); - int assignedID = partitionID; - if (denom > 1) { - assignedID = partitionID / denom; - } + int assignedID = partitionID % peerNum; - if (assignedID == peer.getNumPeers()) - assignedID = assignedID - 1; - // TODO set replica factor to 1. // TODO and check whether we can write to specific DataNode. if (assignedID == peer.getPeerIndex()) {