diff options
author | Michael Cahill <michael.cahill@wiredtiger.com> | 2014-06-27 14:18:11 +1000 |
---|---|---|
committer | Michael Cahill <michael.cahill@wiredtiger.com> | 2014-06-27 14:18:11 +1000 |
commit | f2842ced64dfb7d4f79df7a70b8a3da6f6467ed4 (patch) | |
tree | 2f88dfd5c2f954859112dddc634afe6a9b9fbe74 /api | |
parent | a721db22d53dc7d0dbf74d894d7c2b4d50de1fda (diff) | |
download | mongo-f2842ced64dfb7d4f79df7a70b8a3da6f6467ed4.tar.gz |
Improve building and installing LevelDB variants: add wiredtiger_config.h to the LevelDB includes.
Diffstat (limited to 'api')
-rw-r--r-- | api/leveldb/Makefile.am | 36 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/c.h | 290 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/cache.h | 7 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/comparator.h | 11 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/db.h | 43 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/env.h | 9 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/filter_policy.h | 5 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/iterator.h | 9 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/options.h | 18 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/perf_count.h | 4 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/replay_iterator.h | 67 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/slice.h | 5 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/status.h | 7 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/table.h | 85 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/table_builder.h | 92 | ||||
-rw-r--r-- | api/leveldb/include/leveldb/write_batch.h | 7 | ||||
-rw-r--r-- | api/leveldb/leveldb_wt.h | 13 |
17 files changed, 205 insertions, 503 deletions
diff --git a/api/leveldb/Makefile.am b/api/leveldb/Makefile.am index 552bbddd70c..6f7f471181d 100644 --- a/api/leveldb/Makefile.am +++ b/api/leveldb/Makefile.am @@ -7,26 +7,36 @@ noinst_PROGRAMS = leveldb_test # Setup the LevelDB headers to be installed in a wiredtiger/leveldb # subdirectory, so we don't interfere with other LevelDB installs. +if HAVE_HYPERLEVELDB +leveldbincludedir = $(includedir)/wiredtiger/hyperleveldb +else +if HAVE_ROCKSDB +leveldbincludedir = $(includedir)/wiredtiger/rocksdb +else leveldbincludedir = $(includedir)/wiredtiger/leveldb +endif +endif leveldbinclude_HEADERS = \ - include/leveldb/cache.h \ - include/leveldb/c.h \ - include/leveldb/comparator.h\ - include/leveldb/db.h \ - include/leveldb/env.h \ - include/leveldb/filter_policy.h \ - include/leveldb/iterator.h \ - include/leveldb/options.h \ - include/leveldb/slice.h \ - include/leveldb/status.h \ - include/leveldb/table_builder.h \ - include/leveldb/table.h \ - include/leveldb/write_batch.h + wiredtiger_config.h \ + include/leveldb/cache.h \ + include/leveldb/comparator.h\ + include/leveldb/db.h \ + include/leveldb/env.h \ + include/leveldb/filter_policy.h \ + include/leveldb/iterator.h \ + include/leveldb/options.h \ + include/leveldb/slice.h \ + include/leveldb/status.h \ + include/leveldb/write_batch.h if HAVE_ELEVELDB leveldbinclude_HEADERS += \ include/leveldb/perf_count.h endif +if HAVE_HYPERLEVELDB +leveldbinclude_HEADERS += \ + include/leveldb/replay_iterator.h +endif libwiredtiger_leveldb_la_LDFLAGS = -release @VERSION@ libwiredtiger_leveldb_la_SOURCES = \ diff --git a/api/leveldb/include/leveldb/c.h b/api/leveldb/include/leveldb/c.h deleted file mode 100644 index 1048fe3b868..00000000000 --- a/api/leveldb/include/leveldb/c.h +++ /dev/null @@ -1,290 +0,0 @@ -/* Copyright (c) 2011 The LevelDB Authors. All rights reserved. - Use of this source code is governed by a BSD-style license that can be - found in the LICENSE file. See the AUTHORS file for names of contributors. - - C bindings for leveldb. May be useful as a stable ABI that can be - used by programs that keep leveldb in a shared library, or for - a JNI api. - - Does not support: - . getters for the option types - . custom comparators that implement key shortening - . custom iter, db, env, cache implementations using just the C bindings - - Some conventions: - - (1) We expose just opaque struct pointers and functions to clients. - This allows us to change internal representations without having to - recompile clients. - - (2) For simplicity, there is no equivalent to the Slice type. Instead, - the caller has to pass the pointer and length as separate - arguments. - - (3) Errors are represented by a null-terminated c string. NULL - means no error. All operations that can raise an error are passed - a "char** errptr" as the last argument. One of the following must - be true on entry: - *errptr == NULL - *errptr points to a malloc()ed null-terminated error message - (On Windows, *errptr must have been malloc()-ed by this library.) - On success, a leveldb routine leaves *errptr unchanged. - On failure, leveldb frees the old value of *errptr and - set *errptr to a malloc()ed error message. - - (4) Bools have the type unsigned char (0 == false; rest == true) - - (5) All of the pointer arguments must be non-NULL. -*/ - -#ifndef STORAGE_LEVELDB_INCLUDE_C_H_ -#define STORAGE_LEVELDB_INCLUDE_C_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdarg.h> -#include <stddef.h> -#include <stdint.h> - -/* Exported types */ - -typedef struct leveldb_t leveldb_t; -typedef struct leveldb_cache_t leveldb_cache_t; -typedef struct leveldb_comparator_t leveldb_comparator_t; -typedef struct leveldb_env_t leveldb_env_t; -typedef struct leveldb_filelock_t leveldb_filelock_t; -typedef struct leveldb_filterpolicy_t leveldb_filterpolicy_t; -typedef struct leveldb_iterator_t leveldb_iterator_t; -typedef struct leveldb_logger_t leveldb_logger_t; -typedef struct leveldb_options_t leveldb_options_t; -typedef struct leveldb_randomfile_t leveldb_randomfile_t; -typedef struct leveldb_readoptions_t leveldb_readoptions_t; -typedef struct leveldb_seqfile_t leveldb_seqfile_t; -typedef struct leveldb_snapshot_t leveldb_snapshot_t; -typedef struct leveldb_writablefile_t leveldb_writablefile_t; -typedef struct leveldb_writebatch_t leveldb_writebatch_t; -typedef struct leveldb_writeoptions_t leveldb_writeoptions_t; - -/* DB operations */ - -extern leveldb_t* leveldb_open( - const leveldb_options_t* options, - const char* name, - char** errptr); - -extern void leveldb_close(leveldb_t* db); - -extern void leveldb_put( - leveldb_t* db, - const leveldb_writeoptions_t* options, - const char* key, size_t keylen, - const char* val, size_t vallen, - char** errptr); - -extern void leveldb_delete( - leveldb_t* db, - const leveldb_writeoptions_t* options, - const char* key, size_t keylen, - char** errptr); - -extern void leveldb_write( - leveldb_t* db, - const leveldb_writeoptions_t* options, - leveldb_writebatch_t* batch, - char** errptr); - -/* Returns NULL if not found. A malloc()ed array otherwise. - Stores the length of the array in *vallen. */ -extern char* leveldb_get( - leveldb_t* db, - const leveldb_readoptions_t* options, - const char* key, size_t keylen, - size_t* vallen, - char** errptr); - -extern leveldb_iterator_t* leveldb_create_iterator( - leveldb_t* db, - const leveldb_readoptions_t* options); - -extern const leveldb_snapshot_t* leveldb_create_snapshot( - leveldb_t* db); - -extern void leveldb_release_snapshot( - leveldb_t* db, - const leveldb_snapshot_t* snapshot); - -/* Returns NULL if property name is unknown. - Else returns a pointer to a malloc()-ed null-terminated value. */ -extern char* leveldb_property_value( - leveldb_t* db, - const char* propname); - -extern void leveldb_approximate_sizes( - leveldb_t* db, - int num_ranges, - const char* const* range_start_key, const size_t* range_start_key_len, - const char* const* range_limit_key, const size_t* range_limit_key_len, - uint64_t* sizes); - -extern void leveldb_compact_range( - leveldb_t* db, - const char* start_key, size_t start_key_len, - const char* limit_key, size_t limit_key_len); - -/* Management operations */ - -extern void leveldb_destroy_db( - const leveldb_options_t* options, - const char* name, - char** errptr); - -extern void leveldb_repair_db( - const leveldb_options_t* options, - const char* name, - char** errptr); - -/* Iterator */ - -extern void leveldb_iter_destroy(leveldb_iterator_t*); -extern unsigned char leveldb_iter_valid(const leveldb_iterator_t*); -extern void leveldb_iter_seek_to_first(leveldb_iterator_t*); -extern void leveldb_iter_seek_to_last(leveldb_iterator_t*); -extern void leveldb_iter_seek(leveldb_iterator_t*, const char* k, size_t klen); -extern void leveldb_iter_next(leveldb_iterator_t*); -extern void leveldb_iter_prev(leveldb_iterator_t*); -extern const char* leveldb_iter_key(const leveldb_iterator_t*, size_t* klen); -extern const char* leveldb_iter_value(const leveldb_iterator_t*, size_t* vlen); -extern void leveldb_iter_get_error(const leveldb_iterator_t*, char** errptr); - -/* Write batch */ - -extern leveldb_writebatch_t* leveldb_writebatch_create(); -extern void leveldb_writebatch_destroy(leveldb_writebatch_t*); -extern void leveldb_writebatch_clear(leveldb_writebatch_t*); -extern void leveldb_writebatch_put( - leveldb_writebatch_t*, - const char* key, size_t klen, - const char* val, size_t vlen); -extern void leveldb_writebatch_delete( - leveldb_writebatch_t*, - const char* key, size_t klen); -extern void leveldb_writebatch_iterate( - leveldb_writebatch_t*, - void* state, - void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), - void (*deleted)(void*, const char* k, size_t klen)); - -/* Options */ - -extern leveldb_options_t* leveldb_options_create(); -extern void leveldb_options_destroy(leveldb_options_t*); -extern void leveldb_options_set_comparator( - leveldb_options_t*, - leveldb_comparator_t*); -extern void leveldb_options_set_filter_policy( - leveldb_options_t*, - leveldb_filterpolicy_t*); -extern void leveldb_options_set_create_if_missing( - leveldb_options_t*, unsigned char); -extern void leveldb_options_set_error_if_exists( - leveldb_options_t*, unsigned char); -extern void leveldb_options_set_paranoid_checks( - leveldb_options_t*, unsigned char); -extern void leveldb_options_set_env(leveldb_options_t*, leveldb_env_t*); -extern void leveldb_options_set_info_log(leveldb_options_t*, leveldb_logger_t*); -extern void leveldb_options_set_write_buffer_size(leveldb_options_t*, size_t); -extern void leveldb_options_set_max_open_files(leveldb_options_t*, int); -extern void leveldb_options_set_cache(leveldb_options_t*, leveldb_cache_t*); -extern void leveldb_options_set_block_size(leveldb_options_t*, size_t); -extern void leveldb_options_set_block_restart_interval(leveldb_options_t*, int); - -enum { - leveldb_no_compression = 0, - leveldb_snappy_compression = 1 -}; -extern void leveldb_options_set_compression(leveldb_options_t*, int); - -/* Comparator */ - -extern leveldb_comparator_t* leveldb_comparator_create( - void* state, - void (*destructor)(void*), - int (*compare)( - void*, - const char* a, size_t alen, - const char* b, size_t blen), - const char* (*name)(void*)); -extern void leveldb_comparator_destroy(leveldb_comparator_t*); - -/* Filter policy */ - -extern leveldb_filterpolicy_t* leveldb_filterpolicy_create( - void* state, - void (*destructor)(void*), - char* (*create_filter)( - void*, - const char* const* key_array, const size_t* key_length_array, - int num_keys, - size_t* filter_length), - unsigned char (*key_may_match)( - void*, - const char* key, size_t length, - const char* filter, size_t filter_length), - const char* (*name)(void*)); -extern void leveldb_filterpolicy_destroy(leveldb_filterpolicy_t*); - -extern leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom( - int bits_per_key); - -/* Read options */ - -extern leveldb_readoptions_t* leveldb_readoptions_create(); -extern void leveldb_readoptions_destroy(leveldb_readoptions_t*); -extern void leveldb_readoptions_set_verify_checksums( - leveldb_readoptions_t*, - unsigned char); -extern void leveldb_readoptions_set_fill_cache( - leveldb_readoptions_t*, unsigned char); -extern void leveldb_readoptions_set_snapshot( - leveldb_readoptions_t*, - const leveldb_snapshot_t*); - -/* Write options */ - -extern leveldb_writeoptions_t* leveldb_writeoptions_create(); -extern void leveldb_writeoptions_destroy(leveldb_writeoptions_t*); -extern void leveldb_writeoptions_set_sync( - leveldb_writeoptions_t*, unsigned char); - -/* Cache */ - -extern leveldb_cache_t* leveldb_cache_create_lru(size_t capacity); -extern void leveldb_cache_destroy(leveldb_cache_t* cache); - -/* Env */ - -extern leveldb_env_t* leveldb_create_default_env(); -extern void leveldb_env_destroy(leveldb_env_t*); - -/* Utility */ - -/* Calls free(ptr). - REQUIRES: ptr was malloc()-ed and returned by one of the routines - in this file. Note that in certain cases (typically on Windows), you - may need to call this routine instead of free(ptr) to dispose of - malloc()-ed memory returned by this library. */ -extern void leveldb_free(void* ptr); - -/* Return the major version number for this release. */ -extern int leveldb_major_version(); - -/* Return the minor version number for this release. */ -extern int leveldb_minor_version(); - -#ifdef __cplusplus -} /* end extern "C" */ -#endif - -#endif /* STORAGE_LEVELDB_INCLUDE_C_H_ */ diff --git a/api/leveldb/include/leveldb/cache.h b/api/leveldb/include/leveldb/cache.h index 5e3b47637d4..e671d2ad01a 100644 --- a/api/leveldb/include/leveldb/cache.h +++ b/api/leveldb/include/leveldb/cache.h @@ -18,8 +18,13 @@ #ifndef STORAGE_LEVELDB_INCLUDE_CACHE_H_ #define STORAGE_LEVELDB_INCLUDE_CACHE_H_ +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + #include <stdint.h> -#include "leveldb/slice.h" +#include "slice.h" namespace leveldb { diff --git a/api/leveldb/include/leveldb/comparator.h b/api/leveldb/include/leveldb/comparator.h index 556b984c769..23e0ba84559 100644 --- a/api/leveldb/include/leveldb/comparator.h +++ b/api/leveldb/include/leveldb/comparator.h @@ -5,6 +5,12 @@ #ifndef STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ #define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_ +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + +#include <stdint.h> #include <string> namespace leveldb { @@ -51,6 +57,11 @@ class Comparator { // Simple comparator implementations may return with *key unchanged, // i.e., an implementation of this method that does nothing is correct. virtual void FindShortSuccessor(std::string* key) const = 0; + +#ifdef HAVE_HYPERLEVELDB + // If unsure, return 0; + virtual uint64_t KeyNum(const Slice& key) const; +#endif }; // Return a builtin comparator that uses lexicographic byte-wise diff --git a/api/leveldb/include/leveldb/db.h b/api/leveldb/include/leveldb/db.h index d93c46b7859..380fe7a126e 100644 --- a/api/leveldb/include/leveldb/db.h +++ b/api/leveldb/include/leveldb/db.h @@ -5,10 +5,18 @@ #ifndef STORAGE_LEVELDB_INCLUDE_DB_H_ #define STORAGE_LEVELDB_INCLUDE_DB_H_ +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + #include <stdint.h> #include <stdio.h> -#include "leveldb/iterator.h" -#include "leveldb/options.h" +#include "iterator.h" +#include "options.h" +#ifdef HAVE_HYPERLEVELDB +#include "replay_iterator.h" +#endif namespace leveldb { @@ -157,6 +165,37 @@ class DB { // db->CompactRange(NULL, NULL); virtual void CompactRange(const Slice* begin, const Slice* end) = 0; +#ifdef HAVE_HYPERLEVELDB + // Create a live backup of a live LevelDB instance. + // The backup is stored in a directory named "backup-<name>" under the top + // level of the open LevelDB database. The implementation is permitted, and + // even encouraged, to improve the performance of this call through + // hard-links. + virtual Status LiveBackup(const Slice& name) = 0; + + // Return an opaque timestamp that identifies the current point in time of the + // database. This timestamp may be subsequently presented to the + // NewReplayIterator method to create a ReplayIterator. + virtual void GetReplayTimestamp(std::string* timestamp) = 0; + + // Set the lower bound for manual garbage collection. This method only takes + // effect when Options.manual_garbage_collection is true. + virtual void AllowGarbageCollectBeforeTimestamp(const std::string& timestamp) = 0; + + // Validate the timestamp + virtual bool ValidateTimestamp(const std::string& timestamp) = 0; + + // Compare two timestamps and return -1, 0, 1 for lt, eq, gt + virtual int CompareTimestamps(const std::string& lhs, const std::string& rhs) = 0; + + // Return a ReplayIterator that returns every write operation performed after + // the timestamp. + virtual Status GetReplayIterator(const std::string& timestamp, + ReplayIterator** iter) = 0; + + // Release a previously allocated replay iterator. + virtual void ReleaseReplayIterator(ReplayIterator* iter) = 0; +#endif private: // No copying allowed DB(const DB&); diff --git a/api/leveldb/include/leveldb/env.h b/api/leveldb/include/leveldb/env.h index 6b1af9c2825..35071f6992d 100644 --- a/api/leveldb/include/leveldb/env.h +++ b/api/leveldb/include/leveldb/env.h @@ -13,14 +13,19 @@ #ifndef STORAGE_LEVELDB_INCLUDE_ENV_H_ #define STORAGE_LEVELDB_INCLUDE_ENV_H_ +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + #include <string> #include <vector> #include <stdarg.h> #include <stdint.h> #if HAVE_ELEVELDB -#include "leveldb/perf_count.h" +#include "perf_count.h" #endif -#include "leveldb/status.h" +#include "status.h" namespace leveldb { diff --git a/api/leveldb/include/leveldb/filter_policy.h b/api/leveldb/include/leveldb/filter_policy.h index 9f824fd1e48..b9c6ddd3dde 100644 --- a/api/leveldb/include/leveldb/filter_policy.h +++ b/api/leveldb/include/leveldb/filter_policy.h @@ -16,6 +16,11 @@ #ifndef STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ #define STORAGE_LEVELDB_INCLUDE_FILTER_POLICY_H_ +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + #include <string> namespace leveldb { diff --git a/api/leveldb/include/leveldb/iterator.h b/api/leveldb/include/leveldb/iterator.h index ad543eb46cd..3845d553a4e 100644 --- a/api/leveldb/include/leveldb/iterator.h +++ b/api/leveldb/include/leveldb/iterator.h @@ -15,8 +15,13 @@ #ifndef STORAGE_LEVELDB_INCLUDE_ITERATOR_H_ #define STORAGE_LEVELDB_INCLUDE_ITERATOR_H_ -#include "leveldb/slice.h" -#include "leveldb/status.h" +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + +#include "slice.h" +#include "status.h" namespace leveldb { diff --git a/api/leveldb/include/leveldb/options.h b/api/leveldb/include/leveldb/options.h index c8e4ba668ff..77cfac61b33 100644 --- a/api/leveldb/include/leveldb/options.h +++ b/api/leveldb/include/leveldb/options.h @@ -5,6 +5,11 @@ #ifndef STORAGE_LEVELDB_INCLUDE_OPTIONS_H_ #define STORAGE_LEVELDB_INCLUDE_OPTIONS_H_ +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + #include <stddef.h> namespace leveldb { @@ -145,6 +150,19 @@ struct Options { // Default: NULL const FilterPolicy* filter_policy; +#ifdef HAVE_HYPERLEVELDB + // Is the database used with the Replay mechanism? If yes, the lower bound on + // values to compact is (somewhat) left up to the application; if no, then + // LevelDB functions as usual, and uses snapshots to determine the lower + // bound. HyperLevelDB will always maintain the integrity of snapshots, so + // the application merely has the option to hold data as if it's holding a + // snapshot. This just prevents compaction from grabbing data before the app + // can get a snapshot. + // + // Default: false/no. + bool manual_garbage_collection; +#endif + // Create an Options object with default values for all fields. Options(); }; diff --git a/api/leveldb/include/leveldb/perf_count.h b/api/leveldb/include/leveldb/perf_count.h index 4ed215e20b1..0edf1b96549 100644 --- a/api/leveldb/include/leveldb/perf_count.h +++ b/api/leveldb/include/leveldb/perf_count.h @@ -23,9 +23,11 @@ #ifndef STORAGE_LEVELDB_INCLUDE_PERF_COUNT_H_ #define STORAGE_LEVELDB_INCLUDE_PERF_COUNT_H_ +#include "wiredtiger_config.h" + #include <stdint.h> #include <string> -#include "leveldb/status.h" +#include "status.h" namespace leveldb { diff --git a/api/leveldb/include/leveldb/replay_iterator.h b/api/leveldb/include/leveldb/replay_iterator.h new file mode 100644 index 00000000000..6e2f562c6c4 --- /dev/null +++ b/api/leveldb/include/leveldb/replay_iterator.h @@ -0,0 +1,67 @@ +// Copyright (c) 2013 The HyperLevelDB Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. See the AUTHORS file for names of contributors. + +#ifndef STORAGE_LEVELDB_INCLUDE_REPLAY_ITERATOR_H_ +#define STORAGE_LEVELDB_INCLUDE_REPLAY_ITERATOR_H_ + +#include "wiredtiger_config.h" + +#include "slice.h" +#include "status.h" + +namespace leveldb { + +class ReplayIterator { + public: + ReplayIterator(); + + // An iterator is either positioned at a deleted key, present key/value pair, + // or not valid. This method returns true iff the iterator is valid. + virtual bool Valid() = 0; + + // Moves to the next entry in the source. After this call, Valid() is + // true iff the iterator was not positioned at the last entry in the source. + // REQUIRES: Valid() + virtual void Next() = 0; + + // Position at the first key in the source that at or past target for this + // pass. Note that this is unlike the Seek call, as the ReplayIterator is + // unsorted. + // The iterator is Valid() after this call iff the source contains + // an entry that comes at or past target. + virtual void SkipTo(const Slice& target) = 0; + virtual void SkipToLast() = 0; + + // Return true if the current entry points to a key-value pair. If this + // returns false, it means the current entry is a deleted entry. + virtual bool HasValue() = 0; + + // Return the key for the current entry. The underlying storage for + // the returned slice is valid only until the next modification of + // the iterator. + // REQUIRES: Valid() + virtual Slice key() const = 0; + + // Return the value for the current entry. The underlying storage for + // the returned slice is valid only until the next modification of + // the iterator. + // REQUIRES: !AtEnd() && !AtStart() + virtual Slice value() const = 0; + + // If an error has occurred, return it. Else return an ok status. + virtual Status status() const = 0; + + protected: + // must be released by giving it back to the DB + virtual ~ReplayIterator(); + + private: + // No copying allowed + ReplayIterator(const ReplayIterator&); + void operator=(const ReplayIterator&); +}; + +} // namespace leveldb + +#endif // STORAGE_LEVELDB_INCLUDE_REPLAY_ITERATOR_H_ diff --git a/api/leveldb/include/leveldb/slice.h b/api/leveldb/include/leveldb/slice.h index bc367986f7e..c801f783b64 100644 --- a/api/leveldb/include/leveldb/slice.h +++ b/api/leveldb/include/leveldb/slice.h @@ -15,6 +15,11 @@ #ifndef STORAGE_LEVELDB_INCLUDE_SLICE_H_ #define STORAGE_LEVELDB_INCLUDE_SLICE_H_ +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + #include <assert.h> #include <stddef.h> #include <string.h> diff --git a/api/leveldb/include/leveldb/status.h b/api/leveldb/include/leveldb/status.h index 11dbd4b47ed..8b2cbb9b422 100644 --- a/api/leveldb/include/leveldb/status.h +++ b/api/leveldb/include/leveldb/status.h @@ -13,8 +13,13 @@ #ifndef STORAGE_LEVELDB_INCLUDE_STATUS_H_ #define STORAGE_LEVELDB_INCLUDE_STATUS_H_ +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + #include <string> -#include "leveldb/slice.h" +#include "slice.h" namespace leveldb { diff --git a/api/leveldb/include/leveldb/table.h b/api/leveldb/include/leveldb/table.h deleted file mode 100644 index a9746c3f5ea..00000000000 --- a/api/leveldb/include/leveldb/table.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2011 The LevelDB Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. See the AUTHORS file for names of contributors. - -#ifndef STORAGE_LEVELDB_INCLUDE_TABLE_H_ -#define STORAGE_LEVELDB_INCLUDE_TABLE_H_ - -#include <stdint.h> -#include "leveldb/iterator.h" - -namespace leveldb { - -class Block; -class BlockHandle; -class Footer; -struct Options; -class RandomAccessFile; -struct ReadOptions; -class TableCache; - -// A Table is a sorted map from strings to strings. Tables are -// immutable and persistent. A Table may be safely accessed from -// multiple threads without external synchronization. -class Table { - public: - // Attempt to open the table that is stored in bytes [0..file_size) - // of "file", and read the metadata entries necessary to allow - // retrieving data from the table. - // - // If successful, returns ok and sets "*table" to the newly opened - // table. The client should delete "*table" when no longer needed. - // If there was an error while initializing the table, sets "*table" - // to NULL and returns a non-ok status. Does not take ownership of - // "*source", but the client must ensure that "source" remains live - // for the duration of the returned table's lifetime. - // - // *file must remain live while this Table is in use. - static Status Open(const Options& options, - RandomAccessFile* file, - uint64_t file_size, - Table** table); - - ~Table(); - - // Returns a new iterator over the table contents. - // The result of NewIterator() is initially invalid (caller must - // call one of the Seek methods on the iterator before using it). - Iterator* NewIterator(const ReadOptions&) const; - - // Given a key, return an approximate byte offset in the file where - // the data for that key begins (or would begin if the key were - // present in the file). The returned value is in terms of file - // bytes, and so includes effects like compression of the underlying data. - // E.g., the approximate offset of the last key in the table will - // be close to the file length. - uint64_t ApproximateOffsetOf(const Slice& key) const; - - private: - struct Rep; - Rep* rep_; - - explicit Table(Rep* rep) { rep_ = rep; } - static Iterator* BlockReader(void*, const ReadOptions&, const Slice&); - - // Calls (*handle_result)(arg, ...) with the entry found after a call - // to Seek(key). May not make such a call if filter policy says - // that key is not present. - friend class TableCache; - Status InternalGet( - const ReadOptions&, const Slice& key, - void* arg, - void (*handle_result)(void* arg, const Slice& k, const Slice& v)); - - - void ReadMeta(const Footer& footer); - void ReadFilter(const Slice& filter_handle_value); - - // No copying allowed - Table(const Table&); - void operator=(const Table&); -}; - -} // namespace leveldb - -#endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_ diff --git a/api/leveldb/include/leveldb/table_builder.h b/api/leveldb/include/leveldb/table_builder.h deleted file mode 100644 index 5fd1dc71f1c..00000000000 --- a/api/leveldb/include/leveldb/table_builder.h +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2011 The LevelDB Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. See the AUTHORS file for names of contributors. -// -// TableBuilder provides the interface used to build a Table -// (an immutable and sorted map from keys to values). -// -// Multiple threads can invoke const methods on a TableBuilder without -// external synchronization, but if any of the threads may call a -// non-const method, all threads accessing the same TableBuilder must use -// external synchronization. - -#ifndef STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_ -#define STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_ - -#include <stdint.h> -#include "leveldb/options.h" -#include "leveldb/status.h" - -namespace leveldb { - -class BlockBuilder; -class BlockHandle; -class WritableFile; - -class TableBuilder { - public: - // Create a builder that will store the contents of the table it is - // building in *file. Does not close the file. It is up to the - // caller to close the file after calling Finish(). - TableBuilder(const Options& options, WritableFile* file); - - // REQUIRES: Either Finish() or Abandon() has been called. - ~TableBuilder(); - - // Change the options used by this builder. Note: only some of the - // option fields can be changed after construction. If a field is - // not allowed to change dynamically and its value in the structure - // passed to the constructor is different from its value in the - // structure passed to this method, this method will return an error - // without changing any fields. - Status ChangeOptions(const Options& options); - - // Add key,value to the table being constructed. - // REQUIRES: key is after any previously added key according to comparator. - // REQUIRES: Finish(), Abandon() have not been called - void Add(const Slice& key, const Slice& value); - - // Advanced operation: flush any buffered key/value pairs to file. - // Can be used to ensure that two adjacent entries never live in - // the same data block. Most clients should not need to use this method. - // REQUIRES: Finish(), Abandon() have not been called - void Flush(); - - // Return non-ok iff some error has been detected. - Status status() const; - - // Finish building the table. Stops using the file passed to the - // constructor after this function returns. - // REQUIRES: Finish(), Abandon() have not been called - Status Finish(); - - // Indicate that the contents of this builder should be abandoned. Stops - // using the file passed to the constructor after this function returns. - // If the caller is not going to call Finish(), it must call Abandon() - // before destroying this builder. - // REQUIRES: Finish(), Abandon() have not been called - void Abandon(); - - // Number of calls to Add() so far. - uint64_t NumEntries() const; - - // Size of the file generated so far. If invoked after a successful - // Finish() call, returns the size of the final generated file. - uint64_t FileSize() const; - - private: - bool ok() const { return status().ok(); } - void WriteBlock(BlockBuilder* block, BlockHandle* handle); - void WriteRawBlock(const Slice& data, CompressionType, BlockHandle* handle); - - struct Rep; - Rep* rep_; - - // No copying allowed - TableBuilder(const TableBuilder&); - void operator=(const TableBuilder&); -}; - -} // namespace leveldb - -#endif // STORAGE_LEVELDB_INCLUDE_TABLE_BUILDER_H_ diff --git a/api/leveldb/include/leveldb/write_batch.h b/api/leveldb/include/leveldb/write_batch.h index ee9aab68e0d..01089bff7c4 100644 --- a/api/leveldb/include/leveldb/write_batch.h +++ b/api/leveldb/include/leveldb/write_batch.h @@ -21,8 +21,13 @@ #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ +#include "wiredtiger_config.h" +#if defined(HAVE_ROCKSDB) && !defined(leveldb) +#define leveldb rocksdb +#endif + #include <string> -#include "leveldb/status.h" +#include "status.h" namespace leveldb { diff --git a/api/leveldb/leveldb_wt.h b/api/leveldb/leveldb_wt.h index 520068547a6..08f9523418a 100644 --- a/api/leveldb/leveldb_wt.h +++ b/api/leveldb/leveldb_wt.h @@ -27,17 +27,6 @@ #include "wiredtiger_config.h" -#ifdef HAVE_HYPERLEVELDB -#include <hyperleveldb/cache.h> -#include <hyperleveldb/comparator.h> -#include <hyperleveldb/db.h> -#include <hyperleveldb/env.h> -#include <hyperleveldb/filter_policy.h> -#include <hyperleveldb/slice.h> -#include <hyperleveldb/status.h> -#include <hyperleveldb/table_builder.h> -#include <hyperleveldb/write_batch.h> -#else #include "leveldb/cache.h" #include "leveldb/comparator.h" #include "leveldb/db.h" @@ -46,9 +35,7 @@ #include "leveldb/options.h" #include "leveldb/slice.h" #include "leveldb/status.h" -#include "leveldb/table_builder.h" #include "leveldb/write_batch.h" -#endif #if HAVE_ELEVELDB #include "leveldb/perf_count.h" #endif |