From 708e8cd0f103e2ecb1d87c4ebc6006772e5af22f Mon Sep 17 00:00:00 2001 From: Zihui Deng <451809218@qq.com> Date: Thu, 25 Apr 2024 10:10:38 +0800 Subject: [PATCH] [fix][store] Fixup debug command STORE_REGION_ACTUAL_METRICS issues. --- src/meta/store_meta_manager.cc | 25 ++++++++++++++++++++----- src/meta/store_meta_manager.h | 7 +++++-- src/metrics/store_metrics_manager.cc | 2 +- src/server/debug_service.cc | 10 +++++++--- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/meta/store_meta_manager.cc b/src/meta/store_meta_manager.cc index 6b5d55d50..18cd3d59d 100644 --- a/src/meta/store_meta_manager.cc +++ b/src/meta/store_meta_manager.cc @@ -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_); @@ -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); diff --git a/src/meta/store_meta_manager.h b/src/meta/store_meta_manager.h index 8a7486381..6156f4916 100644 --- a/src/meta/store_meta_manager.h +++ b/src/meta/store_meta_manager.h @@ -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(); @@ -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; } diff --git a/src/metrics/store_metrics_manager.cc b/src/metrics/store_metrics_manager.cc index 3e731c08a..61a1b090f 100644 --- a/src/metrics/store_metrics_manager.cc +++ b/src/metrics/store_metrics_manager.cc @@ -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())) { diff --git a/src/server/debug_service.cc b/src/server/debug_service.cc index f1e14e58c..bf06e0769 100644 --- a/src/server/debug_service.cc +++ b/src/server/debug_service.cc @@ -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; @@ -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;