Gabriel39 commented on code in PR #15642:
URL: https://github.com/apache/doris/pull/15642#discussion_r1071099127


##########
be/src/exec/rowid_fetcher.cpp:
##########
@@ -0,0 +1,131 @@
+// 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 "exec/rowid_fetcher.h"
+
+#include "bthread/countdown_event.h"
+#include "exec/tablet_info.h" // DorisNodesInfo
+#include "gen_cpp/Types_types.h"
+#include "gen_cpp/internal_service.pb.h"
+#include "runtime/exec_env.h"       // ExecEnv
+#include "runtime/runtime_state.h"  // RuntimeState
+#include "util/brpc_client_cache.h" // BrpcClientCache
+#include "util/defer_op.h"
+#include "vec/core/block.h" // Block
+
+namespace doris {
+
+Status RowIDFetcher::init(DorisNodesInfo* nodes_info) {
+    for (auto [node_id, node_info] : nodes_info->nodes_info()) {
+        auto client = 
ExecEnv::GetInstance()->brpc_internal_client_cache()->get_client(
+                node_info.host, node_info.brpc_port);
+        if (!client) {
+            LOG(WARNING) << "Get rpc stub failed, host=" << node_info.host
+                         << ", port=" << node_info.brpc_port;
+            return Status::InternalError("RowIDFetcher failed to init rpc 
client");
+        }
+        _stubs.push_back(client);
+    }
+    return Status::OK();
+}
+
+static std::string format_rowid(const GlobalRowLoacation& location) {
+    return fmt::format("{} {} {} {}", location.tablet_id,
+                       location.row_location.rowset_id.to_string(),
+                       location.row_location.segment_id, 
location.row_location.row_id);
+}
+
+PMultiGetRequest RowIDFetcher::init_fetch_request(const 
vectorized::ColumnString& row_ids) {
+    PMultiGetRequest mget_req;
+    _tuple_desc->to_protobuf(mget_req.mutable_desc());
+    for (auto slot : _tuple_desc->slots()) {
+        slot->to_protobuf(mget_req.add_slots());
+    }
+    for (size_t i = 0; i < row_ids.size(); ++i) {
+        PMultiGetRequest::RowId row_id;
+        StringRef row_id_rep = row_ids.get_data_at(i);
+        auto location = reinterpret_cast<const 
GlobalRowLoacation*>(row_id_rep.data);
+        row_id.set_tablet_id(location->tablet_id);
+        row_id.set_rowset_id(location->row_location.rowset_id.to_string());
+        row_id.set_segment_id(location->row_location.segment_id);
+        row_id.set_ordinal_id(location->row_location.row_id);
+        *mget_req.add_rowids() = std::move(row_id);
+    }
+    mget_req.set_be_exec_version(_st->be_exec_version());
+    return mget_req;
+}
+
+static void fetch_callback(bthread::CountdownEvent* counter) {
+    Defer __defer([&] { counter->signal(); });
+}
+
+static Status MergeRPCResults(const std::vector<PMultiGetResponse>& rsps,
+                              const std::vector<brpc::Controller>& cntls,
+                              vectorized::MutableBlock* output_block) {
+    for (const auto& cntl : cntls) {
+        if (cntl.Failed()) {
+            LOG(WARNING) << "Failed to fetch meet rpc error:" << 
cntl.ErrorText()
+                         << ", host:" << cntl.remote_side();
+            return Status::InternalError(cntl.ErrorText());
+        }
+    }
+    for (const auto& resp : rsps) {
+        Status st(resp.status());
+        if (!st.ok()) {
+            LOG(WARNING) << "Failed to fetch " << st.to_string();
+            return st;
+        }
+        vectorized::Block partial_block(resp.block());
+        output_block->merge(partial_block);
+    }
+    return Status::OK();
+}
+
+Status RowIDFetcher::fetch(const vectorized::ColumnPtr& row_ids,
+                           vectorized::MutableBlock* res_block) {
+    assert(!_stubs.empty());

Review Comment:
   ```suggestion
       CHECK(!_stubs.empty());
   ```



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to