leveldb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +95 -0
  4. data/ext/Rakefile +11 -0
  5. data/ext/leveldb/LICENSE +27 -0
  6. data/ext/leveldb/Makefile +206 -0
  7. data/ext/leveldb/build_config.mk +13 -0
  8. data/ext/leveldb/db/builder.cc +88 -0
  9. data/ext/leveldb/db/builder.h +34 -0
  10. data/ext/leveldb/db/c.cc +595 -0
  11. data/ext/leveldb/db/c_test.c +390 -0
  12. data/ext/leveldb/db/corruption_test.cc +359 -0
  13. data/ext/leveldb/db/db_bench.cc +979 -0
  14. data/ext/leveldb/db/db_impl.cc +1485 -0
  15. data/ext/leveldb/db/db_impl.h +203 -0
  16. data/ext/leveldb/db/db_iter.cc +299 -0
  17. data/ext/leveldb/db/db_iter.h +26 -0
  18. data/ext/leveldb/db/db_test.cc +2092 -0
  19. data/ext/leveldb/db/dbformat.cc +140 -0
  20. data/ext/leveldb/db/dbformat.h +227 -0
  21. data/ext/leveldb/db/dbformat_test.cc +112 -0
  22. data/ext/leveldb/db/filename.cc +139 -0
  23. data/ext/leveldb/db/filename.h +80 -0
  24. data/ext/leveldb/db/filename_test.cc +122 -0
  25. data/ext/leveldb/db/leveldb_main.cc +238 -0
  26. data/ext/leveldb/db/log_format.h +35 -0
  27. data/ext/leveldb/db/log_reader.cc +259 -0
  28. data/ext/leveldb/db/log_reader.h +108 -0
  29. data/ext/leveldb/db/log_test.cc +500 -0
  30. data/ext/leveldb/db/log_writer.cc +103 -0
  31. data/ext/leveldb/db/log_writer.h +48 -0
  32. data/ext/leveldb/db/memtable.cc +145 -0
  33. data/ext/leveldb/db/memtable.h +91 -0
  34. data/ext/leveldb/db/repair.cc +389 -0
  35. data/ext/leveldb/db/skiplist.h +379 -0
  36. data/ext/leveldb/db/skiplist_test.cc +378 -0
  37. data/ext/leveldb/db/snapshot.h +66 -0
  38. data/ext/leveldb/db/table_cache.cc +121 -0
  39. data/ext/leveldb/db/table_cache.h +61 -0
  40. data/ext/leveldb/db/version_edit.cc +266 -0
  41. data/ext/leveldb/db/version_edit.h +107 -0
  42. data/ext/leveldb/db/version_edit_test.cc +46 -0
  43. data/ext/leveldb/db/version_set.cc +1443 -0
  44. data/ext/leveldb/db/version_set.h +383 -0
  45. data/ext/leveldb/db/version_set_test.cc +179 -0
  46. data/ext/leveldb/db/write_batch.cc +147 -0
  47. data/ext/leveldb/db/write_batch_internal.h +49 -0
  48. data/ext/leveldb/db/write_batch_test.cc +120 -0
  49. data/ext/leveldb/doc/bench/db_bench_sqlite3.cc +718 -0
  50. data/ext/leveldb/doc/bench/db_bench_tree_db.cc +528 -0
  51. data/ext/leveldb/helpers/memenv/memenv.cc +384 -0
  52. data/ext/leveldb/helpers/memenv/memenv.h +20 -0
  53. data/ext/leveldb/helpers/memenv/memenv_test.cc +232 -0
  54. data/ext/leveldb/include/leveldb/c.h +291 -0
  55. data/ext/leveldb/include/leveldb/cache.h +99 -0
  56. data/ext/leveldb/include/leveldb/comparator.h +63 -0
  57. data/ext/leveldb/include/leveldb/db.h +161 -0
  58. data/ext/leveldb/include/leveldb/env.h +333 -0
  59. data/ext/leveldb/include/leveldb/filter_policy.h +70 -0
  60. data/ext/leveldb/include/leveldb/iterator.h +100 -0
  61. data/ext/leveldb/include/leveldb/options.h +195 -0
  62. data/ext/leveldb/include/leveldb/slice.h +109 -0
  63. data/ext/leveldb/include/leveldb/status.h +106 -0
  64. data/ext/leveldb/include/leveldb/table.h +85 -0
  65. data/ext/leveldb/include/leveldb/table_builder.h +92 -0
  66. data/ext/leveldb/include/leveldb/write_batch.h +64 -0
  67. data/ext/leveldb/issues/issue178_test.cc +92 -0
  68. data/ext/leveldb/port/atomic_pointer.h +224 -0
  69. data/ext/leveldb/port/port.h +19 -0
  70. data/ext/leveldb/port/port_example.h +135 -0
  71. data/ext/leveldb/port/port_posix.cc +54 -0
  72. data/ext/leveldb/port/port_posix.h +157 -0
  73. data/ext/leveldb/port/thread_annotations.h +59 -0
  74. data/ext/leveldb/port/win/stdint.h +24 -0
  75. data/ext/leveldb/table/block.cc +268 -0
  76. data/ext/leveldb/table/block.h +44 -0
  77. data/ext/leveldb/table/block_builder.cc +109 -0
  78. data/ext/leveldb/table/block_builder.h +57 -0
  79. data/ext/leveldb/table/filter_block.cc +111 -0
  80. data/ext/leveldb/table/filter_block.h +68 -0
  81. data/ext/leveldb/table/filter_block_test.cc +128 -0
  82. data/ext/leveldb/table/format.cc +145 -0
  83. data/ext/leveldb/table/format.h +108 -0
  84. data/ext/leveldb/table/iterator.cc +67 -0
  85. data/ext/leveldb/table/iterator_wrapper.h +63 -0
  86. data/ext/leveldb/table/merger.cc +197 -0
  87. data/ext/leveldb/table/merger.h +26 -0
  88. data/ext/leveldb/table/table.cc +275 -0
  89. data/ext/leveldb/table/table_builder.cc +270 -0
  90. data/ext/leveldb/table/table_test.cc +868 -0
  91. data/ext/leveldb/table/two_level_iterator.cc +182 -0
  92. data/ext/leveldb/table/two_level_iterator.h +34 -0
  93. data/ext/leveldb/util/arena.cc +68 -0
  94. data/ext/leveldb/util/arena.h +68 -0
  95. data/ext/leveldb/util/arena_test.cc +68 -0
  96. data/ext/leveldb/util/bloom.cc +95 -0
  97. data/ext/leveldb/util/bloom_test.cc +160 -0
  98. data/ext/leveldb/util/cache.cc +325 -0
  99. data/ext/leveldb/util/cache_test.cc +186 -0
  100. data/ext/leveldb/util/coding.cc +194 -0
  101. data/ext/leveldb/util/coding.h +104 -0
  102. data/ext/leveldb/util/coding_test.cc +196 -0
  103. data/ext/leveldb/util/comparator.cc +81 -0
  104. data/ext/leveldb/util/crc32c.cc +332 -0
  105. data/ext/leveldb/util/crc32c.h +45 -0
  106. data/ext/leveldb/util/crc32c_test.cc +72 -0
  107. data/ext/leveldb/util/env.cc +96 -0
  108. data/ext/leveldb/util/env_posix.cc +698 -0
  109. data/ext/leveldb/util/env_test.cc +104 -0
  110. data/ext/leveldb/util/filter_policy.cc +11 -0
  111. data/ext/leveldb/util/hash.cc +52 -0
  112. data/ext/leveldb/util/hash.h +19 -0
  113. data/ext/leveldb/util/histogram.cc +139 -0
  114. data/ext/leveldb/util/histogram.h +42 -0
  115. data/ext/leveldb/util/logging.cc +81 -0
  116. data/ext/leveldb/util/logging.h +47 -0
  117. data/ext/leveldb/util/mutexlock.h +41 -0
  118. data/ext/leveldb/util/options.cc +29 -0
  119. data/ext/leveldb/util/posix_logger.h +98 -0
  120. data/ext/leveldb/util/random.h +59 -0
  121. data/ext/leveldb/util/status.cc +75 -0
  122. data/ext/leveldb/util/testharness.cc +77 -0
  123. data/ext/leveldb/util/testharness.h +138 -0
  124. data/ext/leveldb/util/testutil.cc +51 -0
  125. data/ext/leveldb/util/testutil.h +53 -0
  126. data/lib/leveldb/version.rb +3 -0
  127. data/lib/leveldb.rb +1006 -0
  128. metadata +228 -0
