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 CLOUD_META_DATA_H 17 #define CLOUD_META_DATA_H 18 19 #include <mutex> 20 #include <string> 21 #include <unordered_map> 22 23 #include "cloud/cloud_store_types.h" 24 #include "db_types.h" 25 #include "icloud_sync_storage_interface.h" 26 #include "types_export.h" 27 28 namespace DistributedDB { 29 30 class CloudMetaData { 31 public: 32 explicit CloudMetaData(ICloudSyncStorageInterface *store); 33 ~CloudMetaData() = default; 34 35 int GetLocalWaterMark(const TableName &tableName, Timestamp &localMark); 36 int GetCloudWaterMark(const TableName &tableName, std::string &cloudMark); 37 38 int SetLocalWaterMark(const TableName &tableName, Timestamp localMark); 39 int SetCloudWaterMark(const TableName &tableName, std::string &cloudMark); 40 41 int CleanWaterMark(const TableName &tableName); 42 43 private: 44 typedef struct CloudMetaValue { 45 Timestamp localMark = 0u; 46 std::string cloudMark; 47 } CloudMetaValue; 48 49 int ReadMarkFromMeta(const TableName &tableName); 50 int WriteMarkToMeta(const TableName &tableName, Timestamp localmark, std::string &cloudMark); 51 int SerializeMark(Timestamp localMark, std::string &cloudMark, Value &blobMeta); 52 int DeserializeMark(Value &blobMark, CloudMetaValue &cloudMetaValue); 53 Key GetPrefixTableName(const TableName &tableName); 54 55 mutable std::mutex cloudMetaMutex_; 56 std::unordered_map<TableName, CloudMetaValue> cloudMetaVals_; 57 ICloudSyncStorageInterface *store_ = nullptr; 58 }; 59 60 } // namespace DistributedDB 61 #endif // DISTRIBUTEDDB_TYPES_EXPORT_H 62