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


##########
cpp/celeborn/client/reader/WorkerPartitionReader.h:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "celeborn/network/TransportClient.h"
+#include "celeborn/protocol/PartitionLocation.h"
+
+namespace celeborn {
+namespace client {
+class PartitionReader {
+ public:
+  virtual ~PartitionReader() = default;
+

Review Comment:
   There are other types of PartitionReader, I think the method `next` can be a 
virtual method too.



##########
cpp/celeborn/client/reader/WorkerPartitionReader.h:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "celeborn/network/TransportClient.h"
+#include "celeborn/protocol/PartitionLocation.h"
+
+namespace celeborn {
+namespace client {
+class PartitionReader {
+ public:
+  virtual ~PartitionReader() = default;
+
+  virtual bool hasNext() = 0;
+
+  virtual std::unique_ptr<memory::ReadOnlyByteBuffer> next() = 0;
+};
+
+class WorkerPartitionReader
+    : public PartitionReader,
+      public std::enable_shared_from_this<WorkerPartitionReader> {
+ public:
+  // Only allow using create method to get the shared_ptr holder. This is
+  // required by the std::enable_shared_from_this functionality.
+  static std::shared_ptr<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);
+
+  ~WorkerPartitionReader() override;
+
+  bool hasNext() override;
+
+  std::unique_ptr<memory::ReadOnlyByteBuffer> next() override;
+
+  void fetchChunks();

Review Comment:
   this method can be private



##########
cpp/celeborn/client/reader/WorkerPartitionReader.h:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include "celeborn/network/TransportClient.h"
+#include "celeborn/protocol/PartitionLocation.h"
+
+namespace celeborn {
+namespace client {
+class PartitionReader {
+ public:
+  virtual ~PartitionReader() = default;
+
+  virtual bool hasNext() = 0;
+
+  virtual std::unique_ptr<memory::ReadOnlyByteBuffer> next() = 0;
+};
+
+class WorkerPartitionReader
+    : public PartitionReader,
+      public std::enable_shared_from_this<WorkerPartitionReader> {
+ public:
+  // Only allow using create method to get the shared_ptr holder. This is
+  // required by the std::enable_shared_from_this functionality.
+  static std::shared_ptr<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);
+
+  ~WorkerPartitionReader() override;
+
+  bool hasNext() override;
+
+  std::unique_ptr<memory::ReadOnlyByteBuffer> next() override;
+
+  void fetchChunks();
+
+ private:
+  // Disable creating the object directly to make sure that
+  // std::enable_shared_from_this works properly.
+  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);
+
+  // This function cannot be called within constructor!
+  void initAndCheck();
+
+  std::string shuffleKey_;
+  protocol::PartitionLocation location_;

Review Comment:
   This field may be used by the celeborn input stream, we can add a getter 
later.



##########
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:
   Setting the max iteration count is not necessary. The current max iteration 
count is 500, which means that a chunk will be fetched during 250s, this might 
not be enough if a cluster is under heavy load.



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