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 MULTI_VER_VACUUM_EXECUTOR_H 17 #define MULTI_VER_VACUUM_EXECUTOR_H 18 19 #include <list> 20 #include <string> 21 #include <vector> 22 #include <cstdint> 23 24 namespace DistributedDB { 25 enum class RecordType { 26 CLEAR, 27 DELETE, 28 VALID, // Not clear nor delete 29 }; 30 31 struct MultiVerRecordInfo { 32 RecordType type; 33 uint64_t version; 34 std::vector<uint8_t> hashKey; 35 }; 36 37 struct MultiVerCommitInfo { 38 uint64_t version; 39 std::vector<uint8_t> commitId; 40 }; 41 42 // All functions will not be concurrently called 43 class MultiVerVacuumExecutor { 44 public: 45 // Call this always beyond transaction 46 virtual int GetVacuumAbleCommits(std::list<MultiVerCommitInfo> &leftBranchCommits, 47 std::list<MultiVerCommitInfo> &rightBranchCommits) const = 0; 48 49 // Call this within or beyond transaction 50 virtual int GetVacuumNeedRecordsByVersion(uint64_t version, std::list<MultiVerRecordInfo> &vacuumNeedRecords) = 0; 51 52 // Call this within or beyond transaction 53 virtual int GetShadowRecordsOfClearTypeRecord(uint64_t version, const std::vector<uint8_t> &hashKey, 54 std::list<MultiVerRecordInfo> &shadowRecords) = 0; 55 56 // Call this within or beyond transaction 57 virtual int GetShadowRecordsOfNonClearTypeRecord(uint64_t version, const std::vector<uint8_t> &hashKey, 58 std::list<MultiVerRecordInfo> &shadowRecords) = 0; 59 60 // Call this before change the database 61 virtual int StartTransactionForVacuum() = 0; 62 63 // Call this if nothing error happened, if this itself failed, do not need to call rollback 64 virtual int CommitTransactionForVacuum() = 0; 65 66 // Call this if anything wrong happened after start transaction except commit fail 67 virtual int RollBackTransactionForVacuum() = 0; 68 69 // Call this always within transaction 70 virtual int DeleteRecordTotally(uint64_t version, const std::vector<uint8_t> &hashKey) = 0; 71 72 // Call this always within transaction 73 virtual int MarkRecordAsVacuumDone(uint64_t version, const std::vector<uint8_t> &hashKey) = 0; 74 75 // Call this always within transaction 76 virtual int MarkCommitAsVacuumDone(const std::vector<uint8_t> &commitId) = 0; 77 ~MultiVerVacuumExecutor()78 virtual ~MultiVerVacuumExecutor() {}; 79 }; 80 } // namespace DistributedDB 81 82 #endif // MULTI_VER_VACUUM_EXECUTOR_H 83