forked from fastio/1store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memtable.hh
137 lines (121 loc) · 3.9 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
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 2016 ScyllaDB
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
/*
*
* This file is part of Pedis.
*
* Pedis is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* Modified by Peng Jian.
*
*/
#pragma once
#include <map>
#include <memory>
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/list.hpp>
#include <boost/intrusive_ptr.hpp>
#include "utils/logalloc.hh"
#include "utils/managed_bytes.hh"
#include "utils/managed_ref.hh"
#include "partition.hh"
#include "keys.hh"
#include "seastarx.hh"
#include <experimental/optional>
template<class T>
using optional = std::experimental::optional<T>;
namespace bi = boost::intrusive;
namespace store {
class memtable_entry {
boost::intrusive::set_member_hook<> _link;
managed_ref<partition> _partition;
public:
friend class memtable;
memtable_entry()
{
}
memtable_entry(memtable_entry&& o) noexcept;
struct compare {
bool operator()(const bytes& l, const memtable_entry& r) const {
//return l == r.key();
return true;
}
bool operator()(const memtable_entry& l, const memtable_entry& r) const {
//return l.key() == r.key();
return true;
}
bool operator()(const memtable_entry& l, const bytes& r) const {
//return l.key() == r;
return true;
}
};
};
class memtable final : public enable_lw_shared_from_this<memtable>, private logalloc::region {
public:
using partitions_type = bi::set<memtable_entry,
bi::member_hook<memtable_entry, bi::set_member_hook<>, &memtable_entry::_link>,
bi::compare<memtable_entry::compare>>;
private:
logalloc::allocating_section _read_section;
logalloc::allocating_section _allocating_section;
partitions_type _partitions;
uint64_t _flushed_memory = 0;
bool _write_enabled = true;
private:
partition& find_or_create_partition(const redis::decorated_key& key);
void upgrade_entry(memtable_entry&);
void add_flushed_memory(uint64_t);
void remove_flushed_memory(uint64_t);
void clear() noexcept;
uint64_t dirty_size() const;
future<> clear_gently() noexcept;
public:
explicit memtable();
~memtable();
static memtable& from_region(logalloc::region& r) {
return static_cast<memtable&>(r);
}
const logalloc::region& region() const {
return *this;
}
logalloc::region_group* region_group() {
return group();
}
void disable_write() { _write_enabled = false; }
bool write_enabled() const { return _write_enabled; }
public:
size_t partition_count() const;
logalloc::occupancy_stats occupancy() const;
future<> apply(cache_entry& e);
bool empty() const { return _partitions.empty(); }
bool is_flushed() const;
};
}