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 RELATIONAL_DB_CLOUD_INTERFACE_H 17 #define RELATIONAL_DB_CLOUD_INTERFACE_H 18 19 #include "cloud/cloud_db_types.h" 20 #include "data_transformer.h" 21 #include "sqlite_utils.h" 22 #include "store_observer.h" 23 24 namespace DistributedDB { 25 26 enum class OpType : uint8_t { 27 INSERT = 1, 28 UPDATE, // update data, gid and timestamp at same time 29 DELETE, 30 ONLY_UPDATE_GID, 31 // used in Cloud Force Push strategy, when SET_CLOUD_FORCE_PUSH_FLAG_ONE, upload process won't process this record 32 SET_CLOUD_FORCE_PUSH_FLAG_ONE, 33 SET_CLOUD_FORCE_PUSH_FLAG_ZERO, 34 UPDATE_TIMESTAMP, 35 CLEAR_GID, 36 NOT_HANDLE 37 }; 38 39 typedef struct DownloadData { 40 std::vector<VBucket> data; 41 std::vector<OpType> opType; 42 } DownloadData; 43 44 class ICloudSyncStorageInterface { 45 public: 46 ICloudSyncStorageInterface() = default; 47 virtual ~ICloudSyncStorageInterface() = default; 48 49 virtual int GetMetaData(const Key &key, Value &value) const = 0; 50 51 virtual int PutMetaData(const Key &key, const Value &value) = 0; 52 53 virtual int ChkSchema(const TableName &tableName) = 0; 54 55 virtual int SetCloudDbSchema(const DataBaseSchema &schema) = 0; 56 57 virtual int GetCloudDbSchema(DataBaseSchema &cloudSchema) = 0; 58 59 virtual int GetCloudTableSchema(const TableName &tableName, TableSchema &tableSchema) = 0; 60 61 virtual int StartTransaction(TransactType type) = 0; 62 63 virtual int Commit() = 0; 64 65 virtual int Rollback() = 0; 66 67 virtual int GetUploadCount(const std::string &tableName, const Timestamp ×tamp, const bool isCloudForcePush, 68 int64_t &count) = 0; 69 70 virtual int FillCloudGid(const CloudSyncData &data) = 0; 71 72 virtual int GetCloudData(const TableSchema &tableSchema, const Timestamp &beginTime, 73 ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) = 0; 74 75 virtual int GetCloudDataNext(ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) = 0; 76 77 virtual int ReleaseCloudDataToken(ContinueToken &continueStmtToken) = 0; 78 79 virtual int GetInfoByPrimaryKeyOrGid(const std::string &tableName, const VBucket &vBucket, 80 DataInfoWithLog &dataInfoWithLog, VBucket &assetInfo) = 0; 81 82 virtual int PutCloudSyncData(const std::string &tableName, DownloadData &downloadData) = 0; 83 84 virtual int CleanCloudData(ClearMode mode, const std::vector<std::string> &tableNameList, 85 const RelationalSchemaObject &localSchema, std::vector<Asset> &assets) = 0; 86 87 virtual void TriggerObserverAction(const std::string &deviceName, ChangedData &&changedData, 88 bool isChangedData) = 0; 89 90 virtual int FillCloudAssetForDownload(const std::string &tableName, VBucket &asset, bool isDownloadSuccess) = 0; 91 92 virtual int SetLogTriggerStatus(bool status) = 0; 93 94 virtual int FillCloudGidAndAsset(OpType opType, const CloudSyncData &data) = 0; 95 96 virtual std::string GetIdentify() const = 0; 97 }; 98 } 99 100 #endif //RELATIONAL_DB_CLOUD_INTERFACE_H 101