forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemtable.hh
103 lines (84 loc) · 3.36 KB
/
memtable.hh
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
/*
* Copyright 2015 Cloudius Systems
*/
#pragma once
#include <map>
#include <memory>
#include "database_fwd.hh"
#include "dht/i_partitioner.hh"
#include "schema.hh"
#include "mutation_reader.hh"
#include "db/commitlog/replay_position.hh"
class frozen_mutation;
namespace bi = boost::intrusive;
class partition_entry : public bi::set_base_hook<> {
dht::decorated_key _key;
mutation_partition _p;
public:
friend class memtable;
partition_entry(dht::decorated_key key, mutation_partition p)
: _key(std::move(key))
, _p(std::move(p))
{ }
const dht::decorated_key& key() const { return _key; }
const mutation_partition& partition() const { return _p; }
mutation_partition& partition() { return _p; }
struct compare {
dht::decorated_key::less_comparator _c;
compare(schema_ptr s)
: _c(std::move(s))
{}
bool operator()(const dht::decorated_key& k1, const partition_entry& k2) const {
return _c(k1, k2._key);
}
bool operator()(const partition_entry& k1, const partition_entry& k2) const {
return _c(k1._key, k2._key);
}
bool operator()(const partition_entry& k1, const dht::decorated_key& k2) const {
return _c(k1._key, k2);
}
bool operator()(const partition_entry& k1, const dht::ring_position& k2) const {
return _c(k1._key, k2);
}
bool operator()(const dht::ring_position& k1, const partition_entry& k2) const {
return _c(k1, k2._key);
}
};
};
// Managed by lw_shared_ptr<>.
class memtable final : public enable_lw_shared_from_this<memtable> {
public:
using partitions_type = bi::set<partition_entry, bi::compare<partition_entry::compare>>;
private:
schema_ptr _schema;
partitions_type partitions;
db::replay_position _replay_position;
void update(const db::replay_position&);
private:
boost::iterator_range<partitions_type::const_iterator> slice(const query::partition_range& r) const;
public:
using const_mutation_partition_ptr = std::unique_ptr<const mutation_partition>;
public:
explicit memtable(schema_ptr schema);
schema_ptr schema() const { return _schema; }
mutation_partition& find_or_create_partition(const dht::decorated_key& key);
mutation_partition& find_or_create_partition_slow(partition_key_view key);
row& find_or_create_row_slow(const partition_key& partition_key, const clustering_key& clustering_key);
const_mutation_partition_ptr find_partition(const dht::decorated_key& key) const;
void apply(const mutation& m, const db::replay_position& = db::replay_position());
void apply(const frozen_mutation& m, const db::replay_position& = db::replay_position());
public:
const partitions_type& all_partitions() const;
// Creates a reader of data in this memtable for given partition range.
//
// Live readers share ownership of the memtable instance, so caller
// doesn't need to ensure that memtable remains live.
//
// The 'range' parameter must be live as long as the reader is being used
mutation_reader make_reader(const query::partition_range& range = query::full_partition_range) const;
mutation_source as_data_source();
bool empty() const { return partitions.empty(); }
const db::replay_position& replay_position() const {
return _replay_position;
}
};