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_force_push_strategy.h"
16 #include "cloud/cloud_storage_utils.h"
17
18 namespace DistributedDB {
19 const std::string cloud_device_name = "cloud";
TagSyncDataStatus(bool existInLocal,bool isCloudWin,const LogInfo & localInfo,const LogInfo & cloudInfo)20 OpType CloudForcePushStrategy::TagSyncDataStatus(bool existInLocal, bool isCloudWin, const LogInfo &localInfo,
21 const LogInfo &cloudInfo)
22 {
23 if (CloudStorageUtils::IsDataLocked(localInfo.status)) {
24 return OpType::LOCKED_NOT_HANDLE;
25 }
26 bool isCloudDelete = IsDelete(cloudInfo);
27 if (!existInLocal) {
28 return OpType::NOT_HANDLE;
29 }
30
31 if (localInfo.cloudGid.empty()) {
32 // when cloud or local data is deleted, we think it is different data
33 bool isLocalDelete = IsDelete(localInfo);
34 return isCloudDelete || isLocalDelete ? OpType::NOT_HANDLE : OpType::ONLY_UPDATE_GID;
35 }
36
37 if (isCloudDelete) {
38 return OpType::CLEAR_GID;
39 }
40 if (localInfo.device == cloud_device_name) {
41 if (localInfo.timestamp == cloudInfo.timestamp) {
42 return OpType::SET_CLOUD_FORCE_PUSH_FLAG_ONE;
43 } else {
44 return OpType::SET_CLOUD_FORCE_PUSH_FLAG_ZERO;
45 }
46 }
47 if (IsLogNeedUpdate(cloudInfo, localInfo)) {
48 return OpType::ONLY_UPDATE_GID;
49 }
50 return OpType::NOT_HANDLE;
51 }
52
JudgeUpdateCursor()53 bool CloudForcePushStrategy::JudgeUpdateCursor()
54 {
55 return false;
56 }
57
JudgeUpload()58 bool CloudForcePushStrategy::JudgeUpload()
59 {
60 return true;
61 }
62 }