diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp index 06b07a9c13d315fac66ba9deddd407564016d629..304048400b9b514950dff97ca1dd3a33f37ff93e 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()); } } diff --git a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.cpp index 3eb5413ef7a34faf0fed0d8d53f6ca6723bd4b87..598d30e5dc6ba39b31dd0ac4d98c7f3263d0ce4c 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,25 +60,37 @@ 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 + sizeof(uint32_t); - if (insertSize < 0 || updateSize < 0 || deleteSize < 0 || !data.WriteInt32(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."); 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, devId:%{public}s, clear:%{public}d", + 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()); + 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; } diff --git a/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.h b/services/distributeddataservice/service/kvdb/kvdb_observer_proxy.h index 9a706fd260c99091ef1d8e401517c00b4f68e1cf..35d619dbc7c9071a3c490111f4202bb6e95892b1 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