Skip to content

Commit

Permalink
[Enhancement] show persistent index disk cost in be_tablets (backport #…
Browse files Browse the repository at this point in the history
  • Loading branch information
luohaha authored Dec 2, 2023
1 parent 31f22b8 commit 618c032
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
12 changes: 10 additions & 2 deletions be/src/exec/schema_scanner/schema_be_tablets_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SchemaScanner::ColumnDesc SchemaBeTabletsScanner::_s_columns[] = {
{"INDEX_MEM", TYPE_BIGINT, sizeof(int64_t), false}, {"CREATE_TIME", TYPE_BIGINT, sizeof(int64_t), false},
{"STATE", TYPE_VARCHAR, sizeof(StringValue), false}, {"TYPE", TYPE_VARCHAR, sizeof(StringValue), false},
{"DATA_DIR", TYPE_VARCHAR, sizeof(StringValue), false}, {"SHARD_ID", TYPE_BIGINT, sizeof(int64_t), false},
{"SCHEMA_HASH", TYPE_BIGINT, sizeof(int64_t), false},
{"SCHEMA_HASH", TYPE_BIGINT, sizeof(int64_t), false}, {"INDEX_DISK", TYPE_BIGINT, sizeof(int64_t), false},
};

SchemaBeTabletsScanner::SchemaBeTabletsScanner()
Expand Down Expand Up @@ -92,7 +92,7 @@ Status SchemaBeTabletsScanner::fill_chunk(ChunkPtr* chunk) {
for (; _cur_idx < end; _cur_idx++) {
auto& info = _infos[_cur_idx];
for (const auto& [slot_id, index] : slot_id_to_index_map) {
if (slot_id < 1 || slot_id > 17) {
if (slot_id < 1 || slot_id > 18) {
return Status::InternalError(strings::Substitute("invalid slot id:$0", slot_id));
}
ColumnPtr column = (*chunk)->get_column_by_slot_id(slot_id);
Expand Down Expand Up @@ -170,18 +170,26 @@ Status SchemaBeTabletsScanner::fill_chunk(ChunkPtr* chunk) {
break;
}
case 15: {
// DATA_DIR
Slice type = Slice(info.data_dir);
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&type);
break;
}
case 16: {
// SHARD_ID
fill_column_with_slot<TYPE_BIGINT>(column.get(), (void*)&info.shard_id);
break;
}
case 17: {
// SCHEMA_HASH
fill_column_with_slot<TYPE_BIGINT>(column.get(), (void*)&info.schema_hash);
break;
}
case 18: {
// INDEX_DISK
fill_column_with_slot<TYPE_BIGINT>(column.get(), (void*)&info.index_disk_usage);
break;
}
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions be/src/exec/schema_scanner/schema_be_tablets_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct TabletBasicInfo {
std::string data_dir;
int64_t shard_id{0};
int64_t schema_hash{0};
int64_t index_disk_usage{0};
};

class SchemaBeTabletsScanner : public SchemaScanner {
Expand Down
18 changes: 16 additions & 2 deletions be/src/storage/tablet_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2743,10 +2743,14 @@ Status TabletUpdates::_get_extra_file_size(int64_t* pindex_size, int64_t* col_si
std::string filename = entry.path().filename().string();

if (HasPrefixString(filename, "index.l")) {
*pindex_size += std::filesystem::file_size(entry);
if (pindex_size != nullptr) {
*pindex_size += std::filesystem::file_size(entry);
}
} else if (HasSuffixString(filename, ".cols")) {
// TODO skip the expired cols file
*col_size += std::filesystem::file_size(entry);
if (col_size != nullptr) {
*col_size += std::filesystem::file_size(entry);
}
}
}
}
Expand Down Expand Up @@ -3879,6 +3883,16 @@ void TabletUpdates::get_basic_info_extra(TabletBasicInfo& info) {
info.index_mem = index_entry->size();
index_cache.release(index_entry);
}
int64_t pindex_size = 0;
auto st = _get_extra_file_size(&pindex_size, nullptr);
if (!st.ok()) {
// Ignore error status here, because we don't to break up get basic info because of get pk index disk usage failure.
// So just print error log and keep going.
LOG(ERROR) << "get persistent index disk usage fail, tablet_id: " << _tablet.tablet_id()
<< ", error: " << st.get_error_msg();
} else {
info.index_disk_usage = pindex_size;
}
}

static double get_pk_index_write_amp_score_from_meta(Tablet* tablet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static SystemTable create() {
.column("DATA_DIR", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("SHARD_ID", ScalarType.createType(PrimitiveType.BIGINT))
.column("SCHEMA_HASH", ScalarType.createType(PrimitiveType.BIGINT))
.column("INDEX_DISK", ScalarType.createType(PrimitiveType.BIGINT))
.build(), TSchemaTableType.SCH_BE_TABLETS);
}
}

0 comments on commit 618c032

Please sign in to comment.