1 /* 2 * Copyright (c) 2021 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 I_KV_DB_COMMIT_STORAGE_H 17 #define I_KV_DB_COMMIT_STORAGE_H 18 19 #include <vector> 20 #include <string> 21 #include <list> 22 #include <map> 23 24 #include "db_types.h" 25 #include "ikvdb_commit.h" 26 #include "multi_ver_def.h" 27 28 namespace DistributedDB { 29 class IKvDBCommitStorage { 30 public: 31 struct Property final { 32 std::string path; 33 std::string identifierName; 34 bool isNeedCreate = true; 35 CipherType cipherType = CipherType::AES_256_GCM; 36 CipherPassword passwd; 37 }; 38 ~IKvDBCommitStorage()39 virtual ~IKvDBCommitStorage() {}; 40 virtual int CheckVersion(const Property &property, bool &isDbExist) const = 0; 41 virtual int Open(const Property &property) = 0; 42 virtual void Close() = 0; 43 virtual int Remove(const Property &property) = 0; 44 virtual IKvDBCommit *AllocCommit(int &errCode) const = 0; 45 virtual IKvDBCommit *GetCommit(const CommitID &commitId, int &errCode) const = 0; 46 virtual int AddCommit(const IKvDBCommit &commitEntry, bool isHeader) = 0; 47 virtual int RemoveCommit(const CommitID &commitId) = 0; 48 virtual void ReleaseCommit(const IKvDBCommit *commit) const = 0; 49 virtual int SetHeader(const CommitID &commitId) = 0; 50 virtual CommitID GetHeader(int &errCode) const = 0; 51 virtual bool CommitExist(const CommitID &commitId, int &errCode) const = 0; 52 virtual int GetLatestCommits(std::map<DeviceID, IKvDBCommit *> &latestCommits) const = 0; 53 virtual int GetCommitTree(const std::map<DeviceID, CommitID> &latestCommits, 54 std::list<IKvDBCommit *> &commits) const = 0; 55 virtual Version GetMaxCommitVersion(int &errCode) const = 0; 56 virtual int BackupCurrentDatabase(const Property &property, const std::string &dir) = 0; 57 virtual int ImportDatabase(const Property &property, const std::string &dir, const CipherPassword &passwd) = 0; 58 virtual int StartVacuum() = 0; 59 virtual int CancelVacuum() = 0; 60 virtual int FinishVacuum() = 0; 61 virtual int GetAllCommitsInTree(std::list<MultiVerCommitNode> &commits) const = 0; 62 }; 63 } // namespace DistributedDB 64 65 #endif // I_KV_DB_COMMIT_STORAGE_H 66