From 5799c37a7ed4e5782d18d16c0cfc47ce87765189 Mon Sep 17 00:00:00 2001 From: wenjinchao Date: Thu, 10 Jul 2025 17:55:00 +0800 Subject: [PATCH 1/3] fix warning Signed-off-by: wenjinchao Change-Id: I9f7de340ef4d4c1320a7d163fe68020c289cfccb --- .../service/udmf/store/runtime_store.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.cpp b/services/distributeddataservice/service/udmf/store/runtime_store.cpp index cd57d8801..ab19ed1c3 100644 --- a/services/distributeddataservice/service/udmf/store/runtime_store.cpp +++ b/services/distributeddataservice/service/udmf/store/runtime_store.cpp @@ -435,9 +435,11 @@ bool RuntimeStore::Init() }); if (status != DBStatus::OK) { ZLOGE("GetKvStore fail, status: %{public}d.", static_cast(status)); - if (status == INVALID_PASSWD_OR_CORRUPTED_DB && - (status = delegateManager_->DeleteKvStore(storeId_)) != DBStatus::OK) { - ZLOGE("DeleteKvStore fail, status: %{public}d.", static_cast(status)); + if (status == INVALID_PASSWD_OR_CORRUPTED_DB) { + status = delegateManager_->DeleteKvStore(storeId_); + if (status != DBStatus::OK) { + ZLOGE("DeleteKvStore fail, status: %{public}d.", static_cast(status)); + } } return false; } @@ -450,8 +452,12 @@ bool RuntimeStore::Init() if (retStatus != DBStatus::OK) { ZLOGE("CloseKvStore fail, status: %{public}d.", static_cast(retStatus)); } - if (isCorrupted_ && (retStatus = delegateManager_->DeleteKvStore(storeId_)) != DBStatus::OK) { - ZLOGE("DeleteKvStore fail, status: %{public}d.", static_cast(retStatus)); + if (isCorrupted_) { + ZLOGE("Db corrupted!"); + retStatus = delegateManager_->DeleteKvStore(storeId_); + if (retStatus != DBStatus::OK) { + ZLOGE("DeleteKvStore fail, status: %{public}d.", static_cast(retStatus)); + } } }; kvStore_ = std::shared_ptr(delegate, release); -- Gitee From 17ef60071e6b6ce0fb7ab995686163e8638a6180 Mon Sep 17 00:00:00 2001 From: wenjinchao Date: Fri, 11 Jul 2025 09:59:55 +0800 Subject: [PATCH 2/3] fix warning Signed-off-by: wenjinchao Change-Id: I8abcb2a21c8d932ff5ac80d5234628900681593d --- .../service/udmf/store/runtime_store.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.cpp b/services/distributeddataservice/service/udmf/store/runtime_store.cpp index ab19ed1c3..0e26004ed 100644 --- a/services/distributeddataservice/service/udmf/store/runtime_store.cpp +++ b/services/distributeddataservice/service/udmf/store/runtime_store.cpp @@ -444,16 +444,16 @@ bool RuntimeStore::Init() return false; } auto release = [this](KvStoreNbDelegate *delegate) { - ZLOGI("Release runtime kvStore."); + ZLOGI("Release runtime kvStore, db is corrupted: %{public}d.", isCorrupted_); if (delegate == nullptr) { return; } auto retStatus = delegateManager_->CloseKvStore(delegate); if (retStatus != DBStatus::OK) { ZLOGE("CloseKvStore fail, status: %{public}d.", static_cast(retStatus)); + return; } if (isCorrupted_) { - ZLOGE("Db corrupted!"); retStatus = delegateManager_->DeleteKvStore(storeId_); if (retStatus != DBStatus::OK) { ZLOGE("DeleteKvStore fail, status: %{public}d.", static_cast(retStatus)); -- Gitee From 7082f9a75325369f733d94a9d9cdd7b4f8ecb0e8 Mon Sep 17 00:00:00 2001 From: wenjinchao Date: Fri, 11 Jul 2025 11:43:55 +0800 Subject: [PATCH 3/3] fix -warming Signed-off-by: wenjinchao Change-Id: I9ddfe747fa659164b074b4fdb13468d56466fbde --- .../service/udmf/store/runtime_store.cpp | 33 +++++++++++-------- .../service/udmf/store/runtime_store.h | 2 ++ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.cpp b/services/distributeddataservice/service/udmf/store/runtime_store.cpp index 0e26004ed..8badccd4a 100644 --- a/services/distributeddataservice/service/udmf/store/runtime_store.cpp +++ b/services/distributeddataservice/service/udmf/store/runtime_store.cpp @@ -445,20 +445,7 @@ bool RuntimeStore::Init() } auto release = [this](KvStoreNbDelegate *delegate) { ZLOGI("Release runtime kvStore, db is corrupted: %{public}d.", isCorrupted_); - if (delegate == nullptr) { - return; - } - auto retStatus = delegateManager_->CloseKvStore(delegate); - if (retStatus != DBStatus::OK) { - ZLOGE("CloseKvStore fail, status: %{public}d.", static_cast(retStatus)); - return; - } - if (isCorrupted_) { - retStatus = delegateManager_->DeleteKvStore(storeId_); - if (retStatus != DBStatus::OK) { - ZLOGE("DeleteKvStore fail, status: %{public}d.", static_cast(retStatus)); - } - } + ReleaseStore(delegate); }; kvStore_ = std::shared_ptr(delegate, release); uint32_t pragmData = 16 * 1024 * 1024; @@ -547,6 +534,24 @@ bool RuntimeStore::SaveMetaData() return true; } +void RuntimeStore::ReleaseStore(DistributedDB::KvStoreNbDelegate *delegate) +{ + if (delegate == nullptr) { + return; + } + auto retStatus = delegateManager_->CloseKvStore(delegate); + if (retStatus != DBStatus::OK) { + ZLOGE("CloseKvStore fail, status: %{public}d.", static_cast(retStatus)); + return; + } + if (isCorrupted_) { + retStatus = delegateManager_->DeleteKvStore(storeId_); + if (retStatus != DBStatus::OK) { + ZLOGE("DeleteKvStore fail, status: %{public}d.", static_cast(retStatus)); + } + } +} + void RuntimeStore::SetDelegateManager(const std::string &dataDir, const std::string &appId, const std::string &userId) { delegateManager_ = std::make_shared(appId, userId); diff --git a/services/distributeddataservice/service/udmf/store/runtime_store.h b/services/distributeddataservice/service/udmf/store/runtime_store.h index 214c6f15c..cfa06e62d 100644 --- a/services/distributeddataservice/service/udmf/store/runtime_store.h +++ b/services/distributeddataservice/service/udmf/store/runtime_store.h @@ -65,6 +65,8 @@ private: const DevNameMap &deviceNameMap); Status PutSummary(const UnifiedData &data, std::vector &entries); Status MarkWhenCorrupted(DistributedDB::DBStatus status); + void ReleaseStore(DistributedDB::KvStoreNbDelegate *delegate); + bool isCorrupted_ = false; }; } // namespace UDMF -- Gitee