diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index a17db039415..37cd831ffd4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -435,6 +435,10 @@ Release 2.5.0 - UNRELEASED HDFS-6337. Setfacl testcase is failing due to dash character in username in TestAclCLI (umamahesh) + HDFS-5381. ExtendedBlock#hashCode should use both blockId and block pool ID + (Benoy Antony via Colin Patrick McCabe) + + Release 2.4.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/ExtendedBlock.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/ExtendedBlock.java index 3d8f3754922..27c1761ad26 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/ExtendedBlock.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/ExtendedBlock.java @@ -112,7 +112,8 @@ public class ExtendedBlock { @Override // Object public int hashCode() { - return block.hashCode(); + int result = 31 + poolId.hashCode(); + return (31 * result + block.hashCode()); } @Override // Object diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestExtendedBlock.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestExtendedBlock.java index 4c117a992e8..10c1671b627 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestExtendedBlock.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestExtendedBlock.java @@ -49,6 +49,26 @@ public class TestExtendedBlock { new ExtendedBlock(POOL_A, BLOCK_1_GS1), new ExtendedBlock(POOL_A, BLOCK_1_GS2)); } + + @Test + public void testHashcode() { + + // Different pools, same block id -> different hashcode + assertNotEquals( + new ExtendedBlock(POOL_A, BLOCK_1_GS1).hashCode(), + new ExtendedBlock(POOL_B, BLOCK_1_GS1).hashCode()); + + // Same pool, different block id -> different hashcode + assertNotEquals( + new ExtendedBlock(POOL_A, BLOCK_1_GS1).hashCode(), + new ExtendedBlock(POOL_A, BLOCK_2_GS1).hashCode()); + + // Same block -> same hashcode + assertEquals( + new ExtendedBlock(POOL_A, BLOCK_1_GS1).hashCode(), + new ExtendedBlock(POOL_A, BLOCK_1_GS1).hashCode()); + + } private static void assertNotEquals(Object a, Object b) { assertFalse("expected not equal: '" + a + "' and '" + b + "'",