• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 CLOUD_SYNC_STRATEGY_H
17 #define CLOUD_SYNC_STRATEGY_H
18 
19 #include "data_transformer.h"
20 #include "db_errno.h"
21 #include "db_types.h"
22 #include "icloud_sync_storage_interface.h"
23 
24 namespace DistributedDB {
25 class CloudSyncStrategy {
26 public:
27     CloudSyncStrategy();
28     virtual ~CloudSyncStrategy() = default;
29 
30     void SetConflictResolvePolicy(SingleVerConflictResolvePolicy policy);
31 
32     virtual OpType TagSyncDataStatus(bool existInLocal, bool isCloudWin, const LogInfo &localInfo,
33         const LogInfo &cloudInfo);
34 
35     virtual bool JudgeUpdateCursor();
36 
37     virtual bool JudgeUpload();
38 
39     static bool IsDelete(const LogInfo &info);
40 
41     static bool IsLogNeedUpdate(const LogInfo &cloudInfo, const LogInfo &localInfo);
42 
43     OpType TagUpdateLocal(const LogInfo &cloudInfo, const LogInfo &localInfo) const;
44 protected:
45     static bool IsSameVersion(const LogInfo &cloudInfo, const LogInfo &localInfo);
46 
47     bool IsIgnoreUpdate(const LogInfo &localInfo) const;
48 
49     bool IsSameRecord(const LogInfo &cloudInfo, const LogInfo &localInfo);
50 
51     SingleVerConflictResolvePolicy policy_;
52 };
53 }
54 #endif // CLOUD_SYNC_STRATEGY_H
55