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 #ifndef I_CLOUD_SYNCER_H 16 #define I_CLOUD_SYNCER_H 17 #include <cstdint> 18 #include <string> 19 #include "cloud/cloud_store_types.h" 20 #include "icloud_sync_storage_interface.h" 21 #include "query_sync_object.h" 22 #include "ref_object.h" 23 namespace DistributedDB { 24 using DownloadAssetUnit = std::tuple<std::string, Type, OpType, std::map<std::string, Assets>, Key, 25 std::vector<Type>, Timestamp>; 26 using DownloadList = std::vector<DownloadAssetUnit>; 27 class ICloudSyncer : public virtual RefObject { 28 public: 29 using TaskId = uint64_t; 30 struct CloudTaskInfo { 31 bool priorityTask = false; 32 int32_t priorityLevel = 0; 33 bool compensatedTask = false; 34 bool isAssetsOnly = false; 35 bool pause = false; 36 bool resume = false; 37 bool merge = false; 38 bool asyncDownloadAssets = false; 39 int errCode = 0; 40 SyncMode mode = SyncMode::SYNC_MODE_PUSH_ONLY; 41 ProcessStatus status = ProcessStatus::PREPARED; 42 LockAction lockAction = LockAction::INSERT; 43 TaskId taskId = 0u; 44 int64_t timeout = 0; 45 SyncProcessCallback callback; 46 std::vector<std::string> table; 47 std::vector<std::string> devices; 48 std::vector<QuerySyncObject> queryList; 49 std::vector<std::string> users; 50 std::string storeId; 51 std::string prepareTraceId; 52 uint32_t groupNum = 0; 53 AssetsGroupMap assetsGroupMap; 54 }; 55 56 struct UploadRetryInfo { 57 uint32_t uploadBatchRetryCount = 0; 58 uint32_t downloadBatchOpCount = 0; 59 }; 60 61 struct InnerProcessInfo { 62 std::string tableName; 63 ProcessStatus tableStatus = ProcessStatus::PREPARED; 64 Info downLoadInfo; 65 Info upLoadInfo; 66 UploadRetryInfo retryInfo; 67 bool isAsyncDownload = false; 68 }; 69 70 struct WithoutRowIdData { 71 std::vector<size_t> insertData = {}; 72 std::vector<std::tuple<size_t, size_t>> updateData = {}; 73 std::vector<std::tuple<size_t, size_t>> assetInsertData = {}; 74 }; 75 76 struct SyncParam { 77 DownloadData downloadData; 78 ChangedData changedData; 79 InnerProcessInfo info; 80 DownloadList assetsDownloadList; 81 std::string cloudWaterMark; 82 std::vector<std::string> pkColNames; 83 std::set<Key> deletePrimaryKeySet; 84 std::set<Key> dupHashKeySet; 85 std::string tableName; 86 bool isSinglePrimaryKey = false; 87 bool isLastBatch = false; 88 WithoutRowIdData withoutRowIdData; 89 std::vector<std::vector<Type>> insertPk; 90 bool isAssetsOnly = false; 91 bool isVaildForAssetsOnly = false; 92 uint32_t groupNum = 0; 93 AssetsGroupMap assetsGroupMap; 94 std::string cloudWaterMarkForAssetsOnly; 95 std::map<std::string, AssetsMap> gidAssetsMap; // only used for assets only. 96 bool isForcePullAseets = false; 97 }; 98 99 struct DataInfo { 100 DataInfoWithLog localInfo; 101 LogInfo cloudLogInfo; 102 }; 103 104 virtual std::string GetIdentify() const = 0; 105 106 virtual bool IsClosed() const = 0; 107 }; 108 } 109 #endif // I_CLOUD_SYNCER_H 110