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 SyncParam to reduce parameter. 28 int Sync(const SyncParam ¶m, uint64_t connectionId) override; 29 30 void EnableAutoSync(bool enable) override; 31 32 void LocalDataChanged(int notifyEvent) override; 33 34 int32_t GetTaskCount() override; 35 protected: 36 37 int PrepareSync(const SyncParam ¶m, uint32_t syncId, uint64_t connectionId) override; 38 39 int SyncConditionCheck(const SyncParam ¶m, const ISyncEngine *engine, ISyncInterface *storage) const override; 40 41 private: 42 43 int GenerateEachSyncTask(const SyncParam ¶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 SyncParam ¶m, uint32_t syncId); 49 void DoOnSubSyncComplete(const uint32_t subSyncId, const uint32_t syncId, 50 const SyncParam ¶m, const std::map<std::string, int> &devicesMap); 51 52 void SchemaChangeCallback(); 53 54 int QuerySyncPreCheck(const SyncParam ¶m) const; 55 56 static std::vector<QuerySyncObject> GetQuerySyncObject(const SyncParam ¶m); 57 58 mutable std::mutex syncMapLock_; 59 std::map<uint32_t, std::set<uint32_t>> fullSyncIdMap_; 60 std::map<uint32_t, std::map<std::string, std::vector<TableStatus>>> resMap_; 61 }; 62 } 63 #endif 64 #endif // RELATIONAL_SYNCER_H