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(const SyncParma ¶m, const ISyncEngine *engine, ISyncInterface *storage) const override; 39 40 private: 41 42 int GenerateEachSyncTask(const SyncParma ¶m, uint32_t syncId, 43 const std::vector<QuerySyncObject> &tablesQuery, uint64_t connectionId, std::set<uint32_t> &subSyncIdSet); 44 45 void DoRollBack(std::set<uint32_t> &subSyncIdSet); 46 47 void DoOnComplete(const SyncParma ¶m, uint32_t syncId); 48 void DoOnSubSyncComplete(const uint32_t subSyncId, const uint32_t syncId, 49 const SyncParma ¶m, const std::map<std::string, int> &devicesMap); 50 51 void SchemaChangeCallback(); 52 53 int QuerySyncPreCheck(const SyncParma ¶m) const; 54 55 mutable std::mutex syncMapLock_; 56 std::map<uint32_t, std::set<uint32_t>> fullSyncIdMap_; 57 std::map<uint32_t, std::map<std::string, std::map<std::string, int>>> resMap_; 58 }; 59 } 60 #endif 61 #endif // RELATIONAL_SYNCER_H