Skip to content

Commit 32c40bd

Browse files
nshangyimingmergify[bot]
authored andcommitted
[Enhancement] Add medium type of data dir in be_tablets (#37070)
Add storage medium type in be_tablets table so that we can debug some balancing issue. Signed-off-by: Dejun Xia <[email protected]> (cherry picked from commit cceb194) # Conflicts: # be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.cpp # be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.h # fe/fe-core/src/main/java/com/starrocks/catalog/system/information/BeTabletsSystemTable.java # fe/fe-core/src/test/resources/sql/scheduler/schema_scan.sql
1 parent dbb87bb commit 32c40bd

File tree

5 files changed

+198
-1
lines changed

5 files changed

+198
-1
lines changed

be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.cpp

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
#include "exec/vectorized/schema_scanner/schema_be_tablets_scanner.h"
1616

1717
#include "agent/master_info.h"
18+
<<<<<<< HEAD:be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.cpp
1819
#include "exec/vectorized/schema_scanner/schema_helper.h"
20+
=======
21+
#include "exec/schema_scanner/schema_helper.h"
22+
#include "gen_cpp/Types_types.h" // for TStorageMedium::type
23+
>>>>>>> cceb1943b0 ([Enhancement] Add medium type of data dir in be_tablets (#37070)):be/src/exec/schema_scanner/schema_be_tablets_scanner.cpp
1924
#include "gutil/strings/substitute.h"
2025
#include "runtime/string_value.h"
2126
#include "storage/storage_engine.h"
@@ -27,6 +32,7 @@ using starrocks::vectorized::fill_column_with_slot;
2732
namespace starrocks::vectorized {
2833

2934
SchemaScanner::ColumnDesc SchemaBeTabletsScanner::_s_columns[] = {
35+
<<<<<<< HEAD:be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.cpp
3036
{"BE_ID", TYPE_BIGINT, sizeof(int64_t), false}, {"TABLE_ID", TYPE_BIGINT, sizeof(int64_t), false},
3137
{"PARTITION_ID", TYPE_BIGINT, sizeof(int64_t), false}, {"TABLET_ID", TYPE_BIGINT, sizeof(int64_t), false},
3238
{"NUM_VERSION", TYPE_BIGINT, sizeof(int64_t), false}, {"MAX_VERSION", TYPE_BIGINT, sizeof(int64_t), false},
@@ -36,6 +42,28 @@ SchemaScanner::ColumnDesc SchemaBeTabletsScanner::_s_columns[] = {
3642
{"STATE", TYPE_VARCHAR, sizeof(StringValue), false}, {"TYPE", TYPE_VARCHAR, sizeof(StringValue), false},
3743
{"DATA_DIR", TYPE_VARCHAR, sizeof(StringValue), false}, {"SHARD_ID", TYPE_BIGINT, sizeof(int64_t), false},
3844
{"SCHEMA_HASH", TYPE_BIGINT, sizeof(int64_t), false},
45+
=======
46+
{"BE_ID", TYPE_BIGINT, sizeof(int64_t), false},
47+
{"TABLE_ID", TYPE_BIGINT, sizeof(int64_t), false},
48+
{"PARTITION_ID", TYPE_BIGINT, sizeof(int64_t), false},
49+
{"TABLET_ID", TYPE_BIGINT, sizeof(int64_t), false},
50+
{"NUM_VERSION", TYPE_BIGINT, sizeof(int64_t), false},
51+
{"MAX_VERSION", TYPE_BIGINT, sizeof(int64_t), false},
52+
{"MIN_VERSION", TYPE_BIGINT, sizeof(int64_t), false},
53+
{"NUM_ROWSET", TYPE_BIGINT, sizeof(int64_t), false},
54+
{"NUM_ROW", TYPE_BIGINT, sizeof(int64_t), false},
55+
{"DATA_SIZE", TYPE_BIGINT, sizeof(int64_t), false},
56+
{"INDEX_MEM", TYPE_BIGINT, sizeof(int64_t), false},
57+
{"CREATE_TIME", TYPE_BIGINT, sizeof(int64_t), false},
58+
{"STATE", TYPE_VARCHAR, sizeof(StringValue), false},
59+
{"TYPE", TYPE_VARCHAR, sizeof(StringValue), false},
60+
{"DATA_DIR", TYPE_VARCHAR, sizeof(StringValue), false},
61+
{"SHARD_ID", TYPE_BIGINT, sizeof(int64_t), false},
62+
{"SCHEMA_HASH", TYPE_BIGINT, sizeof(int64_t), false},
63+
{"INDEX_DISK", TYPE_BIGINT, sizeof(int64_t), false},
64+
{"MEDIUM_TYPE", TYPE_VARCHAR, sizeof(StringValue), false},
65+
66+
>>>>>>> cceb1943b0 ([Enhancement] Add medium type of data dir in be_tablets (#37070)):be/src/exec/schema_scanner/schema_be_tablets_scanner.cpp
3967
};
4068

4169
SchemaBeTabletsScanner::SchemaBeTabletsScanner()
@@ -87,13 +115,32 @@ static const char* keys_type_to_string(KeysType type) {
87115
}
88116
}
89117

118+
<<<<<<< HEAD:be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.cpp
90119
Status SchemaBeTabletsScanner::fill_chunk(vectorized::ChunkPtr* chunk) {
120+
=======
121+
static const char* medium_type_to_string(TStorageMedium::type type) {
122+
switch (type) {
123+
case TStorageMedium::SSD:
124+
return "SSD";
125+
case TStorageMedium::HDD:
126+
return "HDD";
127+
default:
128+
return "UNKNOWN";
129+
}
130+
}
131+
132+
Status SchemaBeTabletsScanner::fill_chunk(ChunkPtr* chunk) {
133+
>>>>>>> cceb1943b0 ([Enhancement] Add medium type of data dir in be_tablets (#37070)):be/src/exec/schema_scanner/schema_be_tablets_scanner.cpp
91134
const auto& slot_id_to_index_map = (*chunk)->get_slot_id_to_index_map();
92135
auto end = _cur_idx + 1;
93136
for (; _cur_idx < end; _cur_idx++) {
94137
auto& info = _infos[_cur_idx];
95138
for (const auto& [slot_id, index] : slot_id_to_index_map) {
139+
<<<<<<< HEAD:be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.cpp
96140
if (slot_id < 1 || slot_id > 17) {
141+
=======
142+
if (slot_id < 1 || slot_id > 19) {
143+
>>>>>>> cceb1943b0 ([Enhancement] Add medium type of data dir in be_tablets (#37070)):be/src/exec/schema_scanner/schema_be_tablets_scanner.cpp
97144
return Status::InternalError(strings::Substitute("invalid slot id:$0", slot_id));
98145
}
99146
vectorized::ColumnPtr column = (*chunk)->get_column_by_slot_id(slot_id);
@@ -139,7 +186,7 @@ Status SchemaBeTabletsScanner::fill_chunk(vectorized::ChunkPtr* chunk) {
139186
break;
140187
}
141188
case 9: {
142-
// num rowt
189+
// num rows
143190
fill_column_with_slot<TYPE_BIGINT>(column.get(), (void*)&info.num_row);
144191
break;
145192
}
@@ -171,8 +218,14 @@ Status SchemaBeTabletsScanner::fill_chunk(vectorized::ChunkPtr* chunk) {
171218
break;
172219
}
173220
case 15: {
221+
<<<<<<< HEAD:be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.cpp
174222
Slice type = Slice(info.data_dir);
175223
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&type);
224+
=======
225+
// DATA_DIR
226+
Slice data_dir = Slice(info.data_dir);
227+
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&data_dir);
228+
>>>>>>> cceb1943b0 ([Enhancement] Add medium type of data dir in be_tablets (#37070)):be/src/exec/schema_scanner/schema_be_tablets_scanner.cpp
176229
break;
177230
}
178231
case 16: {
@@ -183,6 +236,20 @@ Status SchemaBeTabletsScanner::fill_chunk(vectorized::ChunkPtr* chunk) {
183236
fill_column_with_slot<TYPE_BIGINT>(column.get(), (void*)&info.schema_hash);
184237
break;
185238
}
239+
<<<<<<< HEAD:be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.cpp
240+
=======
241+
case 18: {
242+
// INDEX_DISK
243+
fill_column_with_slot<TYPE_BIGINT>(column.get(), (void*)&info.index_disk_usage);
244+
break;
245+
}
246+
case 19: {
247+
// medium type
248+
Slice medium_type = Slice(medium_type_to_string(info.medium_type));
249+
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&medium_type);
250+
break;
251+
}
252+
>>>>>>> cceb1943b0 ([Enhancement] Add medium type of data dir in be_tablets (#37070)):be/src/exec/schema_scanner/schema_be_tablets_scanner.cpp
186253
default:
187254
break;
188255
}

be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "exec/vectorized/schema_scanner.h"
2020
#include "gen_cpp/FrontendService_types.h"
21+
#include "gen_cpp/Types_types.h" // for TStorageMedium::type
2122

2223
namespace starrocks {
2324

@@ -38,6 +39,11 @@ struct TabletBasicInfo {
3839
std::string data_dir;
3940
int64_t shard_id{0};
4041
int64_t schema_hash{0};
42+
<<<<<<< HEAD:be/src/exec/vectorized/schema_scanner/schema_be_tablets_scanner.h
43+
=======
44+
int64_t index_disk_usage{0};
45+
TStorageMedium::type medium_type;
46+
>>>>>>> cceb1943b0 ([Enhancement] Add medium type of data dir in be_tablets (#37070)):be/src/exec/schema_scanner/schema_be_tablets_scanner.h
4147
};
4248

4349
namespace vectorized {

be/src/storage/tablet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,7 @@ void Tablet::get_basic_info(TabletBasicInfo& info) {
12831283
info.data_dir = data_dir()->path();
12841284
info.shard_id = shard_id();
12851285
info.schema_hash = schema_hash();
1286+
info.medium_type = data_dir()->storage_medium();
12861287
if (_updates != nullptr) {
12871288
_updates->get_basic_info_extra(info);
12881289
} else {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2021-present StarRocks, Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package com.starrocks.catalog.system.information;
15+
16+
import com.starrocks.catalog.PrimitiveType;
17+
import com.starrocks.catalog.ScalarType;
18+
import com.starrocks.catalog.Table;
19+
import com.starrocks.catalog.system.SystemId;
20+
import com.starrocks.catalog.system.SystemTable;
21+
import com.starrocks.thrift.TSchemaTableType;
22+
23+
import static com.starrocks.catalog.system.SystemTable.NAME_CHAR_LEN;
24+
import static com.starrocks.catalog.system.SystemTable.builder;
25+
26+
public class BeTabletsSystemTable {
27+
public static SystemTable create() {
28+
return new SystemTable(SystemId.BE_TABLETS_ID,
29+
"be_tablets",
30+
Table.TableType.SCHEMA,
31+
builder()
32+
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
33+
.column("TABLE_ID", ScalarType.createType(PrimitiveType.BIGINT))
34+
.column("PARTITION_ID", ScalarType.createType(PrimitiveType.BIGINT))
35+
.column("TABLET_ID", ScalarType.createType(PrimitiveType.BIGINT))
36+
.column("NUM_VERSION", ScalarType.createType(PrimitiveType.BIGINT))
37+
.column("MAX_VERSION", ScalarType.createType(PrimitiveType.BIGINT))
38+
.column("MIN_VERSION", ScalarType.createType(PrimitiveType.BIGINT))
39+
.column("NUM_ROWSET", ScalarType.createType(PrimitiveType.BIGINT))
40+
.column("NUM_ROW", ScalarType.createType(PrimitiveType.BIGINT))
41+
.column("DATA_SIZE", ScalarType.createType(PrimitiveType.BIGINT))
42+
.column("INDEX_MEM", ScalarType.createType(PrimitiveType.BIGINT))
43+
.column("CREATE_TIME", ScalarType.createType(PrimitiveType.BIGINT))
44+
.column("STATE", ScalarType.createVarchar(NAME_CHAR_LEN))
45+
.column("TYPE", ScalarType.createVarchar(NAME_CHAR_LEN))
46+
.column("DATA_DIR", ScalarType.createVarchar(NAME_CHAR_LEN))
47+
.column("SHARD_ID", ScalarType.createType(PrimitiveType.BIGINT))
48+
.column("SCHEMA_HASH", ScalarType.createType(PrimitiveType.BIGINT))
49+
.column("INDEX_DISK", ScalarType.createType(PrimitiveType.BIGINT))
50+
.column("MEDIUM_TYPE", ScalarType.createVarchar(NAME_CHAR_LEN))
51+
.build(), TSchemaTableType.SCH_BE_TABLETS);
52+
}
53+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[sql]
2+
select * from information_schema.session_variables
3+
[scheduler]
4+
PLAN FRAGMENT 0(F00)
5+
DOP: 16
6+
INSTANCES
7+
INSTANCE(0-F00#0)
8+
BE: 10001
9+
10+
[fragment]
11+
PLAN FRAGMENT 0
12+
OUTPUT EXPRS:1: VARIABLE_NAME | 2: VARIABLE_VALUE
13+
PARTITION: UNPARTITIONED
14+
15+
RESULT SINK
16+
17+
0:SCAN SCHEMA
18+
[end]
19+
20+
[sql]
21+
select * from information_schema.be_tablets
22+
[scheduler]
23+
PLAN FRAGMENT 0(F01)
24+
DOP: 16
25+
INSTANCES
26+
INSTANCE(0-F01#0)
27+
BE: 10002
28+
29+
PLAN FRAGMENT 1(F00)
30+
DOP: 16
31+
INSTANCES
32+
INSTANCE(1-F00#0)
33+
DESTINATIONS: 0-F01#0
34+
BE: 10001
35+
SCAN RANGES
36+
0:SCAN SCHEMA
37+
1. <PLACEHOLDER>
38+
INSTANCE(2-F00#1)
39+
DESTINATIONS: 0-F01#0
40+
BE: 10002
41+
SCAN RANGES
42+
0:SCAN SCHEMA
43+
1. <PLACEHOLDER>
44+
INSTANCE(3-F00#2)
45+
DESTINATIONS: 0-F01#0
46+
BE: 10003
47+
SCAN RANGES
48+
0:SCAN SCHEMA
49+
1. <PLACEHOLDER>
50+
51+
[fragment]
52+
PLAN FRAGMENT 0
53+
OUTPUT EXPRS:1: BE_ID | 2: TABLE_ID | 3: PARTITION_ID | 4: TABLET_ID | 5: NUM_VERSION | 6: MAX_VERSION | 7: MIN_VERSION | 8: NUM_ROWSET | 9: NUM_ROW | 10: DATA_SIZE | 11: INDEX_MEM | 12: CREATE_TIME | 13: STATE | 14: TYPE | 15: DATA_DIR | 16: SHARD_ID | 17: SCHEMA_HASH | 18: INDEX_DISK | 19: MEDIUM_TYPE
54+
PARTITION: UNPARTITIONED
55+
56+
RESULT SINK
57+
58+
1:EXCHANGE
59+
60+
PLAN FRAGMENT 1
61+
OUTPUT EXPRS:
62+
PARTITION: RANDOM
63+
64+
STREAM DATA SINK
65+
EXCHANGE ID: 01
66+
UNPARTITIONED
67+
68+
0:SCAN SCHEMA
69+
[end]
70+

0 commit comments

Comments
 (0)