-
Notifications
You must be signed in to change notification settings - Fork 1
/
engine_internal.h
83 lines (67 loc) · 3.3 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
#pragma once
#include <map>
#include "dbcore/sm-common.h"
namespace ermia {
// 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);
virtual ~OrderedIndex() {}
inline TableDescriptor *GetTableDescriptor() { return table_descriptor; }
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) = 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) = 0;
// Insert a hot record with a key of length keylen.
virtual PROMISE(rc_t) InsertRecord(transaction *t, const varstr &key, varstr &value,
OID *out_oid = nullptr) = 0;
// Insert a cold record with a key of length keylen.
virtual PROMISE(rc_t) InsertColdRecord(transaction *t, const varstr &key, varstr &value,
OID *out_oid = 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) = 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) = 0;
// Default implementation calls put() with NULL (zero-length) value
virtual PROMISE(rc_t) RemoveRecord(transaction *t, const varstr &key) = 0;
virtual size_t Size() = 0;
virtual std::map<std::string, uint64_t> Clear() = 0;
virtual void SetArrays(bool) = 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