koarz commented on code in PR #51282:
URL: https://github.com/apache/doris/pull/51282#discussion_r2125455939


##########
be/src/exec/schema_scanner/schema_tablets_scanner.cpp:
##########
@@ -0,0 +1,219 @@
+// 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/schema_scanner/schema_tablets_scanner.h"
+
+#include <gen_cpp/Descriptors_types.h>
+#include <gen_cpp/olap_common.pb.h>
+
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "cloud/cloud_storage_engine.h"
+#include "cloud/cloud_tablet.h"
+#include "cloud/cloud_tablet_mgr.h"
+#include "cloud/config.h"
+#include "common/status.h"
+#include "olap/storage_engine.h"
+#include "olap/tablet_fwd.h"
+#include "olap/tablet_manager.h"
+#include "runtime/define_primitive_type.h"
+#include "runtime/exec_env.h"
+#include "runtime/runtime_state.h"
+#include "vec/common/string_ref.h"
+
+namespace doris {
+namespace vectorized {
+class Block;
+} // namespace vectorized
+
+#include "common/compile_check_begin.h"
+
+std::vector<SchemaScanner::ColumnDesc> SchemaTabletsScanner::_s_tbls_columns = 
{
+        //   name,       type,          size,     is_null
+        {"BE_ID", TYPE_BIGINT, sizeof(int64_t), true},
+        {"TABLET_ID", TYPE_BIGINT, sizeof(int64_t), true},
+        {"REPLICA_ID", TYPE_BIGINT, sizeof(int64_t), true},
+        {"PARTITION_ID", TYPE_BIGINT, sizeof(int64_t), true},
+        {"TABLET_PATH", TYPE_STRING, sizeof(StringRef), true},
+        {"TABLET_LOCAL_SIZE", TYPE_BIGINT, sizeof(int64_t), true},
+        {"TABLET_REMOTE_SIZE", TYPE_BIGINT, sizeof(int64_t), true},
+        {"VERSION_COUNT", TYPE_BIGINT, sizeof(int64_t), true},
+        {"SEGMENT_COUNT", TYPE_BIGINT, sizeof(int64_t), true},
+        {"NUM_COLUMNS", TYPE_BIGINT, sizeof(int64_t), true},
+        {"ROW_SIZE", TYPE_BIGINT, sizeof(int64_t), true},
+        {"COMPACTION_SCORE", TYPE_INT, sizeof(int32_t), true},
+        {"COMPRESS_KIND", TYPE_STRING, sizeof(StringRef), true},
+        {"IS_USED", TYPE_BOOLEAN, sizeof(bool), true},
+        {"IS_ALTER_FAILED", TYPE_BOOLEAN, sizeof(bool), true},
+        {"CREATE_TIME", TYPE_BIGINT, sizeof(int64_t), true},
+        {"UPDATE_TIME", TYPE_BIGINT, sizeof(int64_t), true},
+        {"IS_OVERLAP", TYPE_BOOLEAN, sizeof(bool), true},
+};
+
+SchemaTabletsScanner::SchemaTabletsScanner()
+        : SchemaScanner(_s_tbls_columns, 
TSchemaTableType::SCH_BACKEND_TABLETS) {};
+
+Status SchemaTabletsScanner::start(RuntimeState* state) {
+    if (!_is_init) {
+        return Status::InternalError("used before initialized.");
+    }
+    _backend_id = state->backend_id();
+    RETURN_IF_ERROR(_get_all_tablets());
+    return Status::OK();
+}
+
+Status SchemaTabletsScanner::_get_all_tablets() {
+    if (config::is_cloud_mode()) {
+        auto tablets =
+                
ExecEnv::GetInstance()->storage_engine().to_cloud().tablet_mgr().get_all_tablet();
+        std::ranges::for_each(tablets, [&](auto& tablet) {
+            _tablets.push_back(std::static_pointer_cast<BaseTablet>(tablet));
+        });
+    } else {
+        auto tablets = ExecEnv::GetInstance()
+                               ->storage_engine()
+                               .to_local()
+                               .tablet_manager()
+                               ->get_all_tablet();
+        std::ranges::for_each(tablets, [&](auto& tablet) {
+            _tablets.push_back(std::static_pointer_cast<BaseTablet>(tablet));
+        });
+    }
+    return Status::OK();
+}
+
+Status SchemaTabletsScanner::get_next_block_internal(vectorized::Block* block, 
bool* eos) {
+    if (!_is_init) {
+        return Status::InternalError("Used before initialized.");
+    }
+    if (nullptr == block || nullptr == eos) {
+        return Status::InternalError("input pointer is nullptr.");
+    }
+    if (_tablets_idx >= _tablets.size()) {
+        *eos = true;
+        return Status::OK();
+    }
+    *eos = false;
+    return _fill_block_impl(block);
+}
+
+Status SchemaTabletsScanner::_fill_block_impl(vectorized::Block* block) {
+    SCOPED_TIMER(_fill_block_timer);
+
+    size_t row_num = _tablets.size();
+    if (row_num == 0) {
+        return Status::OK();
+    }
+
+    size_t fill_tablets_num = std::min(1000UL, _tablets.size() - _tablets_idx);
+    size_t fill_idx_begin = _tablets_idx;
+    size_t fill_idx_end = _tablets_idx + fill_tablets_num;
+    std::vector<void*> datas(fill_tablets_num);
+
+    auto fill_column = [&](auto&& get_value, size_t column_index) {

Review Comment:
   these part origin is like you said, but another reviewer said 
https://github.com/apache/doris/pull/49317/commits/7c0774201e44779cf73d34db296032a6921caadc



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