HolyLow commented on code in PR #3137:
URL: https://github.com/apache/celeborn/pull/3137#discussion_r1986659153


##########
cpp/celeborn/client/reader/WorkerPartitionReader.cpp:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "celeborn/client/reader/WorkerPartitionReader.h"
+
+namespace celeborn {
+namespace client {
+std::shared_ptr<WorkerPartitionReader> WorkerPartitionReader::create(
+    const std::shared_ptr<const conf::CelebornConf>& conf,
+    const std::string& shuffleKey,
+    const protocol::PartitionLocation& location,
+    int32_t startMapIndex,
+    int32_t endMapIndex,
+    network::TransportClientFactory* clientFactory) {
+  return std::shared_ptr<WorkerPartitionReader>(new WorkerPartitionReader(
+      conf, shuffleKey, location, startMapIndex, endMapIndex, clientFactory));
+}
+
+WorkerPartitionReader::WorkerPartitionReader(
+    const std::shared_ptr<const conf::CelebornConf>& conf,
+    const std::string& shuffleKey,
+    const protocol::PartitionLocation& location,
+    int32_t startMapIndex,
+    int32_t endMapIndex,
+    network::TransportClientFactory* clientFactory)
+    : shuffleKey_(shuffleKey),
+      location_(location),
+      startMapIndex_(startMapIndex),
+      endMapIndex_(endMapIndex),
+      fetchingChunkId_(0),
+      toConsumeChunkId_(0),
+      maxFetchChunksInFlight_(conf->clientFetchMaxReqsInFlight()),
+      fetchTimeout_(conf->clientFetchTimeout()) {
+  CELEBORN_CHECK_NOT_NULL(clientFactory);
+  client_ = clientFactory->createClient(location_.host, location_.fetchPort);
+
+  protocol::OpenStream openStream(
+      shuffleKey, location_.filename(), startMapIndex_, endMapIndex_);
+
+  network::RpcRequest request(
+      network::Message::nextRequestId(),
+      openStream.toTransportMessage().toReadOnlyByteBuffer());
+
+  // TODO: it might not be safe to call blocking & might failing command
+  // in constructor
+  auto response = client_->sendRpcRequestSync(request);
+  auto body = response.body();
+  auto transportMessage = protocol::TransportMessage(std::move(body));
+  streamHandler_ =
+      protocol::StreamHandler::fromTransportMessage(transportMessage);
+}
+
+WorkerPartitionReader::~WorkerPartitionReader() {
+  protocol::BufferStreamEnd bufferStreamEnd;
+  bufferStreamEnd.streamId = streamHandler_->streamId;
+  network::RpcRequest request(
+      network::Message::nextRequestId(),
+      bufferStreamEnd.toTransportMessage().toReadOnlyByteBuffer());
+  client_->sendRpcRequestWithoutResponse(request);
+}
+
+bool WorkerPartitionReader::hasNext() {
+  return toConsumeChunkId_ < streamHandler_->numChunks;
+}
+
+std::unique_ptr<memory::ReadOnlyByteBuffer> WorkerPartitionReader::next() {
+  initAndCheck();
+  fetchChunks();
+  auto result = std::unique_ptr<memory::ReadOnlyByteBuffer>();
+  // TODO: the try iter here is not aligned with java version.
+  for (int iter = 0; iter < kDefaultMaxTryConsume && result == nullptr;

Review Comment:
   Changed to infinite loop.



-- 
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]

Reply via email to