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 #include "cloud/cloud_merge_strategy.h"
16
17 namespace DistributedDB {
18
TagSyncDataStatus(bool existInLocal,LogInfo & localInfo,LogInfo & cloudInfo,std::set<Key> & deletePrimaryKeySet)19 OpType CloudMergeStrategy::TagSyncDataStatus(bool existInLocal, LogInfo &localInfo, LogInfo &cloudInfo,
20 std::set<Key> &deletePrimaryKeySet)
21 {
22 bool isCloudDelete = IsDelete(cloudInfo);
23 bool isLocalDelete = IsDelete(localInfo);
24 if (!existInLocal) {
25 // when cloud data is deleted, we think it is different data
26 if (isCloudDelete) {
27 return OpType::NOT_HANDLE;
28 }
29 return OpType::INSERT;
30 }
31 OpType type = OpType::NOT_HANDLE;
32 if (localInfo.timestamp > cloudInfo.timestamp) {
33 if (localInfo.cloudGid.empty()) {
34 type = isCloudDelete ? OpType::NOT_HANDLE : OpType::ONLY_UPDATE_GID;
35 } else {
36 type = isCloudDelete ? OpType::CLEAR_GID : type;
37 }
38 return type;
39 }
40 if (isCloudDelete) {
41 if (isLocalDelete) {
42 return OpType::UPDATE_TIMESTAMP;
43 } else {
44 (void)deletePrimaryKeySet.insert(localInfo.hashKey);
45 return OpType::DELETE;
46 }
47 } else {
48 if (isLocalDelete || deletePrimaryKeySet.find(localInfo.hashKey) != deletePrimaryKeySet.end()) {
49 type = OpType::INSERT;
50 } else {
51 type = OpType::UPDATE;
52 }
53 }
54 return type;
55 }
56
JudgeUpdateCursor()57 bool CloudMergeStrategy::JudgeUpdateCursor()
58 {
59 return true;
60 }
61
JudgeUpload()62 bool CloudMergeStrategy::JudgeUpload()
63 {
64 return true;
65 }
66 }