• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SyncParam {
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         bool isRetry = true;
47         QuerySyncObject syncQuery;
48         DeviceSyncProcessCallback onSyncProcess;
49     };
50 
~ISyncer()51     virtual ~ISyncer() {};
52 
53     // Init the Syncer modules
54     virtual int Initialize(ISyncInterface *syncInterface, bool isNeedActive) = 0;
55 
56     // Close
57     virtual int Close(bool isClosedOperation) = 0;
58 
59     // Sync function.
60     // param devices: The device id list.
61     // param mode: Sync mode, see SyncMode.
62     // param onComplete: The syncer finish callback. set by caller
63     // param onFinalize: will be callback when this Sync Operation finalized.
64     // return a Sync id. It will return a positive value if failed,
65     virtual int Sync(const std::vector<std::string> &devices, int mode,
66         const std::function<void(const std::map<std::string, int> &)> &onComplete,
67         const std::function<void(void)> &onFinalize, bool wait) = 0;
68 
69     // Sync function. use SyncParam to reduce parameter.
70     virtual int Sync(const SyncParam &param, uint64_t connectionId) = 0;
71 
72     // Cancel sync function.
73     virtual int CancelSync(uint32_t syncId) = 0;
74 
75     // Remove the operation, with the given syncId, used to clean resource if sync finished or failed.
76     virtual int RemoveSyncOperation(int syncId) = 0;
77 
78     virtual int StopSync(uint64_t connectionId) = 0;
79 
80     // Get The current virtual timestamp
81     virtual uint64_t GetTimestamp() = 0;
82 
83     // Enable auto sync function
84     virtual void EnableAutoSync(bool enable) = 0;
85 
86     // delete specified device's watermark
87     virtual int EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash) = 0;
88 
89     // delete specified device's and table's watermark
90     virtual int EraseDeviceWaterMark(const std::string &deviceId, bool isNeedHash,
91         const std::string &tableName) = 0;
92 
93     // Local data changed callback
94     virtual void LocalDataChanged(int notifyEvent) = 0;
95 
96     // Get manual sync queue size
97     virtual int GetQueuedSyncSize(int *queuedSyncSize) const = 0;
98 
99     // Set manual sync queue limit
100     virtual int SetQueuedSyncLimit(const int *queuedSyncLimit) = 0;
101 
102     // Get manual sync queue limit
103     virtual int GetQueuedSyncLimit(int *queuedSyncLimit) const = 0;
104 
105     // Disable add new manual sync, for rekey
106     virtual int DisableManualSync(void) = 0;
107 
108     // Enable add new manual sync, for rekey
109     virtual int EnableManualSync(void) = 0;
110 
111     // Get local deviceId, is hashed
112     virtual int GetLocalIdentity(std::string &outTarget) const = 0;
113 
114     // Set stale data wipe policy
115     virtual int SetStaleDataWipePolicy(WipePolicy policy) = 0;
116 
117     // Set Manual Sync retry config
118     virtual int SetSyncRetry(bool isRetry) = 0;
119 
120     // Set an equal identifier for this database, After this called, send msg to the target will use this identifier
121     virtual int SetEqualIdentifier(const std::string &identifier, const std::vector<std::string> &targets) = 0;
122 
123     virtual void Dump(int fd) = 0;
124 
125     virtual SyncerBasicInfo DumpSyncerBasicInfo() = 0;
126 
127     virtual int RemoteQuery(const std::string &device, const RemoteCondition &condition,
128         uint64_t timeout, uint64_t connectionId, std::shared_ptr<ResultSet> &result) = 0;
129 
130     virtual int GetSyncDataSize(const std::string &device, size_t &size) const = 0;
131 
132     virtual int GetHashDeviceId(const std::string &clientId, std::string &hashDevId) const = 0;
133 
134     virtual int GetWatermarkInfo(const std::string &device, WatermarkInfo &info) = 0;
135 
136     virtual int UpgradeSchemaVerInMeta() = 0;
137 
138     virtual void ResetSyncStatus() = 0;
139 
140     virtual int64_t GetLocalTimeOffset() = 0;
141 
142     virtual int32_t GetTaskCount() = 0;
143 
144     virtual bool ExchangeClosePending(bool expected) = 0;
145 };
146 } // namespace DistributedDB
147 
148 #endif  // I_SYNCER_H
149