peterxcli commented on code in PR #11412:
URL: https://github.com/apache/ozone/pull/11412#discussion_r4228910980
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/ContainerStateMachine.java:
##########
@@ -889,6 +897,102 @@ public CompletableFuture<Message> query(Message request) {
}
}
+ /** Serves a Ratis read-only data stream. Only ReadBlock is supported, see
{@link #streamReadBlock}. */
+ @Override
+ public long transferTo(Message request, WritableByteChannel stream) throws
IOException {
+ try {
+ metrics.incNumQueryStateMachineOps();
+ final ContainerCommandRequestProto requestProto =
message2ContainerCommandRequestProto(request);
+ if (requestProto.getCmdType() != Type.ReadBlock) {
+ throw new IOException("Unsupported command for a read-only data
stream: " + requestProto.getCmdType());
+ }
+ return streamReadBlock(dispatcher, requestProto, stream);
+ } catch (IOException e) {
+ metrics.incNumQueryStateMachineFails();
+ throw e;
+ }
+ }
+
+ /**
+ * Reads a block and writes each ReadBlock response to the stream as one
reply:
+ * {@code [int: metadata length][metadata: the response without its
data][data]}.
+ * Then closes the stream, which sends the terminal reply.
+ * If the read fails, this method throws without closing the stream. Ratis
sends the failure as the terminal reply.
+ *
+ * @return the number of bytes written to the stream
+ */
+ static long streamReadBlock(ContainerDispatcher dispatcher,
ContainerCommandRequestProto request,
Review Comment:
just because it doesnt depend on ContainerStateMachine.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]