-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathKVEngine.h
137 lines (97 loc) · 4.74 KB
/
KVEngine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* Copyright (c) 2018 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#ifndef KVSTORE_KVENGINE_H_
#define KVSTORE_KVENGINE_H_
#include "common/base/Base.h"
#include "common/base/ErrorOr.h"
#include "common/base/Status.h"
#include "kvstore/Common.h"
#include "kvstore/KVIterator.h"
namespace nebula {
namespace kvstore {
class WriteBatch {
public:
virtual ~WriteBatch() = default;
virtual nebula::cpp2::ErrorCode put(folly::StringPiece key, folly::StringPiece value) = 0;
virtual nebula::cpp2::ErrorCode remove(folly::StringPiece key) = 0;
// Remove all keys in the range [start, end)
virtual nebula::cpp2::ErrorCode removeRange(folly::StringPiece start, folly::StringPiece end) = 0;
};
class KVEngine {
public:
explicit KVEngine(GraphSpaceID spaceId) : spaceId_(spaceId) {}
virtual ~KVEngine() = default;
virtual void stop() = 0;
// Retrieve the root path for the data
// If the store is persistent, a valid path will be returned
// Otherwise, nullptr will be returned
virtual const char* getDataRoot() const = 0;
virtual const char* getWalRoot() const = 0;
virtual std::unique_ptr<WriteBatch> startBatchWrite() = 0;
virtual nebula::cpp2::ErrorCode commitBatchWrite(std::unique_ptr<WriteBatch> batch,
bool disableWAL,
bool sync,
bool wait) = 0;
// Read a single key
virtual nebula::cpp2::ErrorCode get(const std::string& key, std::string* value) = 0;
// Read a list of keys, if key[i] does not exist, the i-th value in return
// value would be Status::KeyNotFound
virtual std::vector<Status> multiGet(const std::vector<std::string>& keys,
std::vector<std::string>* values) = 0;
// Get all results in range [start, end)
virtual nebula::cpp2::ErrorCode range(const std::string& start,
const std::string& end,
std::unique_ptr<KVIterator>* iter) = 0;
// Get all results with 'prefix' str as prefix.
virtual nebula::cpp2::ErrorCode prefix(const std::string& prefix,
std::unique_ptr<KVIterator>* iter) = 0;
// Get all results with 'prefix' str as prefix starting form 'start'
virtual nebula::cpp2::ErrorCode rangeWithPrefix(const std::string& start,
const std::string& prefix,
std::unique_ptr<KVIterator>* iter) = 0;
virtual nebula::cpp2::ErrorCode scan(std::unique_ptr<KVIterator>* storageIter) = 0;
// Write a single record
virtual nebula::cpp2::ErrorCode put(std::string key, std::string value) = 0;
// Write a batch of records
virtual nebula::cpp2::ErrorCode multiPut(std::vector<KV> keyValues) = 0;
// Remove a single key
virtual nebula::cpp2::ErrorCode remove(const std::string& key) = 0;
// Remove a batch of keys
virtual nebula::cpp2::ErrorCode multiRemove(std::vector<std::string> keys) = 0;
// Remove range [start, end)
virtual nebula::cpp2::ErrorCode removeRange(const std::string& start, const std::string& end) = 0;
// Add partId into current storage engine.
virtual void addPart(PartitionID partId) = 0;
// Remove partId from current storage engine.
virtual void removePart(PartitionID partId) = 0;
// Return all partIds current storage engine holds.
virtual std::vector<PartitionID> allParts() = 0;
// Return total parts num
virtual int32_t totalPartsNum() = 0;
// Ingest sst files
virtual nebula::cpp2::ErrorCode ingest(const std::vector<std::string>& files,
bool verifyFileChecksum = false) = 0;
// Set Config Option
virtual nebula::cpp2::ErrorCode setOption(const std::string& configKey,
const std::string& configValue) = 0;
// Set DB Config Option
virtual nebula::cpp2::ErrorCode setDBOption(const std::string& configKey,
const std::string& configValue) = 0;
virtual nebula::cpp2::ErrorCode compact() = 0;
virtual nebula::cpp2::ErrorCode flush() = 0;
virtual nebula::cpp2::ErrorCode createCheckpoint(const std::string& name) = 0;
// For meta
virtual ErrorOr<nebula::cpp2::ErrorCode, std::string> backupTable(
const std::string& path,
const std::string& tablePrefix,
std::function<bool(const folly::StringPiece& key)> filter) = 0;
virtual nebula::cpp2::ErrorCode backup() = 0;
protected:
GraphSpaceID spaceId_;
};
} // namespace kvstore
} // namespace nebula
#endif // KVSTORE_KVENGINE_H_