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