diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ReplicaAccessorBuilder.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ReplicaAccessorBuilder.java index 2905df1245..14651f47f1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ReplicaAccessorBuilder.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ReplicaAccessorBuilder.java @@ -36,6 +36,9 @@ public abstract class ReplicaAccessorBuilder { public abstract ReplicaAccessorBuilder setBlock(long blockId, String blockPoolId); + /** Set the genstamp of the block which is being opened. */ + public abstract ReplicaAccessorBuilder setGenerationStamp(long genstamp); + /** * Set whether checksums must be verified. Checksums should be skipped if * the user has disabled checksum verification in the configuration. Users diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index cb3b975db7..218f155e2b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -968,6 +968,9 @@ Release 2.8.0 - UNRELEASED HDFS-9112. Improve error message for Haadmin when multiple name service IDs are configured. (Anu Engineer via jing9) + HDFS-9132. Pass genstamp to ReplicaAccessorBuilder. (Colin Patrick McCabe via + Lei (Eddy) Xu) + OPTIMIZATIONS HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/BlockReaderFactory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/BlockReaderFactory.java index b21261a01b..c9add534d8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/BlockReaderFactory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/BlockReaderFactory.java @@ -383,6 +383,7 @@ private BlockReader tryToCreateExternalBlockReader() { ReplicaAccessor accessor = builder. setAllowShortCircuitReads(allowShortCircuitLocalReads). setBlock(block.getBlockId(), block.getBlockPoolId()). + setGenerationStamp(block.getGenerationStamp()). setBlockAccessToken(tokenBytes). setClientName(clientName). setConfiguration(configuration). diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestExternalBlockReader.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestExternalBlockReader.java index 48d337b6f2..3a0e8e63ad 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestExternalBlockReader.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestExternalBlockReader.java @@ -81,6 +81,7 @@ public static class SyntheticReplicaAccessorBuilder String fileName; long blockId; String blockPoolId; + long genstamp; boolean verifyChecksum; String clientName; boolean allowShortCircuit; @@ -100,6 +101,12 @@ public ReplicaAccessorBuilder setBlock(long blockId, String blockPoolId) { return this; } + @Override + public ReplicaAccessorBuilder setGenerationStamp(long genstamp) { + this.genstamp = genstamp; + return this; + } + @Override public ReplicaAccessorBuilder setVerifyChecksum(boolean verifyChecksum) { this.verifyChecksum = verifyChecksum; @@ -154,12 +161,14 @@ public static class SyntheticReplicaAccessor extends ReplicaAccessor { int numCloses = 0; String error = ""; String prefix = ""; + final long genstamp; SyntheticReplicaAccessor(SyntheticReplicaAccessorBuilder builder) { this.length = builder.visibleLength; this.contents = DFSTestUtil. calculateFileContentsFromSeed(SEED, Ints.checkedCast(length)); this.builder = builder; + this.genstamp = builder.genstamp; String uuid = this.builder.conf. get(SYNTHETIC_BLOCK_READER_TEST_UUID_KEY); LinkedList accessorsList = @@ -235,6 +244,10 @@ synchronized String getError() { return error; } + long getGenerationStamp() { + return genstamp; + } + synchronized void addError(String text) { LOG.error("SyntheticReplicaAccessor error: " + text); error = error + prefix + text; @@ -284,6 +297,8 @@ public void testExternalBlockReader() throws Exception { Assert.assertEquals(dfs.getClient().clientName, accessor.builder.clientName); Assert.assertEquals("/a", accessor.builder.fileName); + Assert.assertEquals(block.getGenerationStamp(), + accessor.getGenerationStamp()); Assert.assertTrue(accessor.builder.verifyChecksum); Assert.assertEquals(1024L, accessor.builder.visibleLength); Assert.assertEquals(1024L, accessor.totalRead);