1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef KV_SYNCER_H 17 #define KV_SYNCER_H 18 19 #include "single_ver_syncer.h" 20 21 namespace DistributedDB { 22 class SingleVerKVSyncer final : public SingleVerSyncer { 23 public: 24 SingleVerKVSyncer(); 25 ~SingleVerKVSyncer() override; 26 27 // Enable auto sync function 28 void EnableAutoSync(bool enable) override; 29 30 // Local data changed callback 31 void LocalDataChanged(int notifyEvent) override; 32 33 // Remote data changed callback 34 void RemoteDataChanged(const std::string &device) override; 35 36 void QueryAutoSync(const InternalSyncParma ¶m) override; 37 38 void TriggerSubscribe(const std::string &device, const QuerySyncObject &query); 39 40 SyncerBasicInfo DumpSyncerBasicInfo() override; 41 42 protected: 43 int SyncConditionCheck(QuerySyncObject &query, int mode, bool isQuerySync, 44 const std::vector<std::string> &devices) const override; 45 46 private: 47 // if trigger full sync, no need to trigger query sync again 48 bool TryFullSync(const std::vector<std::string> &devices); 49 void TriggerSubQuerySync(const std::vector<std::string> &devices); 50 bool autoSyncEnable_; 51 std::atomic<bool> triggerSyncTask_; 52 }; 53 } // namespace DistributedDB 54 55 #endif // KV_SYNCER_H 56