Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] add information_schema backend_tablets table #49317

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions be/src/exec/schema_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "exec/schema_scanner/schema_table_privileges_scanner.h"
#include "exec/schema_scanner/schema_table_properties_scanner.h"
#include "exec/schema_scanner/schema_tables_scanner.h"
#include "exec/schema_scanner/schema_tablets_scanner.h"
#include "exec/schema_scanner/schema_user_privileges_scanner.h"
#include "exec/schema_scanner/schema_user_scanner.h"
#include "exec/schema_scanner/schema_variables_scanner.h"
Expand Down Expand Up @@ -231,6 +232,8 @@ std::unique_ptr<SchemaScanner> SchemaScanner::create(TSchemaTableType::type type
return SchemaBackendKerberosTicketCacheScanner::create_unique();
case TSchemaTableType::SCH_ROUTINE_LOAD_JOB:
return SchemaRoutineLoadJobScanner::create_unique();
case TSchemaTableType::SCH_BACKEND_TABLETS:
return SchemaTabletsScanner::create_unique();
default:
return SchemaDummyScanner::create_unique();
break;
Expand Down
270 changes: 270 additions & 0 deletions be/src/exec/schema_scanner/schema_tablets_scanner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
// 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 <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 "olap/storage_engine.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},
};

SchemaTabletsScanner::SchemaTabletsScanner()
: SchemaScanner(_s_tbls_columns, TSchemaTableType::SCH_BACKEND_TABLETS),
_backend_id(0),
_tablets_idx(0) {};

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()) {
// TODO get tablets on cloud
return Status::InternalError("Not support get tablets on the cloud");
}
auto tablets =
ExecEnv::GetInstance()->storage_engine().to_local().tablet_manager()->get_all_tablet();
_tablets = std::move(tablets);
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);
// BACKEND_ID
{
int64_t src = _backend_id;
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
datas[i - fill_idx_begin] = &src;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, datas));
}
// TABLET_ID
{
std::vector<int64_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->tablet_meta()->table_id();
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 1, datas));
}
// REPLICA_ID
{
std::vector<int64_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->tablet_meta()->replica_id();
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 2, datas));
}
// PARTITION_ID
{
std::vector<int64_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->tablet_meta()->partition_id();
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 3, datas));
}
// TABLET_PATH
{
std::vector<std::string> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->tablet_path();
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 4, datas));
}
// TABLET_LOCAL_SIZE
{
std::vector<int64_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->tablet_meta()->tablet_local_size();
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 5, datas));
}
// TABLET_REMOTE_SIZE
{
std::vector<int64_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->tablet_meta()->tablet_remote_size();
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 6, datas));
}
// VERSION_COUNT
{
std::vector<int64_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = static_cast<int64_t>(tablet->tablet_meta()->version_count());
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 7, datas));
}
// SEGMENT_COUNT
{
std::vector<int64_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->tablet_meta()->get_all_segments_size();
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 8, datas));
}
// NUM_COLUMNS
{
std::vector<int64_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->tablet_meta()->tablet_columns_num();
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 9, datas));
}
// ROW_SIZE
{
std::vector<int64_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = static_cast<int64_t>(tablet->row_size());
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 10, datas));
}
// COMPACTION_SCORE
{
std::vector<int32_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->get_compaction_score();
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 11, datas));
}
// COMPRESS_KIND
{
std::vector<std::string> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = CompressKind_Name(tablet->compress_kind());
datas[i - fill_idx_begin] = srcs.data() + i - fill_idx_begin;
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 12, datas));
}
// IS_USED
{
std::vector<int8_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->is_used();
datas[i - fill_idx_begin] = &srcs[i - fill_idx_begin];
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 13, datas));
}
// IS_ALTER_FAILED
{
std::vector<int8_t> srcs(fill_tablets_num);
for (size_t i = fill_idx_begin; i < fill_idx_end; ++i) {
TabletSharedPtr tablet = _tablets[i];
srcs[i - fill_idx_begin] = tablet->is_alter_failed();
datas[i - fill_idx_begin] = &srcs[i - fill_idx_begin];
}
RETURN_IF_ERROR(fill_dest_column_for_range(block, 14, datas));
}

_tablets_idx += fill_tablets_num;
return Status::OK();
}
} // namespace doris
57 changes: 57 additions & 0 deletions be/src/exec/schema_scanner/schema_tablets_scanner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 <cstddef>
#include <cstdint>
#include <vector>

#include "common/status.h"
#include "exec/schema_scanner.h"
#include "olap/tablet.h"

