1 2 /* 3 * Copyright (c) 2021 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef I_SYNCER_H 18 #define I_SYNCER_H 19 20 #include <functional> 21 #include <map> 22 #include <memory> 23 #include <mutex> 24 25 #include "distributeddb/result_set.h" 26 #include "isync_interface.h" 27 #include "types_export.h" 28 #include "query_sync_object.h" 29 #include "store_types.h" 30 31 namespace DistributedDB { 32 struct SyncerBasicInfo { 33 bool isSyncActive = false; 34 bool isAutoSync = false; 35 }; 36 class ISyncer { 37 public: 38 struct SyncParma { 39 std::vector<std::string> devices; 40 std::function<void(const std::map<std::string, int> &devicesMap)> onComplete; 41 SyncStatusCallback relationOnComplete; 42 std::function<void(void)> onFinalize; 43 int mode = 0; 44 bool wait = false; 45 bool isQuerySync = false; 46 QuerySyncObject syncQuery; 47 DeviceSyncProcessCallback onSyncProcess; 48 }; 49 ~ISyncer()50 virtual ~ISyncer() {}; 51 52 // Init the Syncer modules 53 virtual int Initialize(ISyncInterface *syncInterface, bool isNeedActive) = 0; 54 55 // Close 56 virtual int Close(bool isClosedOperation) = 0; 57 58 // Sync function. 59 // param devices: The device id list. 60 // param mode: Sync mode, see SyncMode. 61 // param onComplete: The syncer finish callback. set by caller 62 // param onFinalize: will be callback when this Sync Operation finalized. 63 // return a Sync id. It will return a positive value if failed, 64 virtual int Sync(const std::vector<std::string> &devices, int mode, 65 const std::function<void(const std::map<std::string, int> &)> &onComplete, 66 const std::function<void(void)> &onFinalize, bool wait) = 0; 67 68 // Sync function. use SyncParma to reduce parameter. 69 virtual int Sync(const SyncParma ¶m, uint64_t connectionId) = 0; 70 71 // Cancel sync function. 72 virtual int CancelSync(uint32_t syncId) = 0; 73 74 // Remove the operation, with the given syncId, used to clean resource if sync finished or failed. 75 virtual int RemoveSyncOperation(int syncId) = 0; 76 77 virtual int StopSync(uint64_t connectionId) = 0; 78 79 // Get The current virtual timestamp 80 virtual uint64_t GetTimestamp() = 0; 81 82 // Enable auto sync function 83 virtual void EnableAutoSync(bool enable) = 0; 84 85 // delete specified device's watermark 86 virtual int EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash) = 0; 87 88 // delete specified device's and table's watermark 89 virtual int EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash, 90 const std::string &tableName) = 0; 91 92 // Local data changed callback 93 virtual void LocalDataChanged(int notifyEvent) = 0; 94 95 // Get manual sync queue size 96 virtual int GetQueuedSyncSize(int *queuedSyncSize) const = 0; 97 98 // Set manual sync queue limit 99 virtual int SetQueuedSyncLimit(const int *queuedSyncLimit) = 0; 100 101 // Get manual sync queue limit 102 virtual int GetQueuedSyncLimit(int *queuedSyncLimit) const = 0; 103 104 // Disable add new manual sync, for rekey 105 virtual int DisableManualSync(void) = 0; 106 107 // Enable add new manual sync, for rekey 108 virtual int EnableManualSync(void) = 0; 109 110 // Get local deviceId, is hashed 111 virtual int GetLocalIdentity(std::string &outTarget) const = 0; 112 113 // Set stale data wipe policy 114 virtual int SetStaleDataWipePolicy(WipePolicy policy) = 0; 115 116 // Set Manual Sync retry config 117 virtual int SetSyncRetry(bool isRetry) = 0; 118 119 // Set an equal identifier for this database, After this called, send msg to the target will use this identifier 120 virtual int SetEqualIdentifier(const std::string &identifier, const std::vector<std::string> &targets) = 0; 121 122 virtual void Dump(int fd) = 0; 123 124 virtual SyncerBasicInfo DumpSyncerBasicInfo() = 0; 125 126 virtual int RemoteQuery(const std::string &device, const RemoteCondition &condition, 127 uint64_t timeout, uint64_t connectionId, std::shared_ptr<ResultSet> &result) = 0; 128 129 virtual int GetSyncDataSize(const std::string &device, size_t &size) const = 0; 130 131 virtual int GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const = 0; 132 133 virtual int GetWatermarkInfo(const std::string &device, WatermarkInfo &info) = 0; 134 135 virtual int UpgradeSchemaVerInMeta() = 0; 136 137 virtual void ResetSyncStatus() = 0; 138 139 virtual int64_t GetLocalTimeOffset() = 0; 140 141 virtual int32_t GetTaskCount() = 0; 142 }; 143 } // namespace DistributedDB 144 145 #endif // I_SYNCER_H 146