This is an automated email from the ASF dual-hosted git repository.
peterxcli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new d59193ca8cd HDDS-17206. Refactor GetBlock handling shared by
BlockInputStream and StreamBlockInputStream (#11660)
d59193ca8cd is described below
commit d59193ca8cdcbde632af21b287d6ef64b11c9f77
Author: Peter Lee <[email protected]>
AuthorDate: Thu Oct 22 08:30:49 2026 +0800
HDDS-17206. Refactor GetBlock handling shared by BlockInputStream and
StreamBlockInputStream (#11660)
---
.../hdds/scm/storage/BlockExtendedInputStream.java | 40 +++++++++++++
.../hadoop/hdds/scm/storage/BlockInputStream.java | 48 +---------------
.../hdds/scm/storage/StreamBlockInputStream.java | 13 +----
.../scm/storage/TestStreamBlockInputStream.java | 67 ++++++++++++----------
4 files changed, 79 insertions(+), 89 deletions(-)
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockExtendedInputStream.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockExtendedInputStream.java
index dc47a9edaca..64c1ef81a2a 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockExtendedInputStream.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockExtendedInputStream.java
@@ -19,12 +19,20 @@
import java.io.IOException;
import java.time.Instant;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import org.apache.hadoop.hdds.client.BlockID;
+import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.BlockData;
+import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ChunkInfo;
+import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto;
+import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.DatanodeBlockID;
+import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.GetBlockResponseProto;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.OzoneClientConfig;
+import org.apache.hadoop.hdds.scm.XceiverClientSpi;
+import org.apache.hadoop.hdds.scm.XceiverClientSpi.Validator;
import org.apache.hadoop.hdds.scm.client.HddsClientUtils;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.security.token.OzoneBlockTokenIdentifier;
@@ -41,6 +49,9 @@ public abstract class BlockExtendedInputStream extends
ExtendedInputStream
private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(BlockExtendedInputStream.class);
+ protected static final List<Validator> VALIDATORS =
+ ContainerProtocolCalls.toValidatorList((request, response) ->
validate(response));
+
public abstract BlockID getBlockID();
@Override
@@ -96,6 +107,35 @@ protected boolean shouldRetryRead(IOException cause,
RetryPolicy retryPolicy, in
return false;
}
+ protected BlockData getBlockDataUsingGRPCClient(XceiverClientSpi client,
Pipeline pipeline,
+ Token<OzoneBlockTokenIdentifier> token) throws IOException {
+ LOG.debug("Get block info for block {}", getBlockID());
+ return ContainerProtocolCalls.getBlock(client, VALIDATORS, getBlockID(),
token, pipeline).getBlockData();
+ }
+
+ private static void validate(ContainerCommandResponseProto response) throws
IOException {
+ if (!response.hasGetBlock()) {
+ throw new IllegalArgumentException("Not GetBlock: response=" + response);
+ }
+ final GetBlockResponseProto b = response.getGetBlock();
+ final long blockLength = b.getBlockData().getSize();
+ final List<ChunkInfo> chunks = b.getBlockData().getChunksList();
+ for (int i = 0; i < chunks.size(); i++) {
+ final ChunkInfo c = chunks.get(i);
+ // HDDS-10682 caused an empty chunk to get written to the end of some EC
blocks. Due to this
+ // validation, these blocks will not be readable. In the EC case, the
empty chunk is always
+ // the last chunk and the offset is the block length. We can safely
ignore this case and not fail.
+ if (c.getLen() <= 0 && i == chunks.size() - 1 && c.getOffset() ==
blockLength) {
+ DatanodeBlockID blockID = b.getBlockData().getBlockID();
+ LOG.warn("The last chunk is empty for container/block {}/{} with an
offset of the block length. " +
+ "Likely due to HDDS-10682. This is safe to ignore.",
blockID.getContainerID(), blockID.getLocalID());
+ } else if (c.getLen() <= 0) {
+ throw new IOException("Failed to get chunkInfo["
+ + i + "]: len == " + c.getLen());
+ }
+ }
+ }
+
protected RetryPolicy getReadRetryPolicy(OzoneClientConfig config) {
return HddsClientUtils.createRetryPolicy(config.getMaxReadRetryCount(),
TimeUnit.SECONDS.toMillis(config.getReadRetryInterval()));
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java
index d29fe986c65..75e04b05089 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java
@@ -34,15 +34,12 @@
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.BlockData;
import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ChunkInfo;
-import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto;
-import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.DatanodeBlockID;
import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.GetBlockRequestProto;
import
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.GetBlockResponseProto;
import org.apache.hadoop.hdds.scm.OzoneClientConfig;
import org.apache.hadoop.hdds.scm.XceiverClientFactory;
import org.apache.hadoop.hdds.scm.XceiverClientShortCircuit;
import org.apache.hadoop.hdds.scm.XceiverClientSpi;
-import org.apache.hadoop.hdds.scm.XceiverClientSpi.Validator;
import
org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.hdds.security.exception.SCMSecurityException;
@@ -62,9 +59,6 @@ public class BlockInputStream extends
BlockExtendedInputStream {
public static final Logger LOG =
LoggerFactory.getLogger(BlockInputStream.class);
- private static final List<Validator> VALIDATORS =
- ContainerProtocolCalls.toValidatorList((request, response) ->
validate(response));
-
private final BlockID blockID;
private long length;
private final BlockLocationInfo blockInfo;
@@ -162,7 +156,7 @@ public synchronized void initialize() throws IOException {
try {
blockData = getBlockData();
chunks = blockData.getChunksList();
- if (blockInfo != null && blockInfo.isUnderConstruction()) {
+ if (blockInfo.isUnderConstruction()) {
// use the block length from DN if block is under construction.
length = blockData.getSize();
LOG.debug("Updated block length to {} for block {}", length,
blockID);
@@ -258,7 +252,7 @@ protected BlockData getBlockDataUsingClient() throws
IOException {
acquireClient();
}
}
- return getBlockDataUsingGRPCClient();
+ return getBlockDataUsingGRPCClient(xceiverClientGrpc, pipelineRef.get(),
tokenRef.get());
}
@VisibleForTesting
@@ -298,44 +292,6 @@ protected BlockData getBlockDataUsingSCClient() throws
IOException {
return response.getBlockData();
}
- @VisibleForTesting
- protected BlockData getBlockDataUsingGRPCClient() throws IOException {
- final Pipeline pipeline = pipelineRef.get();
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("Initializing BlockInputStream for get key to access block {}",
- blockID);
- }
-
- GetBlockResponseProto response = ContainerProtocolCalls.getBlock(
- xceiverClientGrpc, VALIDATORS, blockID, tokenRef.get(), pipeline);
- return response.getBlockData();
- }
-
- private static void validate(ContainerCommandResponseProto response)
- throws IOException {
- if (!response.hasGetBlock()) {
- throw new IllegalArgumentException("Not GetBlock: response=" + response);
- }
- final GetBlockResponseProto b = response.getGetBlock();
- final long blockLength = b.getBlockData().getSize();
- final List<ChunkInfo> chunks = b.getBlockData().getChunksList();
- for (int i = 0; i < chunks.size(); i++) {
- final ChunkInfo c = chunks.get(i);
- // HDDS-10682 caused an empty chunk to get written to the end of some EC
blocks. Due to this
- // validation, these blocks will not be readable. In the EC case, the
empty chunk is always
- // the last chunk and the offset is the block length. We can safely
ignore this case and not fail.
- if (c.getLen() <= 0 && i == chunks.size() - 1 && c.getOffset() ==
blockLength) {
- DatanodeBlockID blockID = b.getBlockData().getBlockID();
- LOG.warn("The last chunk is empty for container/block {}/{} with an
offset of the block length. " +
- "Likely due to HDDS-10682. This is safe to ignore.",
blockID.getContainerID(), blockID.getLocalID());
- } else if (c.getLen() <= 0) {
- throw new IOException("Failed to get chunkInfo["
- + i + "]: len == " + c.getLen());
- }
- }
- }
-
private void acquireClient() throws IOException {
final Pipeline pipeline = pipelineRef.get();
// xceiverClientGrpc not-null indicates there is fall back to GRPC reads
diff --git
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java
index c725bdb242f..a0aac296fca 100644
---
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java
+++
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java
@@ -101,16 +101,6 @@ public class StreamBlockInputStream extends
BlockExtendedInputStream {
// Shared by sequential and positioned reads; must be thread-safe for
concurrent access.
private final Set<DatanodeID> failedStreamingDatanodes =
ConcurrentHashMap.newKeySet();
- public StreamBlockInputStream(
- BlockID blockID, long length, Pipeline pipeline,
- Token<OzoneBlockTokenIdentifier> token,
- XceiverClientFactory xceiverClientFactory,
- Function<BlockID, BlockLocationInfo> refreshFunction,
- OzoneClientConfig config) throws IOException {
- this(new
BlockLocationInfo.Builder().setBlockID(blockID).setLength(length).build(),
- pipeline, token, xceiverClientFactory, refreshFunction, config);
- }
-
public StreamBlockInputStream(
BlockLocationInfo blockInfo, Pipeline pipeline,
Token<OzoneBlockTokenIdentifier> token,
@@ -454,8 +444,7 @@ public synchronized void updateBlockLength() throws
IOException {
while (needUpdateBlockLength) {
try {
acquireClient();
- blockLength = ContainerProtocolCalls.getBlock(xceiverClient, blockID,
tokenRef.get(), pipelineRef.get())
- .getBlockData().getSize();
+ blockLength = getBlockDataUsingGRPCClient(xceiverClient,
pipelineRef.get(), tokenRef.get()).getSize();
needUpdateBlockLength = false;
retries = 0;
LOG.debug("{}: Updated block length to {} for block {}", name,
blockLength, blockID);
diff --git
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
index 0fd8091b26d..7bdf10b495f 100644
---
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
+++
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
@@ -123,7 +123,7 @@ public void testPositionedReadsOverlapWithoutMovingCursor()
throws Exception {
return null;
}).when(client).streamRead(any(), any());
ExecutorService executor = Executors.newFixedThreadPool(2);
- try (StreamBlockInputStream stream = new StreamBlockInputStream(new
BlockID(1, 22), 100,
+ try (StreamBlockInputStream stream = new
StreamBlockInputStream(newBlockInfo(new BlockID(1, 22), 100),
mockStandalonePipeline(), null, factory, NO_REFRESH,
newStreamReadConfig())) {
stream.seek(50);
Future<?> first = executor.submit(() -> {
@@ -157,7 +157,7 @@ public void testIncompletePositionedReadReleasesResources()
throws Exception {
XceiverClientGrpc client = mockCapturingStreamingReadClient(observer,
StreamingReaderSpi::onCompleted);
XceiverClientFactory factory = mock(XceiverClientFactory.class);
when(factory.acquireClientForReadData(any())).thenReturn(client);
- try (StreamBlockInputStream stream = new StreamBlockInputStream(new
BlockID(1, 23), 100,
+ try (StreamBlockInputStream stream = new
StreamBlockInputStream(newBlockInfo(new BlockID(1, 23), 100),
mockStandalonePipeline(), null, factory, NO_REFRESH,
newStreamReadConfig())) {
stream.seek(50);
ByteBuffer buffer = ByteBuffer.allocate(2);
@@ -176,7 +176,7 @@ public void
testFailedPositionedReadInitializationReleasesClient() throws Except
doThrow(new IOException("initialization
failed")).when(client).initStreamRead(any(), any(), any());
XceiverClientFactory factory = mock(XceiverClientFactory.class);
when(factory.acquireClientForReadData(any())).thenReturn(client);
- try (StreamBlockInputStream stream = new StreamBlockInputStream(new
BlockID(1, 24), 100,
+ try (StreamBlockInputStream stream = new
StreamBlockInputStream(newBlockInfo(new BlockID(1, 24), 100),
mockStandalonePipeline(), null, factory, NO_REFRESH,
newStreamReadConfig())) {
assertThrows(IOException.class, () -> stream.readFully(10,
ByteBuffer.allocate(2)));
}
@@ -204,7 +204,7 @@ public void testCustomStreamReadConfigIsApplied() throws
Exception {
XceiverClientFactory xceiverClientFactory =
mock(XceiverClientFactory.class);
// Create a StreamBlockInputStream instance
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, length, pipeline, token,
+ newBlockInfo(blockID, length), pipeline, token,
xceiverClientFactory, NO_REFRESH, clientConfig)) {
// Assert: fields should match config values
@@ -276,7 +276,7 @@ public void
testPositionedReadDoesNotReleasePermitWhenInitStreamReadFails() thro
doNothing().when(xceiverClientFactory).releaseClientForReadData(any(),
anyBoolean());
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, 64L, pipeline, null, xceiverClientFactory, NO_REFRESH,
clientConfig)) {
+ newBlockInfo(blockID, 64L), pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer dst = ByteBuffer.allocate(16);
assertThrows(IOException.class, () -> sbis.readPositioned(0, dst));
}
@@ -290,7 +290,8 @@ public void testPositionedReadReleasesUnexpectedClient()
throws Exception {
XceiverClientFactory factory = mock(XceiverClientFactory.class);
when(factory.acquireClientForReadData(any(Pipeline.class))).thenReturn(client);
try (StreamBlockInputStream stream = new StreamBlockInputStream(
- new BlockID(1, 25), 64, mockStandalonePipeline(), null, factory,
NO_REFRESH, newStreamReadConfig())) {
+ newBlockInfo(new BlockID(1, 25), 64), mockStandalonePipeline(), null,
factory, NO_REFRESH,
+ newStreamReadConfig())) {
assertThrows(IOException.class, () -> stream.readPositioned(0,
ByteBuffer.allocate(1)));
}
verify(factory).releaseClientForReadData(client, false);
@@ -325,7 +326,7 @@ public void testReleasesStreamPermitAtBlockEof() throws
Exception {
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, length, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, length), pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer firstRead = ByteBuffer.allocate((int) length - 1);
int first = sbis.read(firstRead);
@@ -364,7 +365,7 @@ public void testCancelsRequestStreamWhenOnCompletedThrows()
throws Exception {
when(xceiverClientFactory.acquireClientForReadData(any(Pipeline.class))).thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, data.length, pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
+ newBlockInfo(blockID, data.length), pipeline, null,
xceiverClientFactory, NO_REFRESH, clientConfig)) {
ByteBuffer all = ByteBuffer.allocate(data.length);
assertEquals(data.length, sbis.read(all));
assertEquals(data.length, sbis.getPos());
@@ -394,7 +395,7 @@ public void
testCloseDoesNotFailWhenOnCompletedAndCancelThrow() throws Exception
when(xceiverClientFactory.acquireClientForReadData(any(Pipeline.class))).thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, data.length, pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
+ newBlockInfo(blockID, data.length), pipeline, null,
xceiverClientFactory, NO_REFRESH, clientConfig)) {
ByteBuffer all = ByteBuffer.allocate(data.length);
assertEquals(data.length, sbis.read(all));
assertEquals(data.length, sbis.getPos());
@@ -462,7 +463,7 @@ public void
testPollDoesNotDropQueuedItemWhenFutureCompletesFirst() throws Excep
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, data.length, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, data.length), pipeline, null,
xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate(data.length);
@@ -481,7 +482,7 @@ public void
testPollDoesNotDropQueuedItemWhenFutureCompletesFirst() throws Excep
@Test
public void testUnderConstructionBlockUsesLengthFromDatanode() throws
Exception {
byte[] data = {1, 2, 3, 4};
- BlockLocationInfo blockInfo = new
BlockLocationInfo.Builder().setBlockID(new BlockID(1L,
30L)).setLength(2).build();
+ BlockLocationInfo blockInfo = newBlockInfo(new BlockID(1L, 30L), 2);
blockInfo.setUnderConstruction(true);
Pipeline pipeline = mockStandalonePipeline();
XceiverClientGrpc client = mockGetBlockClient(data, pipeline);
@@ -499,8 +500,7 @@ public void
testUnderConstructionBlockUsesLengthFromDatanode() throws Exception
@Test
public void testCompletedBlockDoesNotGetBlockFromDatanode() throws Exception
{
byte[] data = {1, 2, 3, 4};
- BlockLocationInfo blockInfo = new
BlockLocationInfo.Builder().setBlockID(new BlockID(1L, 31L))
- .setLength(data.length).build();
+ BlockLocationInfo blockInfo = newBlockInfo(new BlockID(1L, 31L),
data.length);
Pipeline pipeline = mockStandalonePipeline();
XceiverClientGrpc client = mockGetBlockClient(data, pipeline);
try (StreamBlockInputStream sbis = newStreamForBlock(blockInfo, pipeline,
client)) {
@@ -531,6 +531,10 @@ private XceiverClientGrpc mockGetBlockClient(byte[] data,
Pipeline pipeline) thr
return client;
}
+ private static BlockLocationInfo newBlockInfo(BlockID blockID, long length) {
+ return new
BlockLocationInfo.Builder().setBlockID(blockID).setLength(length).build();
+ }
+
private StreamBlockInputStream newStreamForBlock(BlockLocationInfo
blockInfo, Pipeline pipeline,
XceiverClientGrpc client) throws Exception {
XceiverClientFactory factory = mock(XceiverClientFactory.class);
@@ -548,7 +552,7 @@ private StreamBlockInputStream newStreamForData(byte[]
data) throws Exception {
when(xceiverClientFactory.acquireClientForReadData(any(Pipeline.class)))
.thenReturn(xceiverClient);
doNothing().when(xceiverClientFactory).releaseClientForReadData(any(),
anyBoolean());
- return new StreamBlockInputStream(blockID, data.length, pipeline, null,
+ return new StreamBlockInputStream(newBlockInfo(blockID, data.length),
pipeline, null,
xceiverClientFactory, NO_REFRESH, newStreamReadConfig());
}
@@ -639,7 +643,7 @@ public void testPreReadWindowIsRefilledInBulk() throws
Exception {
final long refillThreshold;
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, blockLength, mockStandalonePipeline(), null,
xceiverClientFactory,
+ newBlockInfo(blockID, blockLength), mockStandalonePipeline(), null,
xceiverClientFactory,
NO_REFRESH, clientConfig)) {
refillThreshold =
StreamBlockInputStream.getPreReadRefillThreshold(sbis.getPreReadSize());
// Read one small buffer at a time, as KeyInputStream does, so every
response reaches readBlock again.
@@ -701,7 +705,7 @@ public void testDeadlineExceededFailsOverToFreshStream()
throws Exception {
when(xceiverClientFactory.acquireClientForReadData(any(Pipeline.class))).thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, data.length, pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
+ newBlockInfo(blockID, data.length), pipeline, null,
xceiverClientFactory, NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate(data.length);
assertEquals(data.length, sbis.read(buf), "read should succeed after
failing over to a fresh stream");
assertArrayEquals(data, buf.array());
@@ -811,7 +815,7 @@ public void
testSeekReadsCorrectBytesWhenFirstResponseIsFullyBeforePosition() th
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, length, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, length), pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
sbis.seek(4);
@@ -855,7 +859,7 @@ public void testReadReturnsUnsignedByte() throws Exception {
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, 2, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, 2), pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
assertEquals(0x80, sbis.read());
assertEquals(0xFF, sbis.read());
@@ -914,7 +918,7 @@ public void
testReadFromQueueNpeWhenStreamCompletesWithoutCoveringSeekPosition()
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, length, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, length), pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
sbis.seek(4);
@@ -976,7 +980,7 @@ public void
testReadDoesNotDropQueuedItemsWhenFutureIsDoneOnSecondCall() throws
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, length, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, length), pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate((int) length);
// With the bug: read() returns null on the second call (isDone is true),
@@ -1028,7 +1032,7 @@ public void
testReadGetsFreshResponseTimeoutAfterStreamReadWait() throws Excepti
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, 1L, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, 1L), pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate(1);
assertEquals(1, sbis.read(buf));
@@ -1068,7 +1072,7 @@ public void
testReadWithoutNewRequestGetsFreshTimeoutBudget() throws Exception {
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, 2L, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, 2L), pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer first = ByteBuffer.allocate(1);
assertEquals(1, sbis.read(first));
@@ -1129,7 +1133,7 @@ public void
testStreamCompletedMidReadWithEmptyQueueSurfacesEof() throws Excepti
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, 4L, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, 4L), pipeline, null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate(4);
int bytesRead = assertDoesNotThrow(() -> sbis.read(buf),
@@ -1176,7 +1180,7 @@ public void
testChecksumFailureOnShortPayloadSurfacesRealError() throws Exceptio
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, data.length, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, data.length), pipeline, null,
xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate(data.length);
IOException thrown = assertThrows(IOException.class, () ->
sbis.read(buf),
@@ -1217,7 +1221,7 @@ public void testChecksumFailureBeforeResponseRegistered()
throws Exception {
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, data.length, pipeline, null, xceiverClientFactory,
+ newBlockInfo(blockID, data.length), pipeline, null,
xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate(data.length);
IOException thrown = assertThrows(IOException.class, () ->
sbis.read(buf),
@@ -1250,7 +1254,7 @@ public void testFailFastOnErrorResponseProto() throws
Exception {
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, 1024L, mockStandalonePipeline(), null, xceiverClientFactory,
+ newBlockInfo(blockID, 1024L), mockStandalonePipeline(), null,
xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate(1024);
@@ -1285,7 +1289,7 @@ public void testFailFastOnGrpcOutOfRangeStatus() throws
Exception {
.thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- blockID, 1024L, mockStandalonePipeline(), null, xceiverClientFactory,
+ newBlockInfo(blockID, 1024L), mockStandalonePipeline(), null,
xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate(1024);
@@ -1333,7 +1337,7 @@ public void testErrorResponseDuringPollWaitIsNotEof()
throws Exception {
when(xceiverClientFactory.acquireClientForReadData(any(Pipeline.class))).thenReturn(xceiverClient);
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- new BlockID(1L, 23L), 1024L, mockStandalonePipeline(), null,
xceiverClientFactory,
+ newBlockInfo(new BlockID(1L, 23L), 1024L), mockStandalonePipeline(),
null, xceiverClientFactory,
NO_REFRESH, clientConfig)) {
ByteBuffer buf = ByteBuffer.allocate(1024);
IOException thrown = assertThrows(IOException.class, () ->
sbis.read(buf),
@@ -1393,7 +1397,7 @@ public void testRetriesErrorResponseAfterRefresh() throws
Exception {
};
try (StreamBlockInputStream sbis = new StreamBlockInputStream(
- new BlockID(1L, 22L), data.length, mockStandalonePipeline(), null,
xceiverClientFactory,
+ newBlockInfo(new BlockID(1L, 22L), data.length),
mockStandalonePipeline(), null, xceiverClientFactory,
refresh, clientConfig)) {
ByteBuffer positioned = ByteBuffer.allocate(data.length);
assertEquals(data.length, sbis.readPositioned(0, positioned));
@@ -1547,8 +1551,9 @@ private void
assertStreamResponse(ContainerCommandResponseProto response, byte[]
XceiverClientGrpc client = mockCapturingStreamingReadClient(observer,
reader -> reader.onNext(response));
XceiverClientFactory factory = mock(XceiverClientFactory.class);
when(factory.acquireClientForReadData(any(Pipeline.class))).thenReturn(client);
- try (StreamBlockInputStream stream = new StreamBlockInputStream(new
BlockID(1, 16258), expected.length,
- mockStandalonePipeline(), null, factory, NO_REFRESH, config)) {
+ try (StreamBlockInputStream stream = new StreamBlockInputStream(
+ newBlockInfo(new BlockID(1, 16258), expected.length),
mockStandalonePipeline(), null, factory, NO_REFRESH,
+ config)) {
stream.seek(seek);
byte[] actual = new byte[expected.length - seek];
if (fails) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]