-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathengine_internal.h
105 lines (87 loc) · 3.81 KB
/
engine_internal.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
#pragma once
#include <map>
#include "dbcore/sm-common.h"
namespace ermia {
struct schema_record;
// Base class for user-facing index implementations
class OrderedIndex {
friend class transaction;
protected:
TableDescriptor *table_descriptor;
bool is_primary;
FID self_fid;
public:
OrderedIndex(std::string table_name, bool is_primary);
OrderedIndex(std::string table_name, bool is_primary, FID self_fid);
virtual ~OrderedIndex() {}
inline TableDescriptor *GetTableDescriptor() { return table_descriptor; }
inline void SetTableDescriptor(TableDescriptor *td) {
volatile_write(table_descriptor, td);
}
inline bool IsPrimary() { return is_primary; }
inline FID GetIndexFid() { return self_fid; }
virtual void *GetTable() = 0;
class ScanCallback {
public:
virtual ~ScanCallback() {}
virtual bool Invoke(const char *keyp, size_t keylen,
const varstr &value) = 0;
};
// Get a record with a key of length keylen. The underlying DB does not manage
// the memory associated with key. [rc] stores TRUE if found, FALSE otherwise.
virtual PROMISE(void)
GetRecord(transaction *t, rc_t &rc, const varstr &key, varstr &value,
OID *out_oid = nullptr, schema_record *schema = nullptr) = 0;
// Return the OID that corresponds the given key
virtual PROMISE(void)
GetOID(const varstr &key, rc_t &rc, TXN::xid_context *xc, OID &out_oid,
ConcurrentMasstree::versioned_node_t *out_sinfo = nullptr) = 0;
// Update a database record with a key of length keylen, with mapping of
// length valuelen. The underlying DB does not manage the memory pointed to
// by key or value (a copy is made).
//
// If the does not already exist and config::upsert is set to true, insert.
virtual PROMISE(rc_t)
UpdateRecord(transaction *t, const varstr &key, varstr &value,
schema_record *schema = nullptr) = 0;
// Insert a record with a key of length keylen.
virtual PROMISE(rc_t)
InsertRecord(transaction *t, const varstr &key, varstr &value,
OID *out_oid = nullptr, schema_record *schema = nullptr) = 0;
// Map a key to an existing OID. Could be used for primary or secondary index.
virtual PROMISE(bool)
InsertOID(transaction *t, const varstr &key, OID oid) = 0;
// Search [start_key, *end_key) if end_key is not null, otherwise
// search [start_key, +infty)
virtual PROMISE(rc_t)
Scan(transaction *t, const varstr &start_key, const varstr *end_key,
ScanCallback &callback, schema_record *schema = nullptr) = 0;
// Search (*end_key, start_key] if end_key is not null, otherwise
// search (-infty, start_key] (starting at start_key and traversing
// backwards)
virtual PROMISE(rc_t)
ReverseScan(transaction *t, const varstr &start_key,
const varstr *end_key, ScanCallback &callback,
schema_record *schema = nullptr) = 0;
// Default implementation calls put() with NULL (zero-length) value
virtual PROMISE(rc_t) RemoveRecord(transaction *t, const varstr &key,
schema_record *schema = nullptr) = 0;
#if defined(LAZYDDL) && !defined(OPTLAZYDDL)
virtual PROMISE(rc_t)
LazyBuildSecondaryIndex(transaction *t, OID oid, const varstr &key,
varstr &value, schema_record *schema = nullptr) = 0;
#endif
virtual size_t Size() = 0;
virtual std::map<std::string, uint64_t> Clear() = 0;
virtual void SetArrays(bool) = 0;
virtual oid_array *GetTupleArray() = 0;
virtual bool GetIsPrimary() = 0;
/**
* Insert key-oid pair to the underlying actual index structure.
*
* Returns false if the record already exists or there is potential phantom.
*/
virtual PROMISE(bool)
InsertIfAbsent(transaction *t, const varstr &key, OID oid) = 0;
};
} // namespace ermia