namespace doris {
class RuntimeState;

namespace vectorized {
class Block;
} // namespace vectorized

class SchemaTabletsScanner : public SchemaScanner {
ENABLE_FACTORY_CREATOR(SchemaTabletsScanner)

public:
SchemaTabletsScanner();

~SchemaTabletsScanner() override = default;

Status start(RuntimeState* state) override;

Status get_next_block_internal(vectorized::Block* block, bool* eos) override;

private:
Status _get_all_tablets();

Status _fill_block_impl(vectorized::Block* block);

static std::vector<SchemaScanner::ColumnDesc> _s_tbls_columns;
int64_t _backend_id = 0;
size_t _tablets_idx = 0;
std::vector<TabletSharedPtr> _tablets;
};
} // namespace doris
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public enum SchemaTableType {
SCH_CREATE_TABLE("CREATE_TABLE", "CREATE_TABLE", TSchemaTableType.SCH_CREATE_TABLE),
SCH_INVALID("NULL", "NULL", TSchemaTableType.SCH_INVALID),
SCH_ROWSETS("ROWSETS", "ROWSETS", TSchemaTableType.SCH_ROWSETS),
SCH_TABLETS("BACKEND_TABLETS", "BACKEND_TABLETS", TSchemaTableType.SCH_BACKEND_TABLETS),
SCH_PARAMETERS("PARAMETERS", "PARAMETERS", TSchemaTableType.SCH_PARAMETERS),
SCH_METADATA_NAME_IDS("METADATA_NAME_IDS", "METADATA_NAME_IDS", TSchemaTableType.SCH_METADATA_NAME_IDS),
SCH_PROFILING("PROFILING", "PROFILING", TSchemaTableType.SCH_PROFILING),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public class SchemaTable extends Table {
.column("CURRENT_USED_MEMORY_BYTES", ScalarType.createType(PrimitiveType.BIGINT))
.column("SHUFFLE_SEND_BYTES", ScalarType.createType(PrimitiveType.BIGINT))
.column("SHUFFLE_SEND_ROWS", ScalarType.createType(PrimitiveType.BIGINT))
.column("QUERY_TYPE", ScalarType.createVarchar(256))
.column("QUERY_TYPE", ScalarType.createVarchar(256))
.column("SPILL_WRITE_BYTES_TO_LOCAL_STORAGE",
ScalarType.createType(PrimitiveType.BIGINT))
.column("SPILL_READ_BYTES_FROM_LOCAL_STORAGE",
Expand Down Expand Up @@ -621,6 +621,24 @@ public class SchemaTable extends Table {
.column("IS_ABNORMAL_PAUSE", ScalarType.createType(PrimitiveType.BOOLEAN))
.build())
)
.put("backend_tablets", new SchemaTable(SystemIdGenerator.getNextId(), "backend_tablets", TableType.SCHEMA,
builder().column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
.column("TABLET_ID", ScalarType.createType(PrimitiveType.BIGINT))
.column("REPLICA_ID", ScalarType.createType(PrimitiveType.BIGINT))
.column("PARTITION_ID", ScalarType.createType(PrimitiveType.BIGINT))
.column("TABLET_PATH", ScalarType.createStringType())
.column("TABLET_LOCAL_SIZE", ScalarType.createType(PrimitiveType.BIGINT))
.column("TABLET_REMOTE_SIZE", ScalarType.createType(PrimitiveType.BIGINT))
.column("VERSION_COUNT", ScalarType.createType(PrimitiveType.BIGINT))
.column("SEGMENT_COUNT", ScalarType.createType(PrimitiveType.BIGINT))
.column("NUM_COLUMNS", ScalarType.createType(PrimitiveType.BIGINT))
.column("ROW_SIZE", ScalarType.createType(PrimitiveType.BIGINT))
.column("COMPACTION_SCORE", ScalarType.createType(PrimitiveType.INT))
.column("COMPRESS_KIND", ScalarType.createStringType())
.column("IS_USED", ScalarType.createType(PrimitiveType.BOOLEAN))
.column("IS_ALTER_FAILED", ScalarType.createType(PrimitiveType.BOOLEAN))
.build())
)
.build();

private boolean fetchAllFe = false;
Expand Down
3 changes: 2 additions & 1 deletion gensrc/thrift/Descriptors.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ enum TSchemaTableType {
SCH_FILE_CACHE_STATISTICS = 51,
SCH_CATALOG_META_CACHE_STATISTICS = 52,
SCH_BACKEND_KERBEROS_TICKET_CACHE = 53,
SCH_ROUTINE_LOAD_JOB = 54;
SCH_ROUTINE_LOAD_JOB = 54,
SCH_BACKEND_TABLETS=55;
}

enum THdfsCompression {
Expand Down
Loading