rrudb 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/LICENSE.txt +22 -0
- data/README.md +26 -0
- data/examples/example.rb +39 -0
- data/ext/rudb/NuDB/include/nudb/CMakeLists.txt +104 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/basic_seconds_clock.hpp +200 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/chrono_util.hpp +58 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/test/fail_file.hpp +343 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/test/temp_dir.hpp +73 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/test/test_store.hpp +451 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/test/xor_shift_engine.hpp +105 -0
- data/ext/rudb/NuDB/include/nudb/_experimental/util.hpp +288 -0
- data/ext/rudb/NuDB/include/nudb/basic_store.hpp +461 -0
- data/ext/rudb/NuDB/include/nudb/concepts.hpp +205 -0
- data/ext/rudb/NuDB/include/nudb/context.hpp +144 -0
- data/ext/rudb/NuDB/include/nudb/create.hpp +117 -0
- data/ext/rudb/NuDB/include/nudb/detail/arena.hpp +296 -0
- data/ext/rudb/NuDB/include/nudb/detail/bucket.hpp +473 -0
- data/ext/rudb/NuDB/include/nudb/detail/buffer.hpp +86 -0
- data/ext/rudb/NuDB/include/nudb/detail/bulkio.hpp +196 -0
- data/ext/rudb/NuDB/include/nudb/detail/cache.hpp +236 -0
- data/ext/rudb/NuDB/include/nudb/detail/endian.hpp +93 -0
- data/ext/rudb/NuDB/include/nudb/detail/field.hpp +265 -0
- data/ext/rudb/NuDB/include/nudb/detail/format.hpp +630 -0
- data/ext/rudb/NuDB/include/nudb/detail/gentex.hpp +259 -0
- data/ext/rudb/NuDB/include/nudb/detail/mutex.hpp +26 -0
- data/ext/rudb/NuDB/include/nudb/detail/pool.hpp +243 -0
- data/ext/rudb/NuDB/include/nudb/detail/store_base.hpp +45 -0
- data/ext/rudb/NuDB/include/nudb/detail/stream.hpp +149 -0
- data/ext/rudb/NuDB/include/nudb/detail/xxhash.hpp +328 -0
- data/ext/rudb/NuDB/include/nudb/error.hpp +257 -0
- data/ext/rudb/NuDB/include/nudb/file.hpp +55 -0
- data/ext/rudb/NuDB/include/nudb/impl/basic_store.ipp +785 -0
- data/ext/rudb/NuDB/include/nudb/impl/context.ipp +241 -0
- data/ext/rudb/NuDB/include/nudb/impl/create.ipp +163 -0
- data/ext/rudb/NuDB/include/nudb/impl/error.ipp +175 -0
- data/ext/rudb/NuDB/include/nudb/impl/posix_file.ipp +248 -0
- data/ext/rudb/NuDB/include/nudb/impl/recover.ipp +209 -0
- data/ext/rudb/NuDB/include/nudb/impl/rekey.ipp +248 -0
- data/ext/rudb/NuDB/include/nudb/impl/verify.ipp +634 -0
- data/ext/rudb/NuDB/include/nudb/impl/visit.ipp +96 -0
- data/ext/rudb/NuDB/include/nudb/impl/win32_file.ipp +264 -0
- data/ext/rudb/NuDB/include/nudb/native_file.hpp +76 -0
- data/ext/rudb/NuDB/include/nudb/nudb.hpp +27 -0
- data/ext/rudb/NuDB/include/nudb/posix_file.hpp +228 -0
- data/ext/rudb/NuDB/include/nudb/progress.hpp +32 -0
- data/ext/rudb/NuDB/include/nudb/recover.hpp +73 -0
- data/ext/rudb/NuDB/include/nudb/rekey.hpp +110 -0
- data/ext/rudb/NuDB/include/nudb/store.hpp +27 -0
- data/ext/rudb/NuDB/include/nudb/type_traits.hpp +63 -0
- data/ext/rudb/NuDB/include/nudb/verify.hpp +200 -0
- data/ext/rudb/NuDB/include/nudb/version.hpp +21 -0
- data/ext/rudb/NuDB/include/nudb/visit.hpp +63 -0
- data/ext/rudb/NuDB/include/nudb/win32_file.hpp +246 -0
- data/ext/rudb/NuDB/include/nudb/xxhasher.hpp +45 -0
- data/ext/rudb/extconf.rb +12 -0
- data/ext/rudb/rudb.cpp +234 -0
- data/lib/rudb/version.rb +3 -0
- data/lib/rudb.rb +1 -0
- metadata +104 -0
@@ -0,0 +1,343 @@
|
|
1
|
+
//
|
2
|
+
// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
|
3
|
+
//
|
4
|
+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
5
|
+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
6
|
+
//
|
7
|
+
|
8
|
+
#ifndef NUDB_TEST_FAIL_FILE_HPP
|
9
|
+
#define NUDB_TEST_FAIL_FILE_HPP
|
10
|
+
|
11
|
+
#include <nudb/concepts.hpp>
|
12
|
+
#include <nudb/error.hpp>
|
13
|
+
#include <nudb/file.hpp>
|
14
|
+
#include <atomic>
|
15
|
+
#include <cstddef>
|
16
|
+
#include <string>
|
17
|
+
#include <utility>
|
18
|
+
|
19
|
+
namespace nudb {
|
20
|
+
namespace test {
|
21
|
+
|
22
|
+
/// Test error codes.
|
23
|
+
enum class test_error
|
24
|
+
{
|
25
|
+
/// No error
|
26
|
+
success = 0,
|
27
|
+
|
28
|
+
/// Simulated failure
|
29
|
+
failure
|
30
|
+
};
|
31
|
+
|
32
|
+
/// Returns the error category used for test error codes.
|
33
|
+
inline
|
34
|
+
error_category const&
|
35
|
+
test_category()
|
36
|
+
{
|
37
|
+
struct cat_t : public error_category
|
38
|
+
{
|
39
|
+
char const*
|
40
|
+
name() const noexcept override
|
41
|
+
{
|
42
|
+
return "nudb";
|
43
|
+
}
|
44
|
+
|
45
|
+
std::string
|
46
|
+
message(int ev) const override
|
47
|
+
{
|
48
|
+
switch(static_cast<test_error>(ev))
|
49
|
+
{
|
50
|
+
case test_error::failure:
|
51
|
+
return "test failure";
|
52
|
+
|
53
|
+
default:
|
54
|
+
return "test error";
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
error_condition
|
59
|
+
default_error_condition(int ev) const noexcept override
|
60
|
+
{
|
61
|
+
return error_condition{ev, *this};
|
62
|
+
}
|
63
|
+
|
64
|
+
bool
|
65
|
+
equivalent(int ev,
|
66
|
+
error_condition const& ec) const noexcept override
|
67
|
+
{
|
68
|
+
return ec.value() == ev && &ec.category() == this;
|
69
|
+
}
|
70
|
+
|
71
|
+
bool
|
72
|
+
equivalent(error_code const& ec, int ev) const noexcept override
|
73
|
+
{
|
74
|
+
return ec.value() == ev && &ec.category() == this;
|
75
|
+
}
|
76
|
+
};
|
77
|
+
static cat_t const cat{};
|
78
|
+
return cat;
|
79
|
+
}
|
80
|
+
|
81
|
+
/// Returns a test error code.
|
82
|
+
inline
|
83
|
+
error_code
|
84
|
+
make_error_code(test_error ev)
|
85
|
+
{
|
86
|
+
return error_code{static_cast<int>(ev), test_category()};
|
87
|
+
}
|
88
|
+
|
89
|
+
} // test
|
90
|
+
} // nudb
|
91
|
+
|
92
|
+
namespace boost {
|
93
|
+
namespace system {
|
94
|
+
template<>
|
95
|
+
struct is_error_code_enum<nudb::test::test_error>
|
96
|
+
{
|
97
|
+
static bool const value = true;
|
98
|
+
};
|
99
|
+
} // system
|
100
|
+
} // boost
|
101
|
+
|
102
|
+
namespace nudb {
|
103
|
+
namespace test {
|
104
|
+
|
105
|
+
/** Countdown to test failure mode.
|
106
|
+
|
107
|
+
The counter is constructed with a target ordinal and decremented
|
108
|
+
by callers. When the count reaches zero, a simulated test failure
|
109
|
+
is generated.
|
110
|
+
*/
|
111
|
+
class fail_counter
|
112
|
+
{
|
113
|
+
std::size_t target_;
|
114
|
+
std::atomic<std::size_t> count_;
|
115
|
+
|
116
|
+
public:
|
117
|
+
fail_counter(fail_counter const&) = delete;
|
118
|
+
fail_counter& operator=(fail_counter const&) = delete;
|
119
|
+
|
120
|
+
/// Construct the counter with a target ordinal.
|
121
|
+
explicit
|
122
|
+
fail_counter(std::size_t target = 0)
|
123
|
+
{
|
124
|
+
reset(target);
|
125
|
+
}
|
126
|
+
|
127
|
+
/// Reset the counter to fail at the nth step, or 0 for no failure.
|
128
|
+
void
|
129
|
+
reset(std::size_t n = 0)
|
130
|
+
{
|
131
|
+
target_ = n;
|
132
|
+
count_.store(0);
|
133
|
+
}
|
134
|
+
|
135
|
+
/// Returns `true` if a simulated failure should be generated.
|
136
|
+
bool
|
137
|
+
fail()
|
138
|
+
{
|
139
|
+
return target_ && (++count_ >= target_);
|
140
|
+
}
|
141
|
+
};
|
142
|
+
|
143
|
+
/** A file wrapper to simulate file system failures.
|
144
|
+
|
145
|
+
This wraps an object meeting the requirements of File. On each call,
|
146
|
+
the fail counter is decremented. When the counter reaches zero, a simulated
|
147
|
+
failure is generated.
|
148
|
+
*/
|
149
|
+
template<class File>
|
150
|
+
class fail_file
|
151
|
+
{
|
152
|
+
static_assert(is_File<File>::value,
|
153
|
+
"File requirements not met");
|
154
|
+
|
155
|
+
File f_;
|
156
|
+
fail_counter* c_ = nullptr;
|
157
|
+
|
158
|
+
public:
|
159
|
+
fail_file() = default;
|
160
|
+
fail_file(fail_file const&) = delete;
|
161
|
+
fail_file& operator=(fail_file const&) = delete;
|
162
|
+
~fail_file() = default;
|
163
|
+
|
164
|
+
fail_file(fail_file&&);
|
165
|
+
|
166
|
+
fail_file&
|
167
|
+
operator=(fail_file&& other);
|
168
|
+
|
169
|
+
explicit
|
170
|
+
fail_file(fail_counter& c);
|
171
|
+
|
172
|
+
bool
|
173
|
+
is_open() const
|
174
|
+
{
|
175
|
+
return f_.is_open();
|
176
|
+
}
|
177
|
+
|
178
|
+
path_type const&
|
179
|
+
path() const
|
180
|
+
{
|
181
|
+
return f_.path();
|
182
|
+
}
|
183
|
+
|
184
|
+
std::uint64_t
|
185
|
+
size(error_code& ec) const
|
186
|
+
{
|
187
|
+
return f_.size(ec);
|
188
|
+
}
|
189
|
+
|
190
|
+
void
|
191
|
+
close()
|
192
|
+
{
|
193
|
+
f_.close();
|
194
|
+
}
|
195
|
+
|
196
|
+
void
|
197
|
+
create(file_mode mode, path_type const& path, error_code& ec)
|
198
|
+
{
|
199
|
+
return f_.create(mode, path, ec);
|
200
|
+
}
|
201
|
+
|
202
|
+
void
|
203
|
+
open(file_mode mode, path_type const& path, error_code& ec)
|
204
|
+
{
|
205
|
+
return f_.open(mode, path, ec);
|
206
|
+
}
|
207
|
+
|
208
|
+
static
|
209
|
+
void
|
210
|
+
erase(path_type const& path, error_code& ec)
|
211
|
+
{
|
212
|
+
File::erase(path, ec);
|
213
|
+
}
|
214
|
+
|
215
|
+
void
|
216
|
+
read(std::uint64_t offset,
|
217
|
+
void* buffer, std::size_t bytes, error_code& ec);
|
218
|
+
|
219
|
+
void
|
220
|
+
write(std::uint64_t offset,
|
221
|
+
void const* buffer, std::size_t bytes, error_code& ec);
|
222
|
+
|
223
|
+
void
|
224
|
+
sync(error_code& ec);
|
225
|
+
|
226
|
+
void
|
227
|
+
trunc(std::uint64_t length, error_code& ec);
|
228
|
+
|
229
|
+
private:
|
230
|
+
bool
|
231
|
+
fail();
|
232
|
+
|
233
|
+
void
|
234
|
+
do_fail(error_code& ec)
|
235
|
+
{
|
236
|
+
ec = test_error::failure;
|
237
|
+
}
|
238
|
+
};
|
239
|
+
|
240
|
+
template<class File>
|
241
|
+
fail_file<File>::
|
242
|
+
fail_file(fail_file&& other)
|
243
|
+
: f_(std::move(other.f_))
|
244
|
+
, c_(other.c_)
|
245
|
+
{
|
246
|
+
other.c_ = nullptr;
|
247
|
+
}
|
248
|
+
|
249
|
+
template<class File>
|
250
|
+
fail_file<File>&
|
251
|
+
fail_file<File>::
|
252
|
+
operator=(fail_file&& other)
|
253
|
+
{
|
254
|
+
f_ = std::move(other.f_);
|
255
|
+
c_ = other.c_;
|
256
|
+
other.c_ = nullptr;
|
257
|
+
return *this;
|
258
|
+
}
|
259
|
+
|
260
|
+
template<class File>
|
261
|
+
fail_file<File>::
|
262
|
+
fail_file(fail_counter& c)
|
263
|
+
: c_(&c)
|
264
|
+
{
|
265
|
+
}
|
266
|
+
|
267
|
+
template<class File>
|
268
|
+
void
|
269
|
+
fail_file<File>::
|
270
|
+
read(std::uint64_t offset,
|
271
|
+
void* buffer, std::size_t bytes, error_code& ec)
|
272
|
+
{
|
273
|
+
if(fail())
|
274
|
+
{
|
275
|
+
do_fail(ec);
|
276
|
+
return;
|
277
|
+
}
|
278
|
+
f_.read(offset, buffer, bytes, ec);
|
279
|
+
}
|
280
|
+
|
281
|
+
template<class File>
|
282
|
+
void
|
283
|
+
fail_file<File>::
|
284
|
+
write(std::uint64_t offset,
|
285
|
+
void const* buffer, std::size_t bytes, error_code& ec)
|
286
|
+
{
|
287
|
+
if(fail())
|
288
|
+
{
|
289
|
+
do_fail(ec);
|
290
|
+
return;
|
291
|
+
}
|
292
|
+
if(fail())
|
293
|
+
{
|
294
|
+
// partial write
|
295
|
+
f_.write(offset, buffer,(bytes + 1) / 2, ec);
|
296
|
+
if(ec)
|
297
|
+
return;
|
298
|
+
do_fail(ec);
|
299
|
+
return;
|
300
|
+
}
|
301
|
+
f_.write(offset, buffer, bytes, ec);
|
302
|
+
}
|
303
|
+
|
304
|
+
template<class File>
|
305
|
+
void
|
306
|
+
fail_file<File>::
|
307
|
+
sync(error_code& ec)
|
308
|
+
{
|
309
|
+
if(fail())
|
310
|
+
do_fail(ec);
|
311
|
+
// We don't need a real sync for
|
312
|
+
// testing, it just slows things down.
|
313
|
+
//f_.sync();
|
314
|
+
}
|
315
|
+
|
316
|
+
template<class File>
|
317
|
+
void
|
318
|
+
fail_file<File>::
|
319
|
+
trunc(std::uint64_t length, error_code& ec)
|
320
|
+
{
|
321
|
+
if(fail())
|
322
|
+
{
|
323
|
+
do_fail(ec);
|
324
|
+
return;
|
325
|
+
}
|
326
|
+
f_.trunc(length, ec);
|
327
|
+
}
|
328
|
+
|
329
|
+
template<class File>
|
330
|
+
bool
|
331
|
+
fail_file<File>::
|
332
|
+
fail()
|
333
|
+
{
|
334
|
+
if(c_)
|
335
|
+
return c_->fail();
|
336
|
+
return false;
|
337
|
+
}
|
338
|
+
|
339
|
+
} // test
|
340
|
+
} // nudb
|
341
|
+
|
342
|
+
#endif
|
343
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
//
|
2
|
+
// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
|
3
|
+
//
|
4
|
+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
5
|
+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
6
|
+
//
|
7
|
+
|
8
|
+
#ifndef NUDB_TEST_TEMP_DIR_HPP
|
9
|
+
#define NUDB_TEST_TEMP_DIR_HPP
|
10
|
+
|
11
|
+
#include <boost/filesystem.hpp>
|
12
|
+
#include <string>
|
13
|
+
|
14
|
+
namespace nudb {
|
15
|
+
namespace test {
|
16
|
+
|
17
|
+
/** RAII temporary directory path.
|
18
|
+
|
19
|
+
The directory and all its contents are deleted when
|
20
|
+
the instance of `temp_dir` is destroyed.
|
21
|
+
*/
|
22
|
+
class temp_dir
|
23
|
+
{
|
24
|
+
boost::filesystem::path path_;
|
25
|
+
|
26
|
+
public:
|
27
|
+
temp_dir(const temp_dir&) = delete;
|
28
|
+
temp_dir& operator=(const temp_dir&) = delete;
|
29
|
+
|
30
|
+
/// Construct a temporary directory.
|
31
|
+
explicit
|
32
|
+
temp_dir(boost::filesystem::path dir)
|
33
|
+
{
|
34
|
+
if (dir.empty())
|
35
|
+
dir = boost::filesystem::temp_directory_path();
|
36
|
+
|
37
|
+
do
|
38
|
+
{
|
39
|
+
path_ =
|
40
|
+
dir / boost::filesystem::unique_path();
|
41
|
+
}
|
42
|
+
while(boost::filesystem::exists(path_));
|
43
|
+
boost::filesystem::create_directory(path_);
|
44
|
+
}
|
45
|
+
|
46
|
+
/// Destroy a temporary directory.
|
47
|
+
~temp_dir()
|
48
|
+
{
|
49
|
+
boost::filesystem::remove_all(path_);
|
50
|
+
}
|
51
|
+
|
52
|
+
/// Get the native path for the temporary directory
|
53
|
+
std::string
|
54
|
+
path() const
|
55
|
+
{
|
56
|
+
return path_.string();
|
57
|
+
}
|
58
|
+
|
59
|
+
/** Get the native path for the a file.
|
60
|
+
|
61
|
+
The file does not need to exist.
|
62
|
+
*/
|
63
|
+
std::string
|
64
|
+
file(std::string const& name) const
|
65
|
+
{
|
66
|
+
return (path_ / name).string();
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
} // test
|
71
|
+
} // nudb
|
72
|
+
|
73
|
+
#endif
|