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_MULTI_VER_TRANSACTION_H
17 #define I_KV_DB_MULTI_VER_TRANSACTION_H
18 
19 #ifndef OMIT_MULTI_VER
20 #include "db_types.h"
21 #include "multi_ver_def.h"
22 #include "multi_ver_kv_entry.h"
23 
24 namespace DistributedDB {
25 class IKvDBMultiVerTransaction {
26 public:
~IKvDBMultiVerTransaction()27     virtual ~IKvDBMultiVerTransaction() {};
28     virtual int Put(const Key &key, const Value &value) = 0;
29     virtual int Delete(const Key &key) = 0;
30     virtual int Clear() = 0;
31     virtual int Get(const Key &key, Value &value) const = 0;
32     virtual int GetEntries(const Key &keyPrefix, std::vector<Entry> &entries) const = 0;
33     virtual int PutBatch(const std::vector<MultiVerKvEntry *> &entries, bool isLocal,
34         std::vector<Value> &values) = 0;
35     virtual int GetEntriesByVersion(const Version &versionInfo, std::vector<MultiVerKvEntry *> &entries) const = 0;
36     virtual int GetDiffEntries(const Version &begin, const Version &end, MultiVerDiffData &data) const = 0;
37     virtual int GetMaxVersion(MultiVerDataType type, Version &maxVersion) const = 0;
38     virtual int ClearEntriesByVersion(const Version &versionInfo) = 0;
39     virtual int StartTransaction() = 0;
40     virtual int RollBackTransaction() = 0;
41     virtual int CommitTransaction() = 0;
42     virtual int UpdateTimestampByVersion(const Version &version, Timestamp stamp) const = 0;
43     virtual bool IsDataChanged() const = 0; // only for write transaction.
44     virtual bool IsRecordCleared(const Timestamp timestamp) const = 0;
45     virtual Timestamp GetCurrentMaxTimestamp() const = 0;
46     virtual void SetVersion(const Version &versionInfo) = 0;
47     virtual Version GetVersion() const = 0;
48     virtual int GetEntriesByVersion(Version version, std::list<MultiVerTrimedVersionData> &data) const = 0;
49     virtual int GetOverwrittenClearTypeEntries(Version clearVersion,
50         std::list<MultiVerTrimedVersionData> &data) const = 0;
51     virtual int GetOverwrittenNonClearTypeEntries(Version version, const Key &hashKey,
52         std::list<MultiVerTrimedVersionData> &data) const = 0;
53     virtual int DeleteEntriesByHashKey(Version version, const Key &hashKey) = 0;
54     virtual int GetValueForTrimSlice(const Key &hashKey, const Version vision, Value &value) const = 0;
55 };
56 } // namespace DistributedDB
57 
58 #endif  // I_KV_DB_MULTI_VER_TRANSACTION_H
59 #endif