-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_buffer.h
More file actions
55 lines (43 loc) · 1.35 KB
/
commit_buffer.h
File metadata and controls
55 lines (43 loc) · 1.35 KB
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
#include <atomic>
#include "varstr.h"
#include "mem.h"
namespace felis {
// Commit buffer to deal with repeat updates within one transaction. Usually
// this is a per-transaction hashtable, however, in our case, we don't have a
// notion of commit, and we have to preserve this hashtable across multiple
// phases.
//
// So, our commit buffer is a per-epoch hashtable, it will be reset (in
// parallel) at the epoch boundary.
class VHandle;
class CommitBuffer {
public:
struct Entry {
VHandle *vhandle;
uint32_t short_sid; // sid inside the epoch.
std::atomic_int32_t wcnt;
union {
std::atomic<Entry *> dup = nullptr;
VarStr *value;
} u;
std::atomic<Entry *> next = nullptr;
Entry(VHandle *vhandle, uint32_t sid) : vhandle(vhandle), short_sid(sid), wcnt(1) {}
};
private:
std::atomic<Entry *> *ref_hashtable;
unsigned long ref_hashtable_size;
std::atomic<Entry *> *dup_hashtable;
unsigned long dup_hashtable_size;
std::atomic_uint64_t clear_refcnt; // 0 means all clear
std::array<mem::Brk *,
mem::ParallelAllocationPolicy::kMaxNrPools> entbrks;
void EnsureReady();
public:
CommitBuffer();
void Reset();
void Clear(int core_id);
bool AddRef(int core_id, VHandle *vhandle, uint64_t sid);
Entry *LookupDuplicate(VHandle *vhandle, uint64_t sid);
};
using WriteSetDesc = CommitBuffer::Entry;
}