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 AssetOperationUtils::AssetOpType CalAssetRemoveOperation(const std::string &colName, 40 const Asset &cacheAsset, const VBucket &assets); 41 static uint32_t EraseBitMask(uint32_t status); 42 static void UpdateAssetsFlag(std::vector<VBucket> &from, std::vector<VBucket> &target); 43 static void FilterDeleteAsset(VBucket &record); 44 static std::map<std::string, Assets> FilterNeedDownloadAsset(VBucket &record); 45 static bool IsAssetNeedDownload(const Asset &asset); 46 static bool IsAssetsNeedDownload(const Assets &assets); 47 private: 48 static void Init(); 49 static AssetOperationUtils::AssetOpType DefaultOperation(const Asset &, const Assets &); 50 static AssetOperationUtils::AssetOpType CheckBeforeDownload(const Asset &cacheAsset, const Assets &dbAssets); 51 static AssetOperationUtils::AssetOpType CheckAfterDownload(const Asset &cacheAsset, const Assets &dbAssets); 52 static AssetOperationUtils::AssetOpType CheckWithDownload(bool before, const Asset &cacheAsset, 53 const Assets &dbAssets); 54 static AssetOperationUtils::AssetOpType CheckAfterUpload(const Asset &cacheAsset, const Assets &dbAssets); 55 static AssetOperationUtils::AssetOpType HandleIfExistAndSameStatus(const Asset &cacheAsset, const Assets &dbAssets); 56 static Assets GetAssets(const std::string &colName, const VBucket &rowData); 57 static void MergeAssetFlag(const Assets &from, Asset &target); 58 static void MergeAssetsFlag(const Assets &from, Type &target); 59 static void FillDownloadAssetIfNeed(const std::string &field, const Asset &asset, 60 std::map<std::string, Assets> &beFilledAssets); 61 static bool IsFirstDownloadAsset(const Asset &asset); 62 static constexpr uint32_t BIT_MASK_COUNT = 16; 63 }; 64 } 65 #endif // ASSET_OPERATION_UTILS_H 66