leveldb-ruby 0.7 → 0.8
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.
- data/README +1 -1
- data/leveldb/Makefile +70 -29
- data/leveldb/build_detect_platform +74 -0
- data/leveldb/db/builder.cc +2 -4
- data/leveldb/db/builder.h +4 -6
- data/leveldb/db/c.cc +471 -0
- data/leveldb/db/corruption_test.cc +21 -16
- data/leveldb/db/db_bench.cc +400 -200
- data/leveldb/db/db_impl.cc +276 -131
- data/leveldb/db/db_impl.h +22 -10
- data/leveldb/db/db_iter.cc +2 -1
- data/leveldb/db/db_test.cc +391 -43
- data/leveldb/db/dbformat.cc +31 -0
- data/leveldb/db/dbformat.h +51 -1
- data/leveldb/db/filename.h +1 -1
- data/leveldb/db/log_format.h +1 -1
- data/leveldb/db/log_reader.cc +16 -11
- data/leveldb/db/memtable.cc +37 -0
- data/leveldb/db/memtable.h +6 -0
- data/leveldb/db/repair.cc +17 -14
- data/leveldb/db/skiplist_test.cc +2 -2
- data/leveldb/db/version_edit.cc +7 -9
- data/leveldb/db/version_edit.h +2 -1
- data/leveldb/db/version_set.cc +416 -104
- data/leveldb/db/version_set.h +78 -14
- data/leveldb/db/version_set_test.cc +179 -0
- data/leveldb/db/write_batch_internal.h +2 -0
- data/leveldb/include/leveldb/c.h +246 -0
- data/leveldb/include/leveldb/db.h +14 -2
- data/leveldb/include/leveldb/env.h +31 -10
- data/leveldb/include/leveldb/options.h +7 -18
- data/leveldb/include/leveldb/slice.h +2 -2
- data/leveldb/include/leveldb/status.h +1 -1
- data/leveldb/port/atomic_pointer.h +144 -0
- data/leveldb/port/port.h +0 -2
- data/leveldb/port/port_android.h +7 -1
- data/leveldb/port/port_example.h +11 -1
- data/leveldb/port/port_posix.h +56 -38
- data/leveldb/table/format.cc +12 -8
- data/leveldb/table/table_test.cc +16 -7
- data/leveldb/util/cache.cc +173 -100
- data/leveldb/util/cache_test.cc +28 -11
- data/leveldb/util/coding.h +4 -4
- data/leveldb/util/comparator.cc +1 -0
- data/leveldb/util/env.cc +10 -5
- data/leveldb/util/env_posix.cc +48 -87
- data/leveldb/util/histogram.cc +11 -0
- data/leveldb/util/histogram.h +1 -0
- data/leveldb/util/posix_logger.h +98 -0
- data/leveldb/util/testharness.cc +12 -0
- data/leveldb/util/testharness.h +10 -1
- data/lib/leveldb.rb +11 -3
- metadata +41 -22
data/leveldb/db/version_set.h
CHANGED
@@ -35,6 +35,26 @@ class Version;
|
|
35
35
|
class VersionSet;
|
36
36
|
class WritableFile;
|
37
37
|
|
38
|
+
// Return the smallest index i such that files[i]->largest >= key.
|
39
|
+
// Return files.size() if there is no such file.
|
40
|
+
// REQUIRES: "files" contains a sorted list of non-overlapping files.
|
41
|
+
extern int FindFile(const InternalKeyComparator& icmp,
|
42
|
+
const std::vector<FileMetaData*>& files,
|
43
|
+
const Slice& key);
|
44
|
+
|
45
|
+
// Returns true iff some file in "files" overlaps the user key range
|
46
|
+
// [*smallest,*largest].
|
47
|
+
// smallest==NULL represents a key smaller than all keys in the DB.
|
48
|
+
// largest==NULL represents a key largest than all keys in the DB.
|
49
|
+
// REQUIRES: If disjoint_sorted_files, files[] contains disjoint ranges
|
50
|
+
// in sorted order.
|
51
|
+
extern bool SomeFileOverlapsRange(
|
52
|
+
const InternalKeyComparator& icmp,
|
53
|
+
bool disjoint_sorted_files,
|
54
|
+
const std::vector<FileMetaData*>& files,
|
55
|
+
const Slice* smallest_user_key,
|
56
|
+
const Slice* largest_user_key);
|
57
|
+
|
38
58
|
class Version {
|
39
59
|
public:
|
40
60
|
// Append to *iters a sequence of iterators that will
|
@@ -42,11 +62,47 @@ class Version {
|
|
42
62
|
// REQUIRES: This version has been saved (see VersionSet::SaveTo)
|
43
63
|
void AddIterators(const ReadOptions&, std::vector<Iterator*>* iters);
|
44
64
|
|
65
|
+
// Lookup the value for key. If found, store it in *val and
|
66
|
+
// return OK. Else return a non-OK status. Fills *stats.
|
67
|
+
// REQUIRES: lock is not held
|
68
|
+
struct GetStats {
|
69
|
+
FileMetaData* seek_file;
|
70
|
+
int seek_file_level;
|
71
|
+
};
|
72
|
+
Status Get(const ReadOptions&, const LookupKey& key, std::string* val,
|
73
|
+
GetStats* stats);
|
74
|
+
|
75
|
+
// Adds "stats" into the current state. Returns true if a new
|
76
|
+
// compaction may need to be triggered, false otherwise.
|
77
|
+
// REQUIRES: lock is held
|
78
|
+
bool UpdateStats(const GetStats& stats);
|
79
|
+
|
45
80
|
// Reference count management (so Versions do not disappear out from
|
46
81
|
// under live iterators)
|
47
82
|
void Ref();
|
48
83
|
void Unref();
|
49
84
|
|
85
|
+
void GetOverlappingInputs(
|
86
|
+
int level,
|
87
|
+
const InternalKey* begin, // NULL means before all keys
|
88
|
+
const InternalKey* end, // NULL means after all keys
|
89
|
+
std::vector<FileMetaData*>* inputs);
|
90
|
+
|
91
|
+
// Returns true iff some file in the specified level overlaps
|
92
|
+
// some part of [*smallest_user_key,*largest_user_key].
|
93
|
+
// smallest_user_key==NULL represents a key smaller than all keys in the DB.
|
94
|
+
// largest_user_key==NULL represents a key largest than all keys in the DB.
|
95
|
+
bool OverlapInLevel(int level,
|
96
|
+
const Slice* smallest_user_key,
|
97
|
+
const Slice* largest_user_key);
|
98
|
+
|
99
|
+
// Return the level at which we should place a new memtable compaction
|
100
|
+
// result that covers the range [smallest_user_key,largest_user_key].
|
101
|
+
int PickLevelForMemTableOutput(const Slice& smallest_user_key,
|
102
|
+
const Slice& largest_user_key);
|
103
|
+
|
104
|
+
int NumFiles(int level) const { return files_[level].size(); }
|
105
|
+
|
50
106
|
// Return a human readable string that describes this version's contents.
|
51
107
|
std::string DebugString() const;
|
52
108
|
|
@@ -65,6 +121,10 @@ class Version {
|
|
65
121
|
// List of files per level
|
66
122
|
std::vector<FileMetaData*> files_[config::kNumLevels];
|
67
123
|
|
124
|
+
// Next file to compact based on seek stats.
|
125
|
+
FileMetaData* file_to_compact_;
|
126
|
+
int file_to_compact_level_;
|
127
|
+
|
68
128
|
// Level that should be compacted next and its compaction score.
|
69
129
|
// Score < 1 means compaction is not strictly needed. These fields
|
70
130
|
// are initialized by Finalize().
|
@@ -73,6 +133,8 @@ class Version {
|
|
73
133
|
|
74
134
|
explicit Version(VersionSet* vset)
|
75
135
|
: vset_(vset), next_(this), prev_(this), refs_(0),
|
136
|
+
file_to_compact_(NULL),
|
137
|
+
file_to_compact_level_(-1),
|
76
138
|
compaction_score_(-1),
|
77
139
|
compaction_level_(-1) {
|
78
140
|
}
|
@@ -94,15 +156,14 @@ class VersionSet {
|
|
94
156
|
|
95
157
|
// Apply *edit to the current version to form a new descriptor that
|
96
158
|
// is both saved to persistent state and installed as the new
|
97
|
-
// current version.
|
98
|
-
|
159
|
+
// current version. Will release *mu while actually writing to the file.
|
160
|
+
// REQUIRES: *mu is held on entry.
|
161
|
+
// REQUIRES: no other thread concurrently calls LogAndApply()
|
162
|
+
Status LogAndApply(VersionEdit* edit, port::Mutex* mu);
|
99
163
|
|
100
164
|
// Recover the last saved descriptor from persistent storage.
|
101
165
|
Status Recover();
|
102
166
|
|
103
|
-
// Save current contents to *log
|
104
|
-
Status WriteSnapshot(log::Writer* log);
|
105
|
-
|
106
167
|
// Return the current version.
|
107
168
|
Version* current() const { return current_; }
|
108
169
|
|
@@ -127,6 +188,9 @@ class VersionSet {
|
|
127
188
|
last_sequence_ = s;
|
128
189
|
}
|
129
190
|
|
191
|
+
// Mark the specified file number as used.
|
192
|
+
void MarkFileNumberUsed(uint64_t number);
|
193
|
+
|
130
194
|
// Return the current log file number.
|
131
195
|
uint64_t LogNumber() const { return log_number_; }
|
132
196
|
|
@@ -146,8 +210,8 @@ class VersionSet {
|
|
146
210
|
// the result.
|
147
211
|
Compaction* CompactRange(
|
148
212
|
int level,
|
149
|
-
const InternalKey
|
150
|
-
const InternalKey
|
213
|
+
const InternalKey* begin,
|
214
|
+
const InternalKey* end);
|
151
215
|
|
152
216
|
// Return the maximum overlapping data (in bytes) at next level for any
|
153
217
|
// file at a level >= 1.
|
@@ -158,7 +222,10 @@ class VersionSet {
|
|
158
222
|
Iterator* MakeInputIterator(Compaction* c);
|
159
223
|
|
160
224
|
// Returns true iff some level needs a compaction.
|
161
|
-
bool NeedsCompaction() const {
|
225
|
+
bool NeedsCompaction() const {
|
226
|
+
Version* v = current_;
|
227
|
+
return (v->compaction_score_ >= 1) || (v->file_to_compact_ != NULL);
|
228
|
+
}
|
162
229
|
|
163
230
|
// Add all files listed in any live version to *live.
|
164
231
|
// May also mutate some internal state.
|
@@ -183,12 +250,6 @@ class VersionSet {
|
|
183
250
|
|
184
251
|
void Finalize(Version* v);
|
185
252
|
|
186
|
-
void GetOverlappingInputs(
|
187
|
-
int level,
|
188
|
-
const InternalKey& begin,
|
189
|
-
const InternalKey& end,
|
190
|
-
std::vector<FileMetaData*>* inputs);
|
191
|
-
|
192
253
|
void GetRange(const std::vector<FileMetaData*>& inputs,
|
193
254
|
InternalKey* smallest,
|
194
255
|
InternalKey* largest);
|
@@ -200,6 +261,9 @@ class VersionSet {
|
|
200
261
|
|
201
262
|
void SetupOtherInputs(Compaction* c);
|
202
263
|
|
264
|
+
// Save current contents to *log
|
265
|
+
Status WriteSnapshot(log::Writer* log);
|
266
|
+
|
203
267
|
void AppendVersion(Version* v);
|
204
268
|
|
205
269
|
Env* const env_;
|
@@ -0,0 +1,179 @@
|
|
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 "db/version_set.h"
|
6
|
+
#include "util/logging.h"
|
7
|
+
#include "util/testharness.h"
|
8
|
+
#include "util/testutil.h"
|
9
|
+
|
10
|
+
namespace leveldb {
|
11
|
+
|
12
|
+
class FindFileTest {
|
13
|
+
public:
|
14
|
+
std::vector<FileMetaData*> files_;
|
15
|
+
bool disjoint_sorted_files_;
|
16
|
+
|
17
|
+
FindFileTest() : disjoint_sorted_files_(true) { }
|
18
|
+
|
19
|
+
~FindFileTest() {
|
20
|
+
for (int i = 0; i < files_.size(); i++) {
|
21
|
+
delete files_[i];
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
void Add(const char* smallest, const char* largest,
|
26
|
+
SequenceNumber smallest_seq = 100,
|
27
|
+
SequenceNumber largest_seq = 100) {
|
28
|
+
FileMetaData* f = new FileMetaData;
|
29
|
+
f->number = files_.size() + 1;
|
30
|
+
f->smallest = InternalKey(smallest, smallest_seq, kTypeValue);
|
31
|
+
f->largest = InternalKey(largest, largest_seq, kTypeValue);
|
32
|
+
files_.push_back(f);
|
33
|
+
}
|
34
|
+
|
35
|
+
int Find(const char* key) {
|
36
|
+
InternalKey target(key, 100, kTypeValue);
|
37
|
+
InternalKeyComparator cmp(BytewiseComparator());
|
38
|
+
return FindFile(cmp, files_, target.Encode());
|
39
|
+
}
|
40
|
+
|
41
|
+
bool Overlaps(const char* smallest, const char* largest) {
|
42
|
+
InternalKeyComparator cmp(BytewiseComparator());
|
43
|
+
Slice s(smallest != NULL ? smallest : "");
|
44
|
+
Slice l(largest != NULL ? largest : "");
|
45
|
+
return SomeFileOverlapsRange(cmp, disjoint_sorted_files_, files_,
|
46
|
+
(smallest != NULL ? &s : NULL),
|
47
|
+
(largest != NULL ? &l : NULL));
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
TEST(FindFileTest, Empty) {
|
52
|
+
ASSERT_EQ(0, Find("foo"));
|
53
|
+
ASSERT_TRUE(! Overlaps("a", "z"));
|
54
|
+
ASSERT_TRUE(! Overlaps(NULL, "z"));
|
55
|
+
ASSERT_TRUE(! Overlaps("a", NULL));
|
56
|
+
ASSERT_TRUE(! Overlaps(NULL, NULL));
|
57
|
+
}
|
58
|
+
|
59
|
+
TEST(FindFileTest, Single) {
|
60
|
+
Add("p", "q");
|
61
|
+
ASSERT_EQ(0, Find("a"));
|
62
|
+
ASSERT_EQ(0, Find("p"));
|
63
|
+
ASSERT_EQ(0, Find("p1"));
|
64
|
+
ASSERT_EQ(0, Find("q"));
|
65
|
+
ASSERT_EQ(1, Find("q1"));
|
66
|
+
ASSERT_EQ(1, Find("z"));
|
67
|
+
|
68
|
+
ASSERT_TRUE(! Overlaps("a", "b"));
|
69
|
+
ASSERT_TRUE(! Overlaps("z1", "z2"));
|
70
|
+
ASSERT_TRUE(Overlaps("a", "p"));
|
71
|
+
ASSERT_TRUE(Overlaps("a", "q"));
|
72
|
+
ASSERT_TRUE(Overlaps("a", "z"));
|
73
|
+
ASSERT_TRUE(Overlaps("p", "p1"));
|
74
|
+
ASSERT_TRUE(Overlaps("p", "q"));
|
75
|
+
ASSERT_TRUE(Overlaps("p", "z"));
|
76
|
+
ASSERT_TRUE(Overlaps("p1", "p2"));
|
77
|
+
ASSERT_TRUE(Overlaps("p1", "z"));
|
78
|
+
ASSERT_TRUE(Overlaps("q", "q"));
|
79
|
+
ASSERT_TRUE(Overlaps("q", "q1"));
|
80
|
+
|
81
|
+
ASSERT_TRUE(! Overlaps(NULL, "j"));
|
82
|
+
ASSERT_TRUE(! Overlaps("r", NULL));
|
83
|
+
ASSERT_TRUE(Overlaps(NULL, "p"));
|
84
|
+
ASSERT_TRUE(Overlaps(NULL, "p1"));
|
85
|
+
ASSERT_TRUE(Overlaps("q", NULL));
|
86
|
+
ASSERT_TRUE(Overlaps(NULL, NULL));
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
TEST(FindFileTest, Multiple) {
|
91
|
+
Add("150", "200");
|
92
|
+
Add("200", "250");
|
93
|
+
Add("300", "350");
|
94
|
+
Add("400", "450");
|
95
|
+
ASSERT_EQ(0, Find("100"));
|
96
|
+
ASSERT_EQ(0, Find("150"));
|
97
|
+
ASSERT_EQ(0, Find("151"));
|
98
|
+
ASSERT_EQ(0, Find("199"));
|
99
|
+
ASSERT_EQ(0, Find("200"));
|
100
|
+
ASSERT_EQ(1, Find("201"));
|
101
|
+
ASSERT_EQ(1, Find("249"));
|
102
|
+
ASSERT_EQ(1, Find("250"));
|
103
|
+
ASSERT_EQ(2, Find("251"));
|
104
|
+
ASSERT_EQ(2, Find("299"));
|
105
|
+
ASSERT_EQ(2, Find("300"));
|
106
|
+
ASSERT_EQ(2, Find("349"));
|
107
|
+
ASSERT_EQ(2, Find("350"));
|
108
|
+
ASSERT_EQ(3, Find("351"));
|
109
|
+
ASSERT_EQ(3, Find("400"));
|
110
|
+
ASSERT_EQ(3, Find("450"));
|
111
|
+
ASSERT_EQ(4, Find("451"));
|
112
|
+
|
113
|
+
ASSERT_TRUE(! Overlaps("100", "149"));
|
114
|
+
ASSERT_TRUE(! Overlaps("251", "299"));
|
115
|
+
ASSERT_TRUE(! Overlaps("451", "500"));
|
116
|
+
ASSERT_TRUE(! Overlaps("351", "399"));
|
117
|
+
|
118
|
+
ASSERT_TRUE(Overlaps("100", "150"));
|
119
|
+
ASSERT_TRUE(Overlaps("100", "200"));
|
120
|
+
ASSERT_TRUE(Overlaps("100", "300"));
|
121
|
+
ASSERT_TRUE(Overlaps("100", "400"));
|
122
|
+
ASSERT_TRUE(Overlaps("100", "500"));
|
123
|
+
ASSERT_TRUE(Overlaps("375", "400"));
|
124
|
+
ASSERT_TRUE(Overlaps("450", "450"));
|
125
|
+
ASSERT_TRUE(Overlaps("450", "500"));
|
126
|
+
}
|
127
|
+
|
128
|
+
TEST(FindFileTest, MultipleNullBoundaries) {
|
129
|
+
Add("150", "200");
|
130
|
+
Add("200", "250");
|
131
|
+
Add("300", "350");
|
132
|
+
Add("400", "450");
|
133
|
+
ASSERT_TRUE(! Overlaps(NULL, "149"));
|
134
|
+
ASSERT_TRUE(! Overlaps("451", NULL));
|
135
|
+
ASSERT_TRUE(Overlaps(NULL, NULL));
|
136
|
+
ASSERT_TRUE(Overlaps(NULL, "150"));
|
137
|
+
ASSERT_TRUE(Overlaps(NULL, "199"));
|
138
|
+
ASSERT_TRUE(Overlaps(NULL, "200"));
|
139
|
+
ASSERT_TRUE(Overlaps(NULL, "201"));
|
140
|
+
ASSERT_TRUE(Overlaps(NULL, "400"));
|
141
|
+
ASSERT_TRUE(Overlaps(NULL, "800"));
|
142
|
+
ASSERT_TRUE(Overlaps("100", NULL));
|
143
|
+
ASSERT_TRUE(Overlaps("200", NULL));
|
144
|
+
ASSERT_TRUE(Overlaps("449", NULL));
|
145
|
+
ASSERT_TRUE(Overlaps("450", NULL));
|
146
|
+
}
|
147
|
+
|
148
|
+
TEST(FindFileTest, OverlapSequenceChecks) {
|
149
|
+
Add("200", "200", 5000, 3000);
|
150
|
+
ASSERT_TRUE(! Overlaps("199", "199"));
|
151
|
+
ASSERT_TRUE(! Overlaps("201", "300"));
|
152
|
+
ASSERT_TRUE(Overlaps("200", "200"));
|
153
|
+
ASSERT_TRUE(Overlaps("190", "200"));
|
154
|
+
ASSERT_TRUE(Overlaps("200", "210"));
|
155
|
+
}
|
156
|
+
|
157
|
+
TEST(FindFileTest, OverlappingFiles) {
|
158
|
+
Add("150", "600");
|
159
|
+
Add("400", "500");
|
160
|
+
disjoint_sorted_files_ = false;
|
161
|
+
ASSERT_TRUE(! Overlaps("100", "149"));
|
162
|
+
ASSERT_TRUE(! Overlaps("601", "700"));
|
163
|
+
ASSERT_TRUE(Overlaps("100", "150"));
|
164
|
+
ASSERT_TRUE(Overlaps("100", "200"));
|
165
|
+
ASSERT_TRUE(Overlaps("100", "300"));
|
166
|
+
ASSERT_TRUE(Overlaps("100", "400"));
|
167
|
+
ASSERT_TRUE(Overlaps("100", "500"));
|
168
|
+
ASSERT_TRUE(Overlaps("375", "400"));
|
169
|
+
ASSERT_TRUE(Overlaps("450", "450"));
|
170
|
+
ASSERT_TRUE(Overlaps("450", "500"));
|
171
|
+
ASSERT_TRUE(Overlaps("450", "700"));
|
172
|
+
ASSERT_TRUE(Overlaps("600", "700"));
|
173
|
+
}
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
int main(int argc, char** argv) {
|
178
|
+
return leveldb::test::RunAllTests();
|
179
|
+
}
|
@@ -0,0 +1,246 @@
|
|
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
|
+
C bindings for leveldb. May be useful as a stable ABI that can be
|
6
|
+
used by programs that keep leveldb in a shared library, or for
|
7
|
+
a JNI api.
|
8
|
+
|
9
|
+
Does not support:
|
10
|
+
. getters for the option types
|
11
|
+
. custom comparators that implement key shortening
|
12
|
+
. capturing post-write-snapshot
|
13
|
+
. custom iter, db, env, cache implementations using just the C bindings
|
14
|
+
|
15
|
+
Some conventions:
|
16
|
+
|
17
|
+
(1) We expose just opaque struct pointers and functions to clients.
|
18
|
+
This allows us to change internal representations without having to
|
19
|
+
recompile clients.
|
20
|
+
|
21
|
+
(2) For simplicity, there is no equivalent to the Slice type. Instead,
|
22
|
+
the caller has to pass the pointer and length as separate
|
23
|
+
arguments.
|
24
|
+
|
25
|
+
(3) Errors are represented by a null-terminated c string. NULL
|
26
|
+
means no error. All operations that can raise an error are passed
|
27
|
+
a "char** errptr" as the last argument. One of the following must
|
28
|
+
be true on entry:
|
29
|
+
*errptr == NULL
|
30
|
+
*errptr points to a malloc()ed null-terminated error message
|
31
|
+
On success, a leveldb routine leaves *errptr unchanged.
|
32
|
+
On failure, leveldb frees the old value of *errptr and
|
33
|
+
set *errptr to a malloc()ed error message.
|
34
|
+
|
35
|
+
(4) Bools have the type unsigned char (0 == false; rest == true)
|
36
|
+
|
37
|
+
(5) All of the pointer arguments must be non-NULL.
|
38
|
+
*/
|
39
|
+
|
40
|
+
#ifndef STORAGE_LEVELDB_INCLUDE_C_H_
|
41
|
+
#define STORAGE_LEVELDB_INCLUDE_C_H_
|
42
|
+
|
43
|
+
#ifdef __cplusplus
|
44
|
+
extern "C" {
|
45
|
+
#endif
|
46
|
+
|
47
|
+
#include <stdarg.h>
|
48
|
+
#include <stddef.h>
|
49
|
+
#include <stdint.h>
|
50
|
+
|
51
|
+
/* Exported types */
|
52
|
+
|
53
|
+
typedef struct leveldb_t leveldb_t;
|
54
|
+
typedef struct leveldb_cache_t leveldb_cache_t;
|
55
|
+
typedef struct leveldb_comparator_t leveldb_comparator_t;
|
56
|
+
typedef struct leveldb_env_t leveldb_env_t;
|
57
|
+
typedef struct leveldb_filelock_t leveldb_filelock_t;
|
58
|
+
typedef struct leveldb_iterator_t leveldb_iterator_t;
|
59
|
+
typedef struct leveldb_logger_t leveldb_logger_t;
|
60
|
+
typedef struct leveldb_options_t leveldb_options_t;
|
61
|
+
typedef struct leveldb_randomfile_t leveldb_randomfile_t;
|
62
|
+
typedef struct leveldb_readoptions_t leveldb_readoptions_t;
|
63
|
+
typedef struct leveldb_seqfile_t leveldb_seqfile_t;
|
64
|
+
typedef struct leveldb_snapshot_t leveldb_snapshot_t;
|
65
|
+
typedef struct leveldb_writablefile_t leveldb_writablefile_t;
|
66
|
+
typedef struct leveldb_writebatch_t leveldb_writebatch_t;
|
67
|
+
typedef struct leveldb_writeoptions_t leveldb_writeoptions_t;
|
68
|
+
|
69
|
+
/* DB operations */
|
70
|
+
|
71
|
+
extern leveldb_t* leveldb_open(
|
72
|
+
const leveldb_options_t* options,
|
73
|
+
const char* name,
|
74
|
+
char** errptr);
|
75
|
+
|
76
|
+
extern void leveldb_close(leveldb_t* db);
|
77
|
+
|
78
|
+
extern void leveldb_put(
|
79
|
+
leveldb_t* db,
|
80
|
+
const leveldb_writeoptions_t* options,
|
81
|
+
const char* key, size_t keylen,
|
82
|
+
const char* val, size_t vallen,
|
83
|
+
char** errptr);
|
84
|
+
|
85
|
+
extern void leveldb_delete(
|
86
|
+
leveldb_t* db,
|
87
|
+
const leveldb_writeoptions_t* options,
|
88
|
+
const char* key, size_t keylen,
|
89
|
+
char** errptr);
|
90
|
+
|
91
|
+
extern void leveldb_write(
|
92
|
+
leveldb_t* db,
|
93
|
+
const leveldb_writeoptions_t* options,
|
94
|
+
leveldb_writebatch_t* batch,
|
95
|
+
char** errptr);
|
96
|
+
|
97
|
+
/* Returns NULL if not found. A malloc()ed array otherwise.
|
98
|
+
Stores the length of the array in *vallen. */
|
99
|
+
extern char* leveldb_get(
|
100
|
+
leveldb_t* db,
|
101
|
+
const leveldb_readoptions_t* options,
|
102
|
+
const char* key, size_t keylen,
|
103
|
+
size_t* vallen,
|
104
|
+
char** errptr);
|
105
|
+
|
106
|
+
extern leveldb_iterator_t* leveldb_create_iterator(
|
107
|
+
leveldb_t* db,
|
108
|
+
const leveldb_readoptions_t* options);
|
109
|
+
|
110
|
+
extern const leveldb_snapshot_t* leveldb_create_snapshot(
|
111
|
+
leveldb_t* db);
|
112
|
+
|
113
|
+
extern void leveldb_release_snapshot(
|
114
|
+
leveldb_t* db,
|
115
|
+
const leveldb_snapshot_t* snapshot);
|
116
|
+
|
117
|
+
/* Returns NULL if property name is unknown.
|
118
|
+
Else returns a pointer to a malloc()-ed null-terminated value. */
|
119
|
+
extern char* leveldb_property_value(
|
120
|
+
leveldb_t* db,
|
121
|
+
const char* propname);
|
122
|
+
|
123
|
+
extern void leveldb_approximate_sizes(
|
124
|
+
leveldb_t* db,
|
125
|
+
int num_ranges,
|
126
|
+
const char* const* range_start_key, const size_t* range_start_key_len,
|
127
|
+
const char* const* range_limit_key, const size_t* range_limit_key_len,
|
128
|
+
uint64_t* sizes);
|
129
|
+
|
130
|
+
/* Management operations */
|
131
|
+
|
132
|
+
extern void leveldb_destroy_db(
|
133
|
+
const leveldb_options_t* options,
|
134
|
+
const char* name,
|
135
|
+
char** errptr);
|
136
|
+
|
137
|
+
extern void leveldb_repair_db(
|
138
|
+
const leveldb_options_t* options,
|
139
|
+
const char* name,
|
140
|
+
char** errptr);
|
141
|
+
|
142
|
+
/* Iterator */
|
143
|
+
|
144
|
+
extern void leveldb_iter_destroy(leveldb_iterator_t*);
|
145
|
+
extern unsigned char leveldb_iter_valid(const leveldb_iterator_t*);
|
146
|
+
extern void leveldb_iter_seek_to_first(leveldb_iterator_t*);
|
147
|
+
extern void leveldb_iter_seek_to_last(leveldb_iterator_t*);
|
148
|
+
extern void leveldb_iter_seek(leveldb_iterator_t*, const char* k, size_t klen);
|
149
|
+
extern void leveldb_iter_next(leveldb_iterator_t*);
|
150
|
+
extern void leveldb_iter_prev(leveldb_iterator_t*);
|
151
|
+
extern const char* leveldb_iter_key(const leveldb_iterator_t*, size_t* klen);
|
152
|
+
extern const char* leveldb_iter_value(const leveldb_iterator_t*, size_t* vlen);
|
153
|
+
extern void leveldb_iter_get_error(const leveldb_iterator_t*, char** errptr);
|
154
|
+
|
155
|
+
/* Write batch */
|
156
|
+
|
157
|
+
extern leveldb_writebatch_t* leveldb_writebatch_create();
|
158
|
+
extern void leveldb_writebatch_destroy(leveldb_writebatch_t*);
|
159
|
+
extern void leveldb_writebatch_clear(leveldb_writebatch_t*);
|
160
|
+
extern void leveldb_writebatch_put(
|
161
|
+
leveldb_writebatch_t*,
|
162
|
+
const char* key, size_t klen,
|
163
|
+
const char* val, size_t vlen);
|
164
|
+
extern void leveldb_writebatch_delete(
|
165
|
+
leveldb_writebatch_t*,
|
166
|
+
const char* key, size_t klen);
|
167
|
+
extern void leveldb_writebatch_iterate(
|
168
|
+
leveldb_writebatch_t*,
|
169
|
+
void* state,
|
170
|
+
void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
|
171
|
+
void (*deleted)(void*, const char* k, size_t klen));
|
172
|
+
|
173
|
+
/* Options */
|
174
|
+
|
175
|
+
extern leveldb_options_t* leveldb_options_create();
|
176
|
+
extern void leveldb_options_destroy(leveldb_options_t*);
|
177
|
+
extern void leveldb_options_set_comparator(
|
178
|
+
leveldb_options_t*,
|
179
|
+
leveldb_comparator_t*);
|
180
|
+
extern void leveldb_options_set_create_if_missing(
|
181
|
+
leveldb_options_t*, unsigned char);
|
182
|
+
extern void leveldb_options_set_error_if_exists(
|
183
|
+
leveldb_options_t*, unsigned char);
|
184
|
+
extern void leveldb_options_set_paranoid_checks(
|
185
|
+
leveldb_options_t*, unsigned char);
|
186
|
+
extern void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*);
|
187
|
+
extern void leveldb_options_set_info_log(leveldb_options_t*, leveldb_logger_t*);
|
188
|
+
extern void leveldb_options_set_write_buffer_size(leveldb_options_t*, size_t);
|
189
|
+
extern void leveldb_options_set_max_open_files(leveldb_options_t*, int);
|
190
|
+
extern void leveldb_options_set_cache(leveldb_options_t*, leveldb_cache_t*);
|
191
|
+
extern void leveldb_options_set_block_size(leveldb_options_t*, size_t);
|
192
|
+
extern void leveldb_options_set_block_restart_interval(leveldb_options_t*, int);
|
193
|
+
|
194
|
+
enum {
|
195
|
+
leveldb_no_compression = 0,
|
196
|
+
leveldb_snappy_compression = 1
|
197
|
+
};
|
198
|
+
extern void leveldb_options_set_compression(leveldb_options_t*, int);
|
199
|
+
|
200
|
+
/* Comparator */
|
201
|
+
|
202
|
+
extern leveldb_comparator_t* leveldb_comparator_create(
|
203
|
+
void* state,
|
204
|
+
void (*destructor)(void*),
|
205
|
+
int (*compare)(
|
206
|
+
void*,
|
207
|
+
const char* a, size_t alen,
|
208
|
+
const char* b, size_t blen),
|
209
|
+
const char* (*name)(void*));
|
210
|
+
extern void leveldb_comparator_destroy(leveldb_comparator_t*);
|
211
|
+
|
212
|
+
/* Read options */
|
213
|
+
|
214
|
+
extern leveldb_readoptions_t* leveldb_readoptions_create();
|
215
|
+
extern void leveldb_readoptions_destroy(leveldb_readoptions_t*);
|
216
|
+
extern void leveldb_readoptions_set_verify_checksums(
|
217
|
+
leveldb_readoptions_t*,
|
218
|
+
unsigned char);
|
219
|
+
extern void leveldb_readoptions_set_fill_cache(
|
220
|
+
leveldb_readoptions_t*, unsigned char);
|
221
|
+
extern void leveldb_readoptions_set_snapshot(
|
222
|
+
leveldb_readoptions_t*,
|
223
|
+
const leveldb_snapshot_t*);
|
224
|
+
|
225
|
+
/* Write options */
|
226
|
+
|
227
|
+
extern leveldb_writeoptions_t* leveldb_writeoptions_create();
|
228
|
+
extern void leveldb_writeoptions_destroy(leveldb_writeoptions_t*);
|
229
|
+
extern void leveldb_writeoptions_set_sync(
|
230
|
+
leveldb_writeoptions_t*, unsigned char);
|
231
|
+
|
232
|
+
/* Cache */
|
233
|
+
|
234
|
+
extern leveldb_cache_t* leveldb_cache_create_lru(size_t capacity);
|
235
|
+
extern void leveldb_cache_destroy(leveldb_cache_t* cache);
|
236
|
+
|
237
|
+
/* Env */
|
238
|
+
|
239
|
+
extern leveldb_env_t* leveldb_create_default_env();
|
240
|
+
extern void leveldb_env_destroy(leveldb_env_t*);
|
241
|
+
|
242
|
+
#ifdef __cplusplus
|
243
|
+
} /* end extern "C" */
|
244
|
+
#endif
|
245
|
+
|
246
|
+
#endif /* STORAGE_LEVELDB_INCLUDE_C_H_ */
|