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
…35615) (#36280)

Signed-off-by: luohaha <[email protected]>
  • Loading branch information
luohaha authored Dec 2, 2023
1 parent 952da2d commit f13de63
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 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
56 changes: 55 additions & 1 deletion be/src/storage/tablet_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

#include "storage/tablet_updates.h"

#include <gutil/strings/util.h>

#include <cmath>
#include <ctime>
#include <filesystem>
#include <memory>

#include "common/status.h"
Expand Down Expand Up @@ -2437,6 +2440,38 @@ size_t TabletUpdates::_get_rowset_num_deletes(const Rowset& rowset) {
return num_dels;
}

Status TabletUpdates::_get_extra_file_size(int64_t* pindex_size, int64_t* col_size) {
const std::string tablet_path = _tablet.schema_hash_path();
try {
for (const auto& entry : std::filesystem::directory_iterator(tablet_path)) {
if (entry.is_regular_file()) {
std::string filename = entry.path().filename().string();

if (HasPrefixString(filename, "index.l")) {
if (pindex_size != nullptr) {
*pindex_size += std::filesystem::file_size(entry);
}
} else if (HasSuffixString(filename, ".cols")) {
// TODO skip the expired cols file
if (col_size != nullptr) {
*col_size += std::filesystem::file_size(entry);
}
}
}
}
} catch (const std::filesystem::filesystem_error& ex) {
std::string err_msg = "Iterate dir " + tablet_path + " Filesystem error: " + ex.what();
return Status::InternalError(err_msg);
} catch (const std::exception& ex) {
std::string err_msg = "Iterate dir " + tablet_path + " Standard error: " + ex.what();
return Status::InternalError(err_msg);
} catch (...) {
std::string err_msg = "Iterate dir " + tablet_path + " Unknown exception occurred.";
return Status::InternalError(err_msg);
}
return Status::OK();
}

void TabletUpdates::get_tablet_info_extra(TTabletInfo* info) {
int64_t min_readable_version = 0;
int64_t max_readable_version = 0;
Expand Down Expand Up @@ -2480,13 +2515,22 @@ void TabletUpdates::get_tablet_info_extra(TTabletInfo* info) {
LOG_EVERY_N(WARNING, 10) << "get_tablet_info_extra() some rowset stats not found tablet=" << _tablet.tablet_id()
<< " rowset=" << err_rowsets;
}
int64_t pindex_size = 0;
int64_t col_size = 0;
Status st = _get_extra_file_size(&pindex_size, &col_size);
if (!st.ok()) {
// Ignore error status here, because we don't to break up tablet report because of get extra file size failure.
// So just print error log and keep going.
LOG(ERROR) << "get extra file size in primary table fail, tablet_id: " << _tablet.tablet_id()
<< " status: " << st;
}
info->__set_version(version);
info->__set_min_readable_version(min_readable_version);
info->__set_max_readable_version(max_readable_version);
info->__set_version_miss(has_pending);
info->__set_version_count(version_count);
info->__set_row_count(total_row);
info->__set_data_size(total_size);
info->__set_data_size(total_size + pindex_size + col_size);
info->__set_is_error_state(_error);
}

Expand Down Expand Up @@ -3469,6 +3513,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
2 changes: 2 additions & 0 deletions be/src/storage/tablet_updates.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ class TabletUpdates {

std::timed_mutex* get_index_lock() { return &_index_lock; }

Status _get_extra_file_size(int64_t* pindex_size, int64_t* col_size);

private:
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 f13de63

Please sign in to comment.