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 ASSET_OPERATION_UTILS_H 17 #define ASSET_OPERATION_UTILS_H 18 #include "cloud/cloud_store_types.h" 19 20 namespace DistributedDB { 21 class AssetOperationUtils { 22 public: 23 enum class AssetOpType { 24 HANDLE, 25 NOT_HANDLE, 26 }; 27 enum class CloudSyncAction : uint16_t { 28 START_DOWNLOAD = 0, 29 START_UPLOAD, 30 END_DOWNLOAD, 31 END_UPLOAD, 32 DEFAULT_ACTION 33 }; 34 using RecordAssetOpType = std::map<std::string, std::map<std::string, AssetOperationUtils::AssetOpType>>; 35 static RecordAssetOpType CalAssetOperation(const VBucket &cacheAssets, const VBucket &dbAssets, 36 const CloudSyncAction &action); 37 static AssetOperationUtils::AssetOpType CalAssetOperation(const std::string &colName, const Asset &cacheAsset, 38 const VBucket &dbAssets, const CloudSyncAction &action); 39 static uint32_t EraseBitMask(uint32_t status); 40 static void UpdateAssetsFlag(std::vector<VBucket> &from, std::vector<VBucket> &target); 41 static void FilterDeleteAsset(VBucket &record); 42 private: 43 static void Init(); 44 static AssetOperationUtils::AssetOpType DefaultOperation(const Asset &, const Assets &); 45 static AssetOperationUtils::AssetOpType CheckBeforeDownload(const Asset &cacheAsset, const Assets &dbAssets); 46 static AssetOperationUtils::AssetOpType CheckAfterDownload(const Asset &cacheAsset, const Assets &dbAssets); 47 static AssetOperationUtils::AssetOpType CheckWithDownload(bool before, const Asset &cacheAsset, 48 const Assets &dbAssets); 49 static AssetOperationUtils::AssetOpType CheckAfterUpload(const Asset &cacheAsset, const Assets &dbAssets); 50 static AssetOperationUtils::AssetOpType HandleIfExistAndSameStatus(const Asset &cacheAsset, const Assets &dbAssets); 51 static Assets GetAssets(const std::string &colName, const VBucket &rowData); 52 static void MergeAssetFlag(const Assets &from, Asset &target); 53 static void MergeAssetsFlag(const Assets &from, Type &target); 54 static constexpr uint32_t BIT_MASK_COUNT = 16; 55 }; 56 } 57 #endif // ASSET_OPERATION_UTILS_H 58