From 364d82858797215f971d94791f9252f5d10d4e8a Mon Sep 17 00:00:00 2001 From: Gymee Date: Mon, 27 Dec 2021 13:12:26 +0800 Subject: [PATCH] add delay when retry sync Signed-off-by: Gymee Change-Id: I94a5dd101edfd857ccd91e86fd36d4ac60726bff --- services/core/include/dbstorage/sync_coordinator.h | 2 +- services/core/src/dbstorage/online_sync_table.cpp | 8 +++++--- services/core/src/dbstorage/sync_coordinator.cpp | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/services/core/include/dbstorage/sync_coordinator.h b/services/core/include/dbstorage/sync_coordinator.h index d82bc0d2..a0213c13 100755 --- a/services/core/include/dbstorage/sync_coordinator.h +++ b/services/core/include/dbstorage/sync_coordinator.h @@ -35,7 +35,7 @@ public: void ReleaseSync(); void SetSyncTrigger(bool isOnlineTrigger); bool IsOnlineSync(); - bool DispatchSyncTask(const SyncTask& syncTask); + bool DispatchSyncTask(const SyncTask& syncTask, int64_t delayTime = 0); private: std::atomic isOnlineTrigger_ {false}; diff --git a/services/core/src/dbstorage/online_sync_table.cpp b/services/core/src/dbstorage/online_sync_table.cpp index aaaf63b0..1592c9a6 100755 --- a/services/core/src/dbstorage/online_sync_table.cpp +++ b/services/core/src/dbstorage/online_sync_table.cpp @@ -30,7 +30,8 @@ const std::string TAG = "OnlineSyncTable"; const std::string APP_ID = "distributed_device_profile_service"; const std::string STORE_ID = "online_sync_storage"; -constexpr int32_t MAX_RETRY_SYNC_TIMES = 10; +constexpr int32_t MAX_RETRY_SYNC_TIMES = 30; +constexpr int32_t INTERVAL_RETRY_SYNC_MS = 100; } OnlineSyncTable::OnlineSyncTable() : DeviceProfileStorage(APP_ID, STORE_ID) @@ -122,9 +123,10 @@ void OnlineSyncTable::SyncCompleted(const std::map& results if ((retrySyncTimes_++ < MAX_RETRY_SYNC_TIMES) && !failedDeviceIds.empty()) { auto retrySyncTask = [this, deviceIds = std::move(failedDeviceIds)]() { HILOGI("retrying sync..."); - SyncDeviceProfile(deviceIds, SyncMode::PUSH); + DeviceProfileStorage::SyncDeviceProfile(deviceIds, SyncMode::PUSH); }; - if (!SyncCoordinator::GetInstance().DispatchSyncTask(retrySyncTask)) { + if (!SyncCoordinator::GetInstance().DispatchSyncTask(retrySyncTask, + INTERVAL_RETRY_SYNC_MS)) { HILOGE("post online sync retry task failed"); return; } diff --git a/services/core/src/dbstorage/sync_coordinator.cpp b/services/core/src/dbstorage/sync_coordinator.cpp index a51dcd74..129c3aeb 100755 --- a/services/core/src/dbstorage/sync_coordinator.cpp +++ b/services/core/src/dbstorage/sync_coordinator.cpp @@ -62,9 +62,9 @@ bool SyncCoordinator::IsOnlineSync() return isOnlineTrigger_; } -bool SyncCoordinator::DispatchSyncTask(const SyncTask& syncTask) +bool SyncCoordinator::DispatchSyncTask(const SyncTask& syncTask, int64_t delayTime) { - if (!syncHandler_->PostTask(syncTask)) { + if (!syncHandler_->PostTask(syncTask, delayTime)) { HILOGE("post task failed"); isOnSync_ = false; return false; -- Gitee