leveldb 0.0.1
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/LICENSE.txt +22 -0
- data/README.md +95 -0
- data/ext/Rakefile +11 -0
- data/ext/leveldb/LICENSE +27 -0
- data/ext/leveldb/Makefile +206 -0
- data/ext/leveldb/build_config.mk +13 -0
- data/ext/leveldb/db/builder.cc +88 -0
- data/ext/leveldb/db/builder.h +34 -0
- data/ext/leveldb/db/c.cc +595 -0
- data/ext/leveldb/db/c_test.c +390 -0
- data/ext/leveldb/db/corruption_test.cc +359 -0
- data/ext/leveldb/db/db_bench.cc +979 -0
- data/ext/leveldb/db/db_impl.cc +1485 -0
- data/ext/leveldb/db/db_impl.h +203 -0
- data/ext/leveldb/db/db_iter.cc +299 -0
- data/ext/leveldb/db/db_iter.h +26 -0
- data/ext/leveldb/db/db_test.cc +2092 -0
- data/ext/leveldb/db/dbformat.cc +140 -0
- data/ext/leveldb/db/dbformat.h +227 -0
- data/ext/leveldb/db/dbformat_test.cc +112 -0
- data/ext/leveldb/db/filename.cc +139 -0
- data/ext/leveldb/db/filename.h +80 -0
- data/ext/leveldb/db/filename_test.cc +122 -0
- data/ext/leveldb/db/leveldb_main.cc +238 -0
- data/ext/leveldb/db/log_format.h +35 -0
- data/ext/leveldb/db/log_reader.cc +259 -0
- data/ext/leveldb/db/log_reader.h +108 -0
- data/ext/leveldb/db/log_test.cc +500 -0
- data/ext/leveldb/db/log_writer.cc +103 -0
- data/ext/leveldb/db/log_writer.h +48 -0
- data/ext/leveldb/db/memtable.cc +145 -0
- data/ext/leveldb/db/memtable.h +91 -0
- data/ext/leveldb/db/repair.cc +389 -0
- data/ext/leveldb/db/skiplist.h +379 -0
- data/ext/leveldb/db/skiplist_test.cc +378 -0
- data/ext/leveldb/db/snapshot.h +66 -0
- data/ext/leveldb/db/table_cache.cc +121 -0
- data/ext/leveldb/db/table_cache.h +61 -0
- data/ext/leveldb/db/version_edit.cc +266 -0
- data/ext/leveldb/db/version_edit.h +107 -0
- data/ext/leveldb/db/version_edit_test.cc +46 -0
- data/ext/leveldb/db/version_set.cc +1443 -0
- data/ext/leveldb/db/version_set.h +383 -0
- data/ext/leveldb/db/version_set_test.cc +179 -0
- data/ext/leveldb/db/write_batch.cc +147 -0
- data/ext/leveldb/db/write_batch_internal.h +49 -0
- data/ext/leveldb/db/write_batch_test.cc +120 -0
- data/ext/leveldb/doc/bench/db_bench_sqlite3.cc +718 -0
- data/ext/leveldb/doc/bench/db_bench_tree_db.cc +528 -0
- data/ext/leveldb/helpers/memenv/memenv.cc +384 -0
- data/ext/leveldb/helpers/memenv/memenv.h +20 -0
- data/ext/leveldb/helpers/memenv/memenv_test.cc +232 -0
- data/ext/leveldb/include/leveldb/c.h +291 -0
- data/ext/leveldb/include/leveldb/cache.h +99 -0
- data/ext/leveldb/include/leveldb/comparator.h +63 -0
- data/ext/leveldb/include/leveldb/db.h +161 -0
- data/ext/leveldb/include/leveldb/env.h +333 -0
- data/ext/leveldb/include/leveldb/filter_policy.h +70 -0
- data/ext/leveldb/include/leveldb/iterator.h +100 -0
- data/ext/leveldb/include/leveldb/options.h +195 -0
- data/ext/leveldb/include/leveldb/slice.h +109 -0
- data/ext/leveldb/include/leveldb/status.h +106 -0
- data/ext/leveldb/include/leveldb/table.h +85 -0
- data/ext/leveldb/include/leveldb/table_builder.h +92 -0
- data/ext/leveldb/include/leveldb/write_batch.h +64 -0
- data/ext/leveldb/issues/issue178_test.cc +92 -0
- data/ext/leveldb/port/atomic_pointer.h +224 -0
- data/ext/leveldb/port/port.h +19 -0
- data/ext/leveldb/port/port_example.h +135 -0
- data/ext/leveldb/port/port_posix.cc +54 -0
- data/ext/leveldb/port/port_posix.h +157 -0
- data/ext/leveldb/port/thread_annotations.h +59 -0
- data/ext/leveldb/port/win/stdint.h +24 -0
- data/ext/leveldb/table/block.cc +268 -0
- data/ext/leveldb/table/block.h +44 -0
- data/ext/leveldb/table/block_builder.cc +109 -0
- data/ext/leveldb/table/block_builder.h +57 -0
- data/ext/leveldb/table/filter_block.cc +111 -0
- data/ext/leveldb/table/filter_block.h +68 -0
- data/ext/leveldb/table/filter_block_test.cc +128 -0
- data/ext/leveldb/table/format.cc +145 -0
- data/ext/leveldb/table/format.h +108 -0
- data/ext/leveldb/table/iterator.cc +67 -0
- data/ext/leveldb/table/iterator_wrapper.h +63 -0
- data/ext/leveldb/table/merger.cc +197 -0
- data/ext/leveldb/table/merger.h +26 -0
- data/ext/leveldb/table/table.cc +275 -0
- data/ext/leveldb/table/table_builder.cc +270 -0
- data/ext/leveldb/table/table_test.cc +868 -0
- data/ext/leveldb/table/two_level_iterator.cc +182 -0
- data/ext/leveldb/table/two_level_iterator.h +34 -0
- data/ext/leveldb/util/arena.cc +68 -0
- data/ext/leveldb/util/arena.h +68 -0
- data/ext/leveldb/util/arena_test.cc +68 -0
- data/ext/leveldb/util/bloom.cc +95 -0
- data/ext/leveldb/util/bloom_test.cc +160 -0
- data/ext/leveldb/util/cache.cc +325 -0
- data/ext/leveldb/util/cache_test.cc +186 -0
- data/ext/leveldb/util/coding.cc +194 -0
- data/ext/leveldb/util/coding.h +104 -0
- data/ext/leveldb/util/coding_test.cc +196 -0
- data/ext/leveldb/util/comparator.cc +81 -0
- data/ext/leveldb/util/crc32c.cc +332 -0
- data/ext/leveldb/util/crc32c.h +45 -0
- data/ext/leveldb/util/crc32c_test.cc +72 -0
- data/ext/leveldb/util/env.cc +96 -0
- data/ext/leveldb/util/env_posix.cc +698 -0
- data/ext/leveldb/util/env_test.cc +104 -0
- data/ext/leveldb/util/filter_policy.cc +11 -0
- data/ext/leveldb/util/hash.cc +52 -0
- data/ext/leveldb/util/hash.h +19 -0
- data/ext/leveldb/util/histogram.cc +139 -0
- data/ext/leveldb/util/histogram.h +42 -0
- data/ext/leveldb/util/logging.cc +81 -0
- data/ext/leveldb/util/logging.h +47 -0
- data/ext/leveldb/util/mutexlock.h +41 -0
- data/ext/leveldb/util/options.cc +29 -0
- data/ext/leveldb/util/posix_logger.h +98 -0
- data/ext/leveldb/util/random.h +59 -0
- data/ext/leveldb/util/status.cc +75 -0
- data/ext/leveldb/util/testharness.cc +77 -0
- data/ext/leveldb/util/testharness.h +138 -0
- data/ext/leveldb/util/testutil.cc +51 -0
- data/ext/leveldb/util/testutil.h +53 -0
- data/lib/leveldb/version.rb +3 -0
- data/lib/leveldb.rb +1006 -0
- metadata +228 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
4
|
+
|
|
5
|
+
#ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_
|
|
6
|
+
#define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_
|
|
7
|
+
|
|
8
|
+
#include "leveldb/write_batch.h"
|
|
9
|
+
|
|
10
|
+
namespace leveldb {
|
|
11
|
+
|
|
12
|
+
class MemTable;
|
|
13
|
+
|
|
14
|
+
// WriteBatchInternal provides static methods for manipulating a
|
|
15
|
+
// WriteBatch that we don't want in the public WriteBatch interface.
|
|
16
|
+
class WriteBatchInternal {
|
|
17
|
+
public:
|
|
18
|
+
// Return the number of entries in the batch.
|
|
19
|
+
static int Count(const WriteBatch* batch);
|
|
20
|
+
|
|
21
|
+
// Set the count for the number of entries in the batch.
|
|
22
|
+
static void SetCount(WriteBatch* batch, int n);
|
|
23
|
+
|
|
24
|
+
// Return the seqeunce number for the start of this batch.
|
|
25
|
+
static SequenceNumber Sequence(const WriteBatch* batch);
|
|
26
|
+
|
|
27
|
+
// Store the specified number as the seqeunce number for the start of
|
|
28
|
+
// this batch.
|
|
29
|
+
static void SetSequence(WriteBatch* batch, SequenceNumber seq);
|
|
30
|
+
|
|
31
|
+
static Slice Contents(const WriteBatch* batch) {
|
|
32
|
+
return Slice(batch->rep_);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static size_t ByteSize(const WriteBatch* batch) {
|
|
36
|
+
return batch->rep_.size();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static void SetContents(WriteBatch* batch, const Slice& contents);
|
|
40
|
+
|
|
41
|
+
static Status InsertInto(const WriteBatch* batch, MemTable* memtable);
|
|
42
|
+
|
|
43
|
+
static void Append(WriteBatch* dst, const WriteBatch* src);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
} // namespace leveldb
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
#endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
4
|
+
|
|
5
|
+
#include "leveldb/db.h"
|
|
6
|
+
|
|
7
|
+
#include "db/memtable.h"
|
|
8
|
+
#include "db/write_batch_internal.h"
|
|
9
|
+
#include "leveldb/env.h"
|
|
10
|
+
#include "util/logging.h"
|
|
11
|
+
#include "util/testharness.h"
|
|
12
|
+
|
|
13
|
+
namespace leveldb {
|
|
14
|
+
|
|
15
|
+
static std::string PrintContents(WriteBatch* b) {
|
|
16
|
+
InternalKeyComparator cmp(BytewiseComparator());
|
|
17
|
+
MemTable* mem = new MemTable(cmp);
|
|
18
|
+
mem->Ref();
|
|
19
|
+
std::string state;
|
|
20
|
+
Status s = WriteBatchInternal::InsertInto(b, mem);
|
|
21
|
+
int count = 0;
|
|
22
|
+
Iterator* iter = mem->NewIterator();
|
|
23
|
+
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
|
24
|
+
ParsedInternalKey ikey;
|
|
25
|
+
ASSERT_TRUE(ParseInternalKey(iter->key(), &ikey));
|
|
26
|
+
switch (ikey.type) {
|
|
27
|
+
case kTypeValue:
|
|
28
|
+
state.append("Put(");
|
|
29
|
+
state.append(ikey.user_key.ToString());
|
|
30
|
+
state.append(", ");
|
|
31
|
+
state.append(iter->value().ToString());
|
|
32
|
+
state.append(")");
|
|
33
|
+
count++;
|
|
34
|
+
break;
|
|
35
|
+
case kTypeDeletion:
|
|
36
|
+
state.append("Delete(");
|
|
37
|
+
state.append(ikey.user_key.ToString());
|
|
38
|
+
state.append(")");
|
|
39
|
+
count++;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
state.append("@");
|
|
43
|
+
state.append(NumberToString(ikey.sequence));
|
|
44
|
+
}
|
|
45
|
+
delete iter;
|
|
46
|
+
if (!s.ok()) {
|
|
47
|
+
state.append("ParseError()");
|
|
48
|
+
} else if (count != WriteBatchInternal::Count(b)) {
|
|
49
|
+
state.append("CountMismatch()");
|
|
50
|
+
}
|
|
51
|
+
mem->Unref();
|
|
52
|
+
return state;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
class WriteBatchTest { };
|
|
56
|
+
|
|
57
|
+
TEST(WriteBatchTest, Empty) {
|
|
58
|
+
WriteBatch batch;
|
|
59
|
+
ASSERT_EQ("", PrintContents(&batch));
|
|
60
|
+
ASSERT_EQ(0, WriteBatchInternal::Count(&batch));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
TEST(WriteBatchTest, Multiple) {
|
|
64
|
+
WriteBatch batch;
|
|
65
|
+
batch.Put(Slice("foo"), Slice("bar"));
|
|
66
|
+
batch.Delete(Slice("box"));
|
|
67
|
+
batch.Put(Slice("baz"), Slice("boo"));
|
|
68
|
+
WriteBatchInternal::SetSequence(&batch, 100);
|
|
69
|
+
ASSERT_EQ(100, WriteBatchInternal::Sequence(&batch));
|
|
70
|
+
ASSERT_EQ(3, WriteBatchInternal::Count(&batch));
|
|
71
|
+
ASSERT_EQ("Put(baz, boo)@102"
|
|
72
|
+
"Delete(box)@101"
|
|
73
|
+
"Put(foo, bar)@100",
|
|
74
|
+
PrintContents(&batch));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
TEST(WriteBatchTest, Corruption) {
|
|
78
|
+
WriteBatch batch;
|
|
79
|
+
batch.Put(Slice("foo"), Slice("bar"));
|
|
80
|
+
batch.Delete(Slice("box"));
|
|
81
|
+
WriteBatchInternal::SetSequence(&batch, 200);
|
|
82
|
+
Slice contents = WriteBatchInternal::Contents(&batch);
|
|
83
|
+
WriteBatchInternal::SetContents(&batch,
|
|
84
|
+
Slice(contents.data(),contents.size()-1));
|
|
85
|
+
ASSERT_EQ("Put(foo, bar)@200"
|
|
86
|
+
"ParseError()",
|
|
87
|
+
PrintContents(&batch));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
TEST(WriteBatchTest, Append) {
|
|
91
|
+
WriteBatch b1, b2;
|
|
92
|
+
WriteBatchInternal::SetSequence(&b1, 200);
|
|
93
|
+
WriteBatchInternal::SetSequence(&b2, 300);
|
|
94
|
+
WriteBatchInternal::Append(&b1, &b2);
|
|
95
|
+
ASSERT_EQ("",
|
|
96
|
+
PrintContents(&b1));
|
|
97
|
+
b2.Put("a", "va");
|
|
98
|
+
WriteBatchInternal::Append(&b1, &b2);
|
|
99
|
+
ASSERT_EQ("Put(a, va)@200",
|
|
100
|
+
PrintContents(&b1));
|
|
101
|
+
b2.Clear();
|
|
102
|
+
b2.Put("b", "vb");
|
|
103
|
+
WriteBatchInternal::Append(&b1, &b2);
|
|
104
|
+
ASSERT_EQ("Put(a, va)@200"
|
|
105
|
+
"Put(b, vb)@201",
|
|
106
|
+
PrintContents(&b1));
|
|
107
|
+
b2.Delete("foo");
|
|
108
|
+
WriteBatchInternal::Append(&b1, &b2);
|
|
109
|
+
ASSERT_EQ("Put(a, va)@200"
|
|
110
|
+
"Put(b, vb)@202"
|
|
111
|
+
"Put(b, vb)@201"
|
|
112
|
+
"Delete(foo)@203",
|
|
113
|
+
PrintContents(&b1));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
} // namespace leveldb
|
|
117
|
+
|
|
118
|
+
int main(int argc, char** argv) {
|
|
119
|
+
return leveldb::test::RunAllTests();
|
|
120
|
+
}
|