diff --git a/services/distributeddataservice/service/object/src/object_manager.cpp b/services/distributeddataservice/service/object/src/object_manager.cpp index 859de7085d019a26f19bc35140329b36d32a3760..7d9d732135acc8eb34a51f86495181a3e1854aa4 100644 --- a/services/distributeddataservice/service/object/src/object_manager.cpp +++ b/services/distributeddataservice/service/object/src/object_manager.cpp @@ -438,6 +438,11 @@ void ObjectStoreManager::NotifyChange(const ObjectRecord &changedData) for (const auto &[key, value] : changedData) { keys.emplace_back(key.begin(), key.end()); } + std::lock_guard lock(kvStoreMutex_); + if (delegate_ == nullptr) { + ZLOGE("delegate_ is nullptr"); + return Close(); + } status = delegate_->DeleteBatch(keys); if (status != DistributedDB::DBStatus::OK) { ZLOGE("Delete entries failed, bundleName:%{public}s, source device::%{public}s, status: %{public}d", @@ -836,6 +841,11 @@ void ObjectStoreManager::FlushClosedStore() void ObjectStoreManager::ProcessOldEntry(const std::string &appId) { std::vector entries; + std::lock_guard lock(kvStoreMutex_); + if (delegate_ == nullptr) { + ZLOGE("delegate_ is nullptr"); + return; + } auto status = delegate_->GetEntries(std::vector(appId.begin(), appId.end()), entries); if (status == DistributedDB::DBStatus::NOT_FOUND) { ZLOGI("Get old entries empty, bundleName: %{public}s", appId.c_str()); @@ -898,6 +908,11 @@ int32_t ObjectStoreManager::SaveToStore(const std::string &appId, const std::str entry.value = item.second; entries.emplace_back(entry); } + std::lock_guard lock(kvStoreMutex_); + if (delegate_ == nullptr) { + ZLOGE("delegate_ is nullptr"); + return OBJECT_DBSTATUS_ERROR; + } auto status = delegate_->PutBatch(entries); if (status != DistributedDB::DBStatus::OK) { ZLOGE("PutBatch failed, bundleName: %{public}s, sessionId: %{public}s, dstNetworkId: %{public}s, " @@ -934,6 +949,11 @@ int32_t ObjectStoreManager::SyncOnStore( DistributedDB::Query dbQuery = DistributedDB::Query::Select(); dbQuery.PrefixKey(std::vector(prefix.begin(), prefix.end())); ZLOGI("Start sync data, sequenceId: 0x%{public}" PRIx64 "", sequenceId); + std::lock_guard lock(kvStoreMutex_); + if (delegate_ == nullptr) { + ZLOGE("delegate_ is nullptr"); + return OBJECT_DBSTATUS_ERROR; + } auto status = delegate_->Sync(syncDevices, DistributedDB::SyncMode::SYNC_MODE_PUSH_ONLY, [this, sequenceId](const std::map &devicesMap) { ZLOGI("Sync data finished, sequenceId: 0x%{public}" PRIx64 "", sequenceId); @@ -964,6 +984,11 @@ int32_t ObjectStoreManager::SetSyncStatus(bool status) int32_t ObjectStoreManager::RevokeSaveToStore(const std::string &prefix) { std::vector entries; + std::lock_guard lock(kvStoreMutex_); + if (delegate_ == nullptr) { + ZLOGE("delegate_ is nullptr"); + return OBJECT_DBSTATUS_ERROR; + } auto status = delegate_->GetEntries(std::vector(prefix.begin(), prefix.end()), entries); if (status == DistributedDB::DBStatus::NOT_FOUND) { ZLOGI("Get entries empty, prefix: %{public}s", Anonymous::Change(prefix).c_str()); @@ -996,6 +1021,11 @@ int32_t ObjectStoreManager::RetrieveFromStore(const std::string &appId, const st { std::vector entries; std::string prefix = GetPrefixWithoutDeviceId(appId, sessionId); + std::lock_guard lock(kvStoreMutex_); + if (delegate_ == nullptr) { + ZLOGE("delegate_ is nullptr"); + return OBJECT_DBSTATUS_ERROR; + } auto status = delegate_->GetEntries(std::vector(prefix.begin(), prefix.end()), entries); if (status == DistributedDB::DBStatus::NOT_FOUND) { ZLOGI("Get entries empty, prefix: %{public}s, status: %{public}d", prefix.c_str(), status);