diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp index 4341d38e9039955c071f0f430f1d40487a19b16e..668f65a0a553f0863d08f938a7a61be0228e12b0 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.cpp +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.cpp @@ -661,25 +661,32 @@ int32_t UdmfServiceImpl::StoreSync(const UnifiedKey &key, const QueryOption &que syncInfo.businessUdKey = query.key; std::lock_guard lock(mutex_); asyncProcessInfoMap_.insert_or_assign(syncInfo.businessUdKey, syncInfo); - ZLOGD("store.Sync: name=%{public}s, id=%{public}u, status=%{public}u, total=%{public}u, finish=%{public}u", - syncInfo.srcDevName.c_str(), syncInfo.syncId, syncInfo.syncStatus, - syncInfo.syncTotal, syncInfo.syncFinished); }; RadarReporterAdapter::ReportNormal(std::string(__FUNCTION__), BizScene::SYNC_DATA, SyncDataStage::SYNC_BEGIN, StageRes::SUCCESS); - int32_t id = AccountDelegate::GetInstance()->GetUserByToken(IPCSkeleton::GetCallingFullTokenID()); - StoreMetaData meta = StoreMetaData(std::to_string(id), Bootstrap::GetInstance().GetProcessLabel(), key.intention); + int userId = 0; + if (!AccountDelegate::GetInstance()->QueryForegroundUserId(userId)) { + ZLOGE("QueryForegroundUserId failed"); + return E_ERROR; + } + auto meta = BuildMeta(key.intention, userId); auto uuids = DmAdapter::GetInstance().ToUUID(devices); - if (IsNeedMetaSync(meta, uuids) && !MetaDataManager::GetInstance().Sync(uuids, - [devices, callback, store] (auto &results) { - if (store->Sync(devices, callback) != E_OK) { + if (IsNeedMetaSync(meta, uuids)) { + bool res = MetaDataManager::GetInstance().Sync(uuids, [this, devices, callback, store] (auto &results) { + auto successRes = ProcessResult(results); + if (store->Sync(successRes, callback) != E_OK) { ZLOGE("Store sync failed"); RadarReporterAdapter::ReportFail(std::string(__FUNCTION__), BizScene::SYNC_DATA, SyncDataStage::SYNC_END, StageRes::FAILED, E_DB_ERROR, BizState::DFX_END); + } + }); + if (!res) { + ZLOGE("Meta sync failed"); + RadarReporterAdapter::ReportFail(std::string(__FUNCTION__), + BizScene::SYNC_DATA, SyncDataStage::SYNC_END, StageRes::FAILED, E_DB_ERROR, BizState::DFX_END); + return E_DB_ERROR; } - })) { - ZLOGE("bundleName:%{public}s, meta sync failed", key.bundleName.c_str()); - return E_DB_ERROR; + return E_OK; } if (store->Sync(devices, callback) != E_OK) { ZLOGE("Store sync failed"); @@ -700,7 +707,7 @@ bool UdmfServiceImpl::IsNeedMetaSync(const StoreMetaData &meta, const std::vecto CapMetaData capMeta; auto capKey = CapMetaRow::GetKeyFor(uuid); if (!MetaDataManager::GetInstance().LoadMeta(std::string(capKey.begin(), capKey.end()), capMeta) || - !MetaDataManager::GetInstance().LoadMeta(metaData.GetKey(), metaData)) { + !MetaDataManager::GetInstance().LoadMeta(metaData.GetKeyWithoutPath(), metaData)) { isAfterMeta = true; break; } @@ -1294,5 +1301,27 @@ void UdmfServiceImpl::HandleDbError(const std::string &intention, int32_t &statu status = E_DB_ERROR; } } + +StoreMetaData UdmfServiceImpl::BuildMeta(const std::string &storeId, int userId) +{ + StoreMetaData meta; + meta.user = std::to_string(userId); + meta.storeId = storeId; + meta.bundleName = Bootstrap::GetInstance().GetProcessLabel(); + return meta; +} + +std::vector UdmfServiceImpl::ProcessResult(const std::map &results) +{ + std::vector devices; + for (const auto &[uuid, status] : results) { + if (static_cast(status) == DistributedDB::DBStatus::OK) { + DeviceMatrix::GetInstance().OnExchanged(uuid, DeviceMatrix::META_STORE_MASK); + devices.emplace_back(uuid); + } + } + ZLOGI("Meta sync finish, total size:%{public}zu, success size:%{public}zu", results.size(), devices.size()); + return devices; +} } // namespace UDMF } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/service/udmf/udmf_service_impl.h b/services/distributeddataservice/service/udmf/udmf_service_impl.h index b64267e29d1425849b57c4ff9638b3aecb2ffbb3..0dafbfd52a5e450643ae8616e9563b4e68f3a95e 100644 --- a/services/distributeddataservice/service/udmf/udmf_service_impl.h +++ b/services/distributeddataservice/service/udmf/udmf_service_impl.h @@ -89,6 +89,9 @@ private: const std::string &key); int32_t VerifyDataAccessPermission(std::shared_ptr runtime, const QueryOption &query, const UnifiedData &unifiedData); + std::vector ProcessResult(const std::map &results); + DistributedData::StoreMetaData BuildMeta(const std::string &storeId, int userId); + class Factory { public: Factory();