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 SINGLE_VER_SYNC_ENGINE_H 17 #define SINGLE_VER_SYNC_ENGINE_H 18 19 #include "sync_engine.h" 20 21 namespace DistributedDB { 22 class SingleVerSyncEngine final : public SyncEngine { 23 public: SingleVerSyncEngine()24 SingleVerSyncEngine() : needClearRemoteStaleData_(false) {}; 25 26 // If set true, remote stale data will be clear when remote db rebuilt. 27 void EnableClearRemoteStaleData(bool enable); 28 29 // used by SingleVerKVSyncer when db online 30 int StartAutoSubscribeTimer(const ISyncInterface &syncInterface) override; 31 32 // used by SingleVerKVSyncer when remote/local db closed 33 void StopAutoSubscribeTimer() override; 34 35 int SubscribeTimeOut(TimerId id); 36 37 DISABLE_COPY_ASSIGN_MOVE(SingleVerSyncEngine); 38 protected: ~SingleVerSyncEngine()39 ~SingleVerSyncEngine() override {}; 40 41 // Create a context 42 ISyncTaskContext *CreateSyncTaskContext(const ISyncInterface &syncInterface) override; 43 44 private: 45 DECLARE_OBJECT_TAG(SingleVerSyncEngine); 46 #ifndef RUNNING_ON_TESTCASE 47 static constexpr int SUBSCRIBE_TRIGGER_TIME_OUT = 30 * 60 * 1000; // 30min 48 #else 49 static constexpr int SUBSCRIBE_TRIGGER_TIME_OUT = 5 * 60 * 1000; // 5min for test 50 #endif 51 52 bool needClearRemoteStaleData_; 53 54 // for subscribe timeout callback 55 std::mutex timerLock_; 56 TimerId subscribeTimerId_ = 0; 57 }; 58 } // namespace DistributedDB 59 60 #endif // SINGLE_VER_SYNC_ENGINE_H