From 030eaf5119b7e4cb4bea11ca8a418b1c022596da Mon Sep 17 00:00:00 2001 From: yangliu Date: Wed, 2 Apr 2025 09:24:21 +0800 Subject: [PATCH 1/4] modify onchange Signed-off-by: yangliu --- .../service/kvdb/kvdb_observer_proxy.cpp | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp index 3eb5413ef..e2bdbae6a 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp @@ -47,8 +47,8 @@ void KVDBObserverProxy::OnChange(const ChangeNotification &changeNotification) int64_t insertSize = ITypesUtil::GetTotalSize(changeNotification.GetInsertEntries()); int64_t updateSize = ITypesUtil::GetTotalSize(changeNotification.GetUpdateEntries()); int64_t deleteSize = ITypesUtil::GetTotalSize(changeNotification.GetDeleteEntries()); - int64_t totalSize = insertSize + updateSize + deleteSize + sizeof(uint32_t); - if (insertSize < 0 || updateSize < 0 || deleteSize < 0 || !data.WriteInt32(totalSize)) { + int64_t totalSize = insertSize + updateSize + deleteSize; + if (insertSize < 0 || updateSize < 0 || deleteSize < 0 || !data.WriteInt64(totalSize)) { ZLOGE("Write ChangeNotification buffer size to parcel failed."); return; } @@ -59,10 +59,24 @@ void KVDBObserverProxy::OnChange(const ChangeNotification &changeNotification) return; } } else { - if (!ITypesUtil::Marshal(data, changeNotification.GetDeviceId(), uint32_t(changeNotification.IsClear())) || - !ITypesUtil::MarshalToBuffer(changeNotification.GetInsertEntries(), insertSize, data) || - !ITypesUtil::MarshalToBuffer(changeNotification.GetUpdateEntries(), updateSize, data) || - !ITypesUtil::MarshalToBuffer(changeNotification.GetDeleteEntries(), deleteSize, data)) { + if (!ITypesUtil::Marshal(data, changeNotification.GetDeviceId(), uint32_t(changeNotification.IsClear()))) { + ZLOGE("write deviceId to parcel failed"); + return; + } + if (!data.WriteInt32(changeNotification.GetInsertEntries().size()) || + !data.WriteInt32(changeNotification.GetUpdateEntries().size()) || + !data.WriteInt32(changeNotification.GetDeleteEntries().size())) { + ZLOGE("write change size to parcel failed"); + return; + } + std::vector totalEntries; + totalEntries.insert(totalEntries.end(), changeNotification.GetInsertEntries().begin(), + changeNotification.GetInsertEntries().end()); + totalEntries.insert(totalEntries.end(), changeNotification.GetUpdateEntries().begin(), + changeNotification.GetUpdateEntries().end()); + totalEntries.insert(totalEntries.end(), changeNotification.GetDeleteEntries().begin(), + changeNotification.GetDeleteEntries().end()); + if (!ITypesUtil::MarshalToBuffer(totalEntries, totalSize, data)) { ZLOGE("WriteChangeList to Parcel by buffer failed"); return; } -- Gitee From 7ac69eccf2e0155181499888053742176994157c Mon Sep 17 00:00:00 2001 From: yangliu Date: Mon, 7 Apr 2025 20:21:07 +0800 Subject: [PATCH 2/4] update Signed-off-by: yangliu --- .../service/kvdb/kvdb_observer_proxy.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp index e2bdbae6a..62474db83 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp @@ -60,13 +60,16 @@ void KVDBObserverProxy::OnChange(const ChangeNotification &changeNotification) } } else { if (!ITypesUtil::Marshal(data, changeNotification.GetDeviceId(), uint32_t(changeNotification.IsClear()))) { - ZLOGE("write deviceId to parcel failed"); + ZLOGE("write deviceId to parcel failed, devId:%{public}s, clear:%{public}d", + changeNotification.GetDeviceId(), changeNotification.IsClear()); return; } if (!data.WriteInt32(changeNotification.GetInsertEntries().size()) || !data.WriteInt32(changeNotification.GetUpdateEntries().size()) || !data.WriteInt32(changeNotification.GetDeleteEntries().size())) { - ZLOGE("write change size to parcel failed"); + ZLOGE("write change size to parcel failed, insert:%{public}zu, update:%{public}zu, delete:%{public}zu", + changeNotification.GetInsertEntries().size(), changeNotification.GetUpdateEntries().size(), + changeNotification.GetDeleteEntries().size()); return; } std::vector totalEntries; -- Gitee From 6d55fdeb3f2cb571365d9ec5bed5be1dbe1679b4 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 8 Apr 2025 09:12:56 +0800 Subject: [PATCH 3/4] update Signed-off-by: yangliu --- .../service/kvdb/kvdb_observer_proxy.cpp | 31 +++++++++++++------ .../service/kvdb/kvdb_observer_proxy.h | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp index 62474db83..598d30e5d 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp @@ -36,6 +36,22 @@ KVDBObserverProxy::KVDBObserverProxy(const sptr &impl) : IRemoteP { } +int64_t KVDBObserverProxy::CalTotalSize(const ChangeNotification &changeNotification, MessageParcel &data) +{ + const int errorResult = -1; + int64_t insertSize = ITypesUtil::GetTotalSize(changeNotification.GetInsertEntries()); + int64_t updateSize = ITypesUtil::GetTotalSize(changeNotification.GetUpdateEntries()); + int64_t deleteSize = ITypesUtil::GetTotalSize(changeNotification.GetDeleteEntries()); + int64_t totalSize = insertSize + updateSize + deleteSize; + if (insertSize < 0 || updateSize < 0 || deleteSize < 0 || !data.WriteInt64(totalSize)) { + ZLOGE("Write ChangeNotification buffer size to parcel failed. I(%" PRId64 ") U(%" PRId64 ") D(%" PRId64 ")", + insertSize, updateSize, deleteSize); + return errorResult; + } + ZLOGD("I(%" PRId64 ") U(%" PRId64 ") D(%" PRId64 ") T(%" PRId64 ")", insertSize, updateSize, deleteSize, totalSize); + return totalSize; +} + void KVDBObserverProxy::OnChange(const ChangeNotification &changeNotification) { MessageParcel data; @@ -44,15 +60,10 @@ void KVDBObserverProxy::OnChange(const ChangeNotification &changeNotification) ZLOGE("Write descriptor failed"); return; } - int64_t insertSize = ITypesUtil::GetTotalSize(changeNotification.GetInsertEntries()); - int64_t updateSize = ITypesUtil::GetTotalSize(changeNotification.GetUpdateEntries()); - int64_t deleteSize = ITypesUtil::GetTotalSize(changeNotification.GetDeleteEntries()); - int64_t totalSize = insertSize + updateSize + deleteSize; - if (insertSize < 0 || updateSize < 0 || deleteSize < 0 || !data.WriteInt64(totalSize)) { - ZLOGE("Write ChangeNotification buffer size to parcel failed."); + int64_t totalSize = CalTotalSize(changeNotification, data); + if (totalSize == -1) { return; } - ZLOGD("I(%" PRId64 ") U(%" PRId64 ") D(%" PRId64 ") T(%" PRId64 ")", insertSize, updateSize, deleteSize, totalSize); if (totalSize < SWITCH_RAW_DATA_SIZE) { if (!ITypesUtil::Marshal(data, changeNotification)) { ZLOGW("Write ChangeNotification to parcel failed."); @@ -61,15 +72,15 @@ void KVDBObserverProxy::OnChange(const ChangeNotification &changeNotification) } else { if (!ITypesUtil::Marshal(data, changeNotification.GetDeviceId(), uint32_t(changeNotification.IsClear()))) { ZLOGE("write deviceId to parcel failed, devId:%{public}s, clear:%{public}d", - changeNotification.GetDeviceId(), changeNotification.IsClear()); + changeNotification.GetDeviceId().c_str(), changeNotification.IsClear()); return; } if (!data.WriteInt32(changeNotification.GetInsertEntries().size()) || !data.WriteInt32(changeNotification.GetUpdateEntries().size()) || !data.WriteInt32(changeNotification.GetDeleteEntries().size())) { ZLOGE("write change size to parcel failed, insert:%{public}zu, update:%{public}zu, delete:%{public}zu", - changeNotification.GetInsertEntries().size(), changeNotification.GetUpdateEntries().size(), - changeNotification.GetDeleteEntries().size()); + changeNotification.GetInsertEntries().size(), changeNotification.GetUpdateEntries().size(), + changeNotification.GetDeleteEntries().size()); return; } std::vector totalEntries; diff --git a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.h b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.h index 9a706fd26..35d619dbc 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.h +++ b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.h @@ -32,6 +32,7 @@ public: void OnChange(const DataOrigin &origin, Keys &&keys) override; private: static inline BrokerDelegator delegator_; + int64_t CalTotalSize(const ChangeNotification &changeNotification, MessageParcel &data); }; } // namespace DistributedKv } // namespace OHOS -- Gitee From 7359430938860ffdca1f258a0788a186ba31f78a Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 8 Apr 2025 15:47:18 +0800 Subject: [PATCH 4/4] update Signed-off-by: yangliu --- .../distributeddataservice/app/src/kvstore_meta_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp index 06b07a9c1..304048400 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp @@ -584,8 +584,8 @@ void KvStoreMetaManager::CheckMetaDeviceId() deviceMeta.oldUuid = deviceMeta.newUuid; deviceMeta.newUuid = localUuid; MetaDataManager::GetInstance().SaveMeta(deviceMeta.GetKey(), deviceMeta, true); - ZLOGI("meta changed! curruuid:%{public}s, olduuid:%{public}s", - deviceMeta.newUuid.c_str(), deviceMeta.oldUuid.c_str()); + ZLOGI("meta changed! curruuid:%{public}s, olduuid:%{public}s", Anonymous::Change(deviceMeta.newUuid).c_str(), + Anonymous::Change(deviceMeta.oldUuid).c_str()); } } -- Gitee