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 #ifndef RELATIONAL_SYNCER_H 16 #define RELATIONAL_SYNCER_H 17 #ifdef RELATIONAL_STORE 18 #include "single_ver_syncer.h" 19 namespace DistributedDB { 20 class SingleVerRelationalSyncer final : public SingleVerSyncer { 21 public: 22 SingleVerRelationalSyncer() = default; 23 ~SingleVerRelationalSyncer() override = default; 24 25 int Initialize(ISyncInterface *syncInterface, bool isNeedActive) override; 26 27 // Sync function. use SyncParma to reduce parameter. 28 int Sync(const SyncParma ¶m, uint64_t connectionId) override; 29 30 void EnableAutoSync(bool enable) override; 31 32 void LocalDataChanged(int notifyEvent) override; 33 34 protected: 35 36 int PrepareSync(const SyncParma ¶m, uint32_t syncId, uint64_t connectionId) override; 37 38 int SyncConditionCheck(QuerySyncObject &query, int mode, bool isQuerySync, 39 const std::vector<std::string> &devices) const override; 40 41 private: 42 43 int GenerateEachSyncTask(const SyncParma ¶m, uint32_t syncId, 44 const std::vector<QuerySyncObject> &tablesQuery, uint64_t connectionId, std::set<uint32_t> &subSyncIdSet); 45 46 void DoRollBack(std::set<uint32_t> &subSyncIdSet); 47 48 void DoOnComplete(const SyncParma ¶m, uint32_t syncId); 49 void DoOnSubSyncComplete(const uint32_t subSyncId, const uint32_t syncId, 50 const SyncParma ¶m, const std::map<std::string, int> &devicesMap); 51 52 void SchemaChangeCallback(); 53 54 mutable std::mutex syncMapLock_; 55 std::map<uint32_t, std::set<uint32_t>> fullSyncIdMap_; 56 std::map<uint32_t, std::map<std::string, std::map<std::string, int>>> resMap_; 57 }; 58 } 59 #endif 60 #endif // RELATIONAL_SYNCER_H