@@ -0,0 +1,291 @@
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 Windows, *errptr must have been malloc()-ed by this library.)
32
+ On success, a leveldb routine leaves *errptr unchanged.
33
+ On failure, leveldb frees the old value of *errptr and
34
+ set *errptr to a malloc()ed error message.
35
+
36
+ (4) Bools have the type unsigned char (0 == false; rest == true)
37
+
38
+ (5) All of the pointer arguments must be non-NULL.
39
+ */
40
+
41
+ #ifndef STORAGE_LEVELDB_INCLUDE_C_H_
42
+ #define STORAGE_LEVELDB_INCLUDE_C_H_
43
+
44
+ #ifdef __cplusplus
45
+ extern "C" {
46
+ #endif
47
+
48
+ #include <stdarg.h>
49
+ #include <stddef.h>
50
+ #include <stdint.h>
51
+
52
+ /* Exported types */
53
+
54
+ typedef struct leveldb_t leveldb_t;
55
+ typedef struct leveldb_cache_t leveldb_cache_t;
56
+ typedef struct leveldb_comparator_t leveldb_comparator_t;
57
+ typedef struct leveldb_env_t leveldb_env_t;
58
+ typedef struct leveldb_filelock_t leveldb_filelock_t;
59
+ typedef struct leveldb_filterpolicy_t leveldb_filterpolicy_t;
60
+ typedef struct leveldb_iterator_t leveldb_iterator_t;
61
+ typedef struct leveldb_logger_t leveldb_logger_t;
62
+ typedef struct leveldb_options_t leveldb_options_t;
63
+ typedef struct leveldb_randomfile_t leveldb_randomfile_t;
64
+ typedef struct leveldb_readoptions_t leveldb_readoptions_t;
65
+ typedef struct leveldb_seqfile_t leveldb_seqfile_t;
66
+ typedef struct leveldb_snapshot_t leveldb_snapshot_t;
67
+ typedef struct leveldb_writablefile_t leveldb_writablefile_t;
68
+ typedef struct leveldb_writebatch_t leveldb_writebatch_t;
69
+ typedef struct leveldb_writeoptions_t leveldb_writeoptions_t;
70
+
71
+ /* DB operations */
72
+
73
+ extern leveldb_t* leveldb_open(
74
+ const leveldb_options_t* options,
75
+ const char* name,
76
+ char** errptr);
77
+
78
+ extern void leveldb_close(leveldb_t* db);
79
+
80
+ extern void leveldb_put(
81
+ leveldb_t* db,
82
+ const leveldb_writeoptions_t* options,
83
+ const char* key, size_t keylen,
84
+ const char* val, size_t vallen,
85
+ char** errptr);
86
+
87
+ extern void leveldb_delete(
88
+ leveldb_t* db,
89
+ const leveldb_writeoptions_t* options,
90
+ const char* key, size_t keylen,
91
+ char** errptr);
92
+
93
+ extern void leveldb_write(
94
+ leveldb_t* db,
95
+ const leveldb_writeoptions_t* options,
96
+ leveldb_writebatch_t* batch,
97
+ char** errptr);
98
+
99
+ /* Returns NULL if not found. A malloc()ed array otherwise.
100
+ Stores the length of the array in *vallen. */
101
+ extern char* leveldb_get(
102
+ leveldb_t* db,
103
+ const leveldb_readoptions_t* options,
104
+ const char* key, size_t keylen,
105
+ size_t* vallen,
106
+ char** errptr);
107
+
108
+ extern leveldb_iterator_t* leveldb_create_iterator(
109
+ leveldb_t* db,
110
+ const leveldb_readoptions_t* options);
111
+
112
+ extern const leveldb_snapshot_t* leveldb_create_snapshot(
113
+ leveldb_t* db);
114
+
115
+ extern void leveldb_release_snapshot(
116
+ leveldb_t* db,
117
+ const leveldb_snapshot_t* snapshot);
118
+
119
+ /* Returns NULL if property name is unknown.
120
+ Else returns a pointer to a malloc()-ed null-terminated value. */
121
+ extern char* leveldb_property_value(
122
+ leveldb_t* db,
123
+ const char* propname);
124
+
125
+ extern void leveldb_approximate_sizes(
126
+ leveldb_t* db,
127
+ int num_ranges,
128
+ const char* const* range_start_key, const size_t* range_start_key_len,
129
+ const char* const* range_limit_key, const size_t* range_limit_key_len,
130
+ uint64_t* sizes);
131
+
132
+ extern void leveldb_compact_range(
133
+ leveldb_t* db,
134
+ const char* start_key, size_t start_key_len,
135
+ const char* limit_key, size_t limit_key_len);
136
+
137
+ /* Management operations */
138
+
139
+ extern void leveldb_destroy_db(
140
+ const leveldb_options_t* options,
141
+ const char* name,
142
+ char** errptr);
143
+
144
+ extern void leveldb_repair_db(
145
+ const leveldb_options_t* options,
146
+ const char* name,
147
+ char** errptr);
148
+
149
+ /* Iterator */
150
+
151
+ extern void leveldb_iter_destroy(leveldb_iterator_t*);
152
+ extern unsigned char leveldb_iter_valid(const leveldb_iterator_t*);
153
+ extern void leveldb_iter_seek_to_first(leveldb_iterator_t*);
154
+ extern void leveldb_iter_seek_to_last(leveldb_iterator_t*);
155
+ extern void leveldb_iter_seek(leveldb_iterator_t*, const char* k, size_t klen);
156
+ extern void leveldb_iter_next(leveldb_iterator_t*);
157
+ extern void leveldb_iter_prev(leveldb_iterator_t*);
158
+ extern const char* leveldb_iter_key(const leveldb_iterator_t*, size_t* klen);
159
+ extern const char* leveldb_iter_value(const leveldb_iterator_t*, size_t* vlen);
160
+ extern void leveldb_iter_get_error(const leveldb_iterator_t*, char** errptr);
161
+
162
+ /* Write batch */
163
+
164
+ extern leveldb_writebatch_t* leveldb_writebatch_create();
165
+ extern void leveldb_writebatch_destroy(leveldb_writebatch_t*);
166
+ extern void leveldb_writebatch_clear(leveldb_writebatch_t*);
167
+ extern void leveldb_writebatch_put(
168
+ leveldb_writebatch_t*,
169
+ const char* key, size_t klen,
170
+ const char* val, size_t vlen);
171
+ extern void leveldb_writebatch_delete(
172
+ leveldb_writebatch_t*,
173
+ const char* key, size_t klen);
174
+ extern void leveldb_writebatch_iterate(
175
+ leveldb_writebatch_t*,
176
+ void* state,
177
+ void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
178
+ void (*deleted)(void*, const char* k, size_t klen));
179
+
180
+ /* Options */
181
+
182
+ extern leveldb_options_t* leveldb_options_create();
183
+ extern void leveldb_options_destroy(leveldb_options_t*);
184
+ extern void leveldb_options_set_comparator(
185
+ leveldb_options_t*,
186
+ leveldb_comparator_t*);
187
+ extern void leveldb_options_set_filter_policy(
188
+ leveldb_options_t*,
189
+ leveldb_filterpolicy_t*);
190
+ extern void leveldb_options_set_create_if_missing(
191
+ leveldb_options_t*, unsigned char);
192
+ extern void leveldb_options_set_error_if_exists(
193
+ leveldb_options_t*, unsigned char);
194
+ extern void leveldb_options_set_paranoid_checks(
195
+ leveldb_options_t*, unsigned char);
196
+ extern void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*);
197
+ extern void leveldb_options_set_info_log(leveldb_options_t*, leveldb_logger_t*);
198
+ extern void leveldb_options_set_write_buffer_size(leveldb_options_t*, size_t);
199
+ extern void leveldb_options_set_max_open_files(leveldb_options_t*, int);
200
+ extern void leveldb_options_set_cache(leveldb_options_t*, leveldb_cache_t*);
201
+ extern void leveldb_options_set_block_size(leveldb_options_t*, size_t);
202
+ extern void leveldb_options_set_block_restart_interval(leveldb_options_t*, int);
203
+
204
+ enum {
205
+ leveldb_no_compression = 0,
206
+ leveldb_snappy_compression = 1
207
+ };
208
+ extern void leveldb_options_set_compression(leveldb_options_t*, int);
209
+
210
+ /* Comparator */
211
+
212
+ extern leveldb_comparator_t* leveldb_comparator_create(
213
+ void* state,
214
+ void (*destructor)(void*),
215
+ int (*compare)(
216
+ void*,
217
+ const char* a, size_t alen,
218
+ const char* b, size_t blen),
219
+ const char* (*name)(void*));
220
+ extern void leveldb_comparator_destroy(leveldb_comparator_t*);
221
+
222
+ /* Filter policy */
223
+
224
+ extern leveldb_filterpolicy_t* leveldb_filterpolicy_create(
225
+ void* state,
226
+ void (*destructor)(void*),
227
+ char* (*create_filter)(
228
+ void*,
229
+ const char* const* key_array, const size_t* key_length_array,
230
+ int num_keys,
231
+ size_t* filter_length),
232
+ unsigned char (*key_may_match)(
233
+ void*,
234
+ const char* key, size_t length,
235
+ const char* filter, size_t filter_length),
236
+ const char* (*name)(void*));
237
+ extern void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*);
238
+
239
+ extern leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom(
240
+ int bits_per_key);
241
+
242
+ /* Read options */
243
+
244
+ extern leveldb_readoptions_t* leveldb_readoptions_create();
245
+ extern void leveldb_readoptions_destroy(leveldb_readoptions_t*);
246
+ extern void leveldb_readoptions_set_verify_checksums(
247
+ leveldb_readoptions_t*,
248
+ unsigned char);
249
+ extern void leveldb_readoptions_set_fill_cache(
250
+ leveldb_readoptions_t*, unsigned char);
251
+ extern void leveldb_readoptions_set_snapshot(
252
+ leveldb_readoptions_t*,
253
+ const leveldb_snapshot_t*);
254
+
255
+ /* Write options */
256
+
257
+ extern leveldb_writeoptions_t* leveldb_writeoptions_create();
258
+ extern void leveldb_writeoptions_destroy(leveldb_writeoptions_t*);
259
+ extern void leveldb_writeoptions_set_sync(
260
+ leveldb_writeoptions_t*, unsigned char);
261
+
262
+ /* Cache */
263
+
264
+ extern leveldb_cache_t* leveldb_cache_create_lru(size_t capacity);
265
+ extern void leveldb_cache_destroy(leveldb_cache_t* cache);
266
+
267
+ /* Env */
268
+
269
+ extern leveldb_env_t* leveldb_create_default_env();
270
+ extern void leveldb_env_destroy(leveldb_env_t*);
271
+
272
+ /* Utility */
273
+
274
+ /* Calls free(ptr).
275
+ REQUIRES: ptr was malloc()-ed and returned by one of the routines
276
+ in this file. Note that in certain cases (typically on Windows), you
277
+ may need to call this routine instead of free(ptr) to dispose of
278
+ malloc()-ed memory returned by this library. */
279
+ extern void leveldb_free(void* ptr);
280
+
281
+ /* Return the major version number for this release. */
282
+ extern int leveldb_major_version();
283
+
284
+ /* Return the minor version number for this release. */
285
+ extern int leveldb_minor_version();
286
+
287
+ #ifdef __cplusplus
288
+ } /* end extern "C" */
289
+ #endif
290
+
291
+ #endif /* STORAGE_LEVELDB_INCLUDE_C_H_ */
@@ -0,0 +1,99 @@
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
+ // A Cache is an interface that maps keys to values. It has internal
6
+ // synchronization and may be safely accessed concurrently from
7
+ // multiple threads. It may automatically evict entries to make room
8
+ // for new entries. Values have a specified charge against the cache
9
+ // capacity. For example, a cache where the values are variable
10
+ // length strings, may use the length of the string as the charge for
11
+ // the string.
12
+ //
13
+ // A builtin cache implementation with a least-recently-used eviction
14
+ // policy is provided. Clients may use their own implementations if
15
+ // they want something more sophisticated (like scan-resistance, a
16
+ // custom eviction policy, variable cache sizing, etc.)
17
+
18
+ #ifndef STORAGE_LEVELDB_INCLUDE_CACHE_H_
19
+ #define STORAGE_LEVELDB_INCLUDE_CACHE_H_
20
+
21
+ #include <stdint.h>
22
+ #include "leveldb/slice.h"
23
+
24
+ namespace leveldb {
25
+
26
+ class Cache;
27
+
28
+ // Create a new cache with a fixed size capacity. This implementation
29
+ // of Cache uses a least-recently-used eviction policy.
30
+ extern Cache* NewLRUCache(size_t capacity);
31
+
32
+ class Cache {
33
+ public:
34
+ Cache() { }
35
+
36
+ // Destroys all existing entries by calling the "deleter"
37
+ // function that was passed to the constructor.
38
+ virtual ~Cache();
39
+
40
+ // Opaque handle to an entry stored in the cache.
41
+ struct Handle { };
42
+
43
+ // Insert a mapping from key->value into the cache and assign it
44
+ // the specified charge against the total cache capacity.
45
+ //
46
+ // Returns a handle that corresponds to the mapping. The caller
47
+ // must call this->Release(handle) when the returned mapping is no
48
+ // longer needed.
49
+ //
50
+ // When the inserted entry is no longer needed, the key and
51
+ // value will be passed to "deleter".
52
+ virtual Handle* Insert(const Slice& key, void* value, size_t charge,
53
+ void (*deleter)(const Slice& key, void* value)) = 0;
54
+
55
+ // If the cache has no mapping for "key", returns NULL.
56
+ //
57
+ // Else return a handle that corresponds to the mapping. The caller
58
+ // must call this->Release(handle) when the returned mapping is no
59
+ // longer needed.
60
+ virtual Handle* Lookup(const Slice& key) = 0;
61
+
62
+ // Release a mapping returned by a previous Lookup().
63
+ // REQUIRES: handle must not have been released yet.
64
+ // REQUIRES: handle must have been returned by a method on *this.
65
+ virtual void Release(Handle* handle) = 0;
66
+
67
+ // Return the value encapsulated in a handle returned by a
68
+ // successful Lookup().
69
+ // REQUIRES: handle must not have been released yet.
70
+ // REQUIRES: handle must have been returned by a method on *this.
71
+ virtual void* Value(Handle* handle) = 0;
72
+
73
+ // If the cache contains entry for key, erase it. Note that the
74
+ // underlying entry will be kept around until all existing handles
75
+ // to it have been released.
76
+ virtual void Erase(const Slice& key) = 0;
77
+
78
+ // Return a new numeric id. May be used by multiple clients who are
79
+ // sharing the same cache to partition the key space. Typically the
80
+ // client will allocate a new id at startup and prepend the id to
81
+ // its cache keys.
82
+ virtual uint64_t NewId() = 0;
83
+
84
+ private:
85
+ void LRU_Remove(Handle* e);
86
+ void LRU_Append(Handle* e);
87
+ void Unref(Handle* e);
88
+
89
+ struct Rep;
90
+ Rep* rep_;
91
+
92
+ // No copying allowed
93
+ Cache(const Cache&);
94
+ void operator=(const Cache&);
95
+ };
96
+
97
+ } // namespace leveldb
98
+
99
+ #endif // STORAGE_LEVELDB_UTIL_CACHE_H_
@@ -0,0 +1,63 @@
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_INCLUDE_COMPARATOR_H_
6
+ #define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
7
+
8
+ #include <string>
9
+
10
+ namespace leveldb {
11
+
12
+ class Slice;
13
+
14
+ // A Comparator object provides a total order across slices that are
15
+ // used as keys in an sstable or a database. A Comparator implementation
16
+ // must be thread-safe since leveldb may invoke its methods concurrently
17
+ // from multiple threads.
18
+ class Comparator {
19
+ public:
20
+ virtual ~Comparator();
21
+
22
+ // Three-way comparison. Returns value:
23
+ // < 0 iff "a" < "b",
24
+ // == 0 iff "a" == "b",
25
+ // > 0 iff "a" > "b"
26
+ virtual int Compare(const Slice& a, const Slice& b) const = 0;
27
+
28
+ // The name of the comparator. Used to check for comparator
29
+ // mismatches (i.e., a DB created with one comparator is
30
+ // accessed using a different comparator.
31
+ //
32
+ // The client of this package should switch to a new name whenever
33
+ // the comparator implementation changes in a way that will cause
34
+ // the relative ordering of any two keys to change.
35
+ //
36
+ // Names starting with "leveldb." are reserved and should not be used
37
+ // by any clients of this package.
38
+ virtual const char* Name() const = 0;
39
+
40
+ // Advanced functions: these are used to reduce the space requirements
41
+ // for internal data structures like index blocks.
42
+
43
+ // If *start < limit, changes *start to a short string in [start,limit).
44
+ // Simple comparator implementations may return with *start unchanged,
45
+ // i.e., an implementation of this method that does nothing is correct.
46
+ virtual void FindShortestSeparator(
47
+ std::string* start,
48
+ const Slice& limit) const = 0;
49
+
50
+ // Changes *key to a short string >= *key.
51
+ // Simple comparator implementations may return with *key unchanged,
52
+ // i.e., an implementation of this method that does nothing is correct.
53
+ virtual void FindShortSuccessor(std::string* key) const = 0;
54
+ };
55
+
56
+ // Return a builtin comparator that uses lexicographic byte-wise
57
+ // ordering. The result remains the property of this module and
58
+ // must not be deleted.
59
+ extern const Comparator* BytewiseComparator();
60
+
61
+ } // namespace leveldb
62
+
63
+ #endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
@@ -0,0 +1,161 @@
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_INCLUDE_DB_H_
6
+ #define STORAGE_LEVELDB_INCLUDE_DB_H_
7
+
8
+ #include <stdint.h>
9
+ #include <stdio.h>
10
+ #include "leveldb/iterator.h"
11
+ #include "leveldb/options.h"
12
+
13
+ namespace leveldb {
14
+
15
+ // Update Makefile if you change these
16
+ static const int kMajorVersion = 1;
17
+ static const int kMinorVersion = 12;
18
+
19
+ struct Options;
20
+ struct ReadOptions;
21
+ struct WriteOptions;
22
+ class WriteBatch;
23
+
24
+ // Abstract handle to particular state of a DB.
25
+ // A Snapshot is an immutable object and can therefore be safely
26
+ // accessed from multiple threads without any external synchronization.
27
+ class Snapshot {
28
+ protected:
29
+ virtual ~Snapshot();
30
+ };
31
+
32
+ // A range of keys
33
+ struct Range {
34
+ Slice start; // Included in the range
35
+ Slice limit; // Not included in the range
36
+
37
+ Range() { }
38
+ Range(const Slice& s, const Slice& l) : start(s), limit(l) { }
39
+ };
40
+
41
+ // A DB is a persistent ordered map from keys to values.
42
+ // A DB is safe for concurrent access from multiple threads without
43
+ // any external synchronization.
44
+ class DB {
45
+ public:
46
+ // Open the database with the specified "name".
47
+ // Stores a pointer to a heap-allocated database in *dbptr and returns
48
+ // OK on success.
49
+ // Stores NULL in *dbptr and returns a non-OK status on error.
50
+ // Caller should delete *dbptr when it is no longer needed.
51
+ static Status Open(const Options& options,
52
+ const std::string& name,
53
+ DB** dbptr);
54
+
55
+ DB() { }
56
+ virtual ~DB();
57
+
58
+ // Set the database entry for "key" to "value". Returns OK on success,
59
+ // and a non-OK status on error.
60
+ // Note: consider setting options.sync = true.
61
+ virtual Status Put(const WriteOptions& options,
62
+ const Slice& key,
63
+ const Slice& value) = 0;
64
+
65
+ // Remove the database entry (if any) for "key". Returns OK on
66
+ // success, and a non-OK status on error. It is not an error if "key"
67
+ // did not exist in the database.
68
+ // Note: consider setting options.sync = true.
69
+ virtual Status Delete(const WriteOptions& options, const Slice& key) = 0;
70
+
71
+ // Apply the specified updates to the database.
72
+ // Returns OK on success, non-OK on failure.
73
+ // Note: consider setting options.sync = true.
74
+ virtual Status Write(const WriteOptions& options, WriteBatch* updates) = 0;
75
+
76
+ // If the database contains an entry for "key" store the
77
+ // corresponding value in *value and return OK.
78
+ //
79
+ // If there is no entry for "key" leave *value unchanged and return
80
+ // a status for which Status::IsNotFound() returns true.
81
+ //
82
+ // May return some other Status on an error.
83
+ virtual Status Get(const ReadOptions& options,
84
+ const Slice& key, std::string* value) = 0;
85
+
86
+ // Return a heap-allocated iterator over the contents of the database.
87
+ // The result of NewIterator() is initially invalid (caller must
88
+ // call one of the Seek methods on the iterator before using it).
89
+ //
90
+ // Caller should delete the iterator when it is no longer needed.
91
+ // The returned iterator should be deleted before this db is deleted.
92
+ virtual Iterator* NewIterator(const ReadOptions& options) = 0;
93
+
94
+ // Return a handle to the current DB state. Iterators created with
95
+ // this handle will all observe a stable snapshot of the current DB
96
+ // state. The caller must call ReleaseSnapshot(result) when the
97
+ // snapshot is no longer needed.
98
+ virtual const Snapshot* GetSnapshot() = 0;
99
+
100
+ // Release a previously acquired snapshot. The caller must not
101
+ // use "snapshot" after this call.
102
+ virtual void ReleaseSnapshot(const Snapshot* snapshot) = 0;
103
+
104
+ // DB implementations can export properties about their state
105
+ // via this method. If "property" is a valid property understood by this
106
+ // DB implementation, fills "*value" with its current value and returns
107
+ // true. Otherwise returns false.
108
+ //
109
+ //
110
+ // Valid property names include:
111
+ //
112
+ // "leveldb.num-files-at-level<N>" - return the number of files at level <N>,
113
+ // where <N> is an ASCII representation of a level number (e.g. "0").
114
+ // "leveldb.stats" - returns a multi-line string that describes statistics
115
+ // about the internal operation of the DB.
116
+ // "leveldb.sstables" - returns a multi-line string that describes all
117
+ // of the sstables that make up the db contents.
118
+ virtual bool GetProperty(const Slice& property, std::string* value) = 0;
119
+
120
+ // For each i in [0,n-1], store in "sizes[i]", the approximate
121
+ // file system space used by keys in "[range[i].start .. range[i].limit)".
122
+ //
123
+ // Note that the returned sizes measure file system space usage, so
124
+ // if the user data compresses by a factor of ten, the returned
125
+ // sizes will be one-tenth the size of the corresponding user data size.
126
+ //
127
+ // The results may not include the sizes of recently written data.
128
+ virtual void GetApproximateSizes(const Range* range, int n,
129
+ uint64_t* sizes) = 0;
130
+
131
+ // Compact the underlying storage for the key range [*begin,*end].
132
+ // In particular, deleted and overwritten versions are discarded,
133
+ // and the data is rearranged to reduce the cost of operations
134
+ // needed to access the data. This operation should typically only
135
+ // be invoked by users who understand the underlying implementation.
136
+ //
137
+ // begin==NULL is treated as a key before all keys in the database.
138
+ // end==NULL is treated as a key after all keys in the database.
139
+ // Therefore the following call will compact the entire database:
140
+ // db->CompactRange(NULL, NULL);
141
+ virtual void CompactRange(const Slice* begin, const Slice* end) = 0;
142
+
143
+ private:
144
+ // No copying allowed
145
+ DB(const DB&);
146
+ void operator=(const DB&);
147
+ };
148
+
149
+ // Destroy the contents of the specified database.
150
+ // Be very careful using this method.
151
+ Status DestroyDB(const std::string& name, const Options& options);
152
+
153
+ // If a DB cannot be opened, you may attempt to call this method to
154
+ // resurrect as much of the contents of the database as possible.
155
+ // Some data may be lost, so be careful when calling this function
156
+ // on a database that contains important information.
157
+ Status RepairDB(const std::string& dbname, const Options& options);
158
+
159
+ } // namespace leveldb
160
+
161
+ #endif // STORAGE_LEVELDB_INCLUDE_DB_H_