Skip to content

Commit

Permalink
[fix][store] Fixup debug command STORE_REGION_ACTUAL_METRICS issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
rock-git authored and ketor committed Apr 25, 2024
1 parent 8025753 commit 708e8cd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
25 changes: 20 additions & 5 deletions src/meta/store_meta_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ void Region::DeSerialize(const std::string& data) {
state_.store(inner_region_.state());
}

pb::common::RawEngine Region::GetRawEngineType() {
BAIDU_SCOPED_LOCK(mutex_);
return inner_region_.definition().raw_engine();
}

bool Region::IsTxn() {
auto range = Range(true);
return Helper::IsExecutorTxn(range.start_key()) || Helper::IsClientTxn(range.start_key());
}

bool Region::IsExecutorTxn() {
auto range = Range(true);
return Helper::IsExecutorTxn(range.start_key());
}

bool Region::IsClientTxn() {
auto range = Range(true);
return Helper::IsClientTxn(range.start_key());
}

pb::common::RegionEpoch Region::Epoch(bool lock) {
if (lock) {
BAIDU_SCOPED_LOCK(mutex_);
Expand Down Expand Up @@ -271,11 +291,6 @@ pb::common::RegionDefinition Region::Definition() {
return inner_region_.definition();
}

pb::common::RawEngine Region::GetRawEngineType() {
BAIDU_SCOPED_LOCK(mutex_);
return inner_region_.definition().raw_engine();
}

void Region::SetLastChangeJobId(int64_t job_id) {
BAIDU_SCOPED_LOCK(mutex_);
inner_region_.set_last_change_job_id(job_id);
Expand Down
7 changes: 5 additions & 2 deletions src/meta/store_meta_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ class Region {
const std::string& Name() const { return inner_region_.definition().name(); }
pb::common::RegionType Type() { return inner_region_.region_type(); }

pb::common::RawEngine GetRawEngine() { return inner_region_.definition().raw_engine(); }
pb::common::RawEngine GetRawEngineType();

bool IsTxn();
bool IsExecutorTxn();
bool IsClientTxn();

pb::common::RegionEpoch Epoch(bool lock = true);
std::string EpochToString();
Expand Down Expand Up @@ -118,7 +122,6 @@ class Region {

pb::store_internal::Region InnerRegion();
pb::common::RegionDefinition Definition();
pb::common::RawEngine GetRawEngineType();

VectorIndexWrapperPtr VectorIndexWrapper() { return vector_index_wapper_; }
void SetVectorIndexWrapper(VectorIndexWrapperPtr vector_index_wapper) { vector_index_wapper_ = vector_index_wapper; }
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/store_metrics_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ bool StoreRegionMetrics::CollectMetrics() {
// vector index
bool vector_index_has_data = false;
auto vector_index_wrapper = region->VectorIndexWrapper();
auto vector_reader = engine_->NewVectorReader(region->GetRawEngine());
auto vector_reader = engine_->NewVectorReader(region->GetRawEngineType());

if (vector_index_wrapper != nullptr && vector_reader != nullptr) {
if (BAIDU_UNLIKELY(pb::common::VectorIndexType::VECTOR_INDEX_TYPE_NONE != vector_index_wrapper->Type())) {
Expand Down
10 changes: 7 additions & 3 deletions src/server/debug_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ static pb::common::RegionMetrics GetRegionActualMetrics(int64_t region_id) {
return region_metrics;
}

auto raw_engine = Server::GetInstance().GetRawEngine(region->GetRawEngine());
auto raw_engine = Server::GetInstance().GetRawEngine(region->GetRawEngineType());
if (raw_engine == nullptr) {
DINGO_LOG(ERROR) << "Not found raw engine for region " << region_id;
return region_metrics;
Expand All @@ -357,13 +357,17 @@ static pb::common::RegionMetrics GetRegionActualMetrics(int64_t region_id) {
std::string min_key, max_key;
auto range = region->Range();

std::string start_key = region->IsTxn() ? Helper::EncodeTxnKey(range.start_key(), 0) : range.start_key();
std::string end_key = region->IsTxn() ? Helper::EncodeTxnKey(range.end_key(), 0) : range.end_key();

auto column_family_names = Helper::GetColumnFamilyNames(range.start_key());
for (const auto& name : column_family_names) {
IteratorOptions options;
options.upper_bound = range.end_key();
options.upper_bound = end_key;

auto iter = raw_engine->Reader()->NewIterator(name, options);
int32_t temp_key_count = 0;
for (iter->Seek(range.start_key()); iter->Valid(); iter->Next()) {
for (iter->Seek(start_key); iter->Valid(); iter->Next()) {
size += iter->Key().size() + iter->Value().size();

++temp_key_count;
Expand Down

0 comments on commit 708e8cd

Please sign in to comment.