From ed726289746c90b6ff35320783a4969dfd077f64 Mon Sep 17 00:00:00 2001 From: Hollokin Date: Sat, 22 Jun 2024 11:20:48 +0800 Subject: [PATCH] =?UTF-8?q?kv=E7=AB=AF=E4=BA=91=E5=90=8C=E6=AD=A5=E9=80=82?= =?UTF-8?q?=E9=85=8D=E9=AB=98=E6=96=AFmerge=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hollokin --- .../service/kvdb/kvdb_general_store.cpp | 18 ++++++++++++------ .../service/kvdb/kvdb_general_store.h | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp b/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp index 58e3e06f2..cb09c44b5 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_general_store.cpp @@ -320,14 +320,20 @@ KVDBGeneralStore::DBSyncCallback KVDBGeneralStore::GetDBSyncCompleteCB(DetailAsy }; } -DBStatus KVDBGeneralStore::CloudSync( - const Devices &devices, DistributedDB::SyncMode cloudSyncMode, DetailAsync async, int64_t wait) +DBStatus KVDBGeneralStore::CloudSync(const Devices &devices, int32_t mode, DetailAsync async, int64_t wait) { + auto syncMode = GeneralStore::GetSyncMode(static_cast(mode)); + if (syncMode < CLOUD_BEGIN || syncMode >= CLOUD_END) { + ZLOGE("Do not need to cloud sync! devices count:%{public}zu, the 1st:%{public}s, syncMode:%{public}d", + devices.size(), devices.empty() ? "null" : Anonymous::Change(*devices.begin()).c_str(), syncMode); + return DBStatus::DB_ERROR; + } DistributedDB::CloudSyncOption syncOption; syncOption.devices = devices; - syncOption.mode = cloudSyncMode; + syncOption.mode = DistributedDB::SyncMode(syncMode); syncOption.waitTime = wait; syncOption.lockAction = DistributedDB::LockAction::NONE; + syncOption.merge = GeneralStore::GetHighMode(static_cast(mode)) == HighMode::AUTO_SYNC_MODE; if (storeInfo_.user == 0) { std::vector users; AccountDelegate::GetInstance()->QueryUsers(users); @@ -340,7 +346,6 @@ DBStatus KVDBGeneralStore::CloudSync( int32_t KVDBGeneralStore::Sync(const Devices &devices, GenQuery &query, DetailAsync async, SyncParam &syncParm) { - auto syncMode = GeneralStore::GetSyncMode(syncParm.mode); std::shared_lock lock(rwMutex_); if (delegate_ == nullptr) { ZLOGE("store already closed! devices count:%{public}zu, the 1st:%{public}s, mode:%{public}d", devices.size(), @@ -348,12 +353,12 @@ int32_t KVDBGeneralStore::Sync(const Devices &devices, GenQuery &query, DetailAs return GeneralError::E_ALREADY_CLOSED; } DBStatus dbStatus; - auto dbMode = DistributedDB::SyncMode(syncMode); + auto syncMode = GeneralStore::GetSyncMode(syncParm.mode); if (syncMode > NEARBY_END && syncMode < CLOUD_END) { if (!enableCloud_) { return GeneralError::E_NOT_SUPPORT; } - dbStatus = CloudSync(devices, dbMode, async, syncParm.wait); + dbStatus = CloudSync(devices, syncParm.mode, async, syncParm.wait); } else { if (devices.empty()) { ZLOGE("Devices is empty! mode:%{public}d", syncParm.mode); @@ -373,6 +378,7 @@ int32_t KVDBGeneralStore::Sync(const Devices &devices, GenQuery &query, DetailAs dbStatus = delegate_->UnSubscribeRemoteQuery(devices, GetDBSyncCompleteCB(std::move(async)), dbQuery, false); } else if (syncMode < NEARBY_END) { + auto dbMode = DistributedDB::SyncMode(syncMode); if (kvQuery->IsEmpty()) { dbStatus = delegate_->Sync(devices, dbMode, GetDBSyncCompleteCB(std::move(async)), false); } else { diff --git a/services/distributeddataservice/service/kvdb/kvdb_general_store.h b/services/distributeddataservice/service/kvdb/kvdb_general_store.h index 81a78627e..b9ad8360c 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_general_store.h +++ b/services/distributeddataservice/service/kvdb/kvdb_general_store.h @@ -91,7 +91,7 @@ private: std::vector GetNewKey(std::vector &key, const std::string &uuid); DBSyncCallback GetDBSyncCompleteCB(DetailAsync async); DBProcessCB GetDBProcessCB(DetailAsync async); - DBStatus CloudSync(const Devices &devices, DistributedDB::SyncMode cloudSyncMode, DetailAsync async, int64_t wait); + DBStatus CloudSync(const Devices &devices, int32_t mode, DetailAsync async, int64_t wait); void InitWaterVersion(const StoreMetaData &meta); void GetIdentifierParams(std::vector &devices, const std::vector &uuids, int32_t authType); -- Gitee