]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os: bring leveldbstore options up to date
authorGreg Farnum <greg@inktank.com>
Wed, 10 Apr 2013 22:58:42 +0000 (15:58 -0700)
committerGreg Farnum <greg@inktank.com>
Fri, 12 Apr 2013 23:29:02 +0000 (16:29 -0700)
LevelDB has a lot of options which we don't implement right now. Add
an options struct to the LevelDBStore which users can access as they
wish in order to set values different from the defaults.
This will let us set various size values, as well as turning on
caching or bloom filter read optimizations.

Signed-off-by: Jim Schutt <jaschut@sandia.gov>
Signed-off-by: Greg Farnum <greg@inktank.com>
src/os/LevelDBStore.cc
src/os/LevelDBStore.h

index 3d94096f93e272a219081991a5b32fd4fc8d7bff..d7d125343a69ceaa83b0903b87ece7c383a0b66e 100644 (file)
@@ -6,18 +6,42 @@
 #include <map>
 #include <string>
 #include <tr1/memory>
-#include "leveldb/db.h"
-#include "leveldb/write_batch.h"
-#include "leveldb/slice.h"
 #include <errno.h>
 using std::string;
 
 int LevelDBStore::init(ostream &out, bool create_if_missing)
 {
-  leveldb::Options options;
-  options.create_if_missing = create_if_missing;
+  leveldb::Options ldoptions;
+
+  if (options.write_buffer_size)
+    ldoptions.write_buffer_size = options.write_buffer_size;
+  if (options.max_open_files)
+    ldoptions.max_open_files = options.max_open_files;
+  if (options.cache_size) {
+    leveldb::Cache *_db_cache = leveldb::NewLRUCache(options.cache_size);
+    db_cache.reset(_db_cache);
+    ldoptions.block_cache = db_cache.get();
+  }
+  if (options.block_size)
+    ldoptions.block_size = options.block_size;
+  if (options.bloom_size) {
+    const leveldb::FilterPolicy *_filterpolicy =
+       leveldb::NewBloomFilterPolicy(options.bloom_size);
+    filterpolicy.reset(_filterpolicy);
+    ldoptions.filter_policy = filterpolicy.get();
+  }
+  if (!options.compression_enabled)
+    ldoptions.compression = leveldb::kNoCompression;
+  if (options.block_restart_interval)
+    ldoptions.block_restart_interval = options.block_restart_interval;
+
+  ldoptions.error_if_exists = options.error_if_exists;
+  ldoptions.paranoid_checks = options.paranoid_checks;
+  ldoptions.compression = leveldb::kNoCompression;
+  ldoptions.create_if_missing = create_if_missing;
+
   leveldb::DB *_db;
-  leveldb::Status status = leveldb::DB::Open(options, path, &_db);
+  leveldb::Status status = leveldb::DB::Open(ldoptions, path, &_db);
   db.reset(_db);
   if (!status.ok()) {
     out << status.ToString() << std::endl;
index 7f0e1542443d423eae4e3a3d6a4a6a4e87528092..3d3b8e818f1d61b55bdbacbfba225c4a7e0f3ccf 100644 (file)
@@ -14,6 +14,8 @@
 #include "leveldb/db.h"
 #include "leveldb/write_batch.h"
 #include "leveldb/slice.h"
+#include "leveldb/cache.h"
+#include "leveldb/filter_policy.h"
 
 /**
  * Uses LevelDB to implement the KeyValueDB interface
 class LevelDBStore : public KeyValueDB {
   string path;
   boost::scoped_ptr<leveldb::DB> db;
+  boost::scoped_ptr<leveldb::Cache> db_cache;
+  boost::scoped_ptr<const leveldb::FilterPolicy> filterpolicy;
 
   int init(ostream &out, bool create_if_missing);
 
 public:
-  LevelDBStore(const string &path) : path(path) {}
+  /**
+   * options_t: Holds options which are minimally interpreted
+   * on initialization and then passed through to LevelDB.
+   * We transform a couple of these into actual LevelDB
+   * structures, but the rest are simply passed through unchanged. See
+   * leveldb/options.h for more precise details on each.
+   *
+   * Set them after constructing the LevelDBStore, but before calling
+   * open() or create_and_open().
+   */
+  struct options_t {
+    uint64_t write_buffer_size; /// in-memory write buffer size
+    int max_open_files; /// maximum number of files LevelDB can open at once
+    uint64_t cache_size; /// size of extra decompressed cache to use
+    uint64_t block_size; /// user data per block
+    int bloom_size; /// number of bits per entry to put in a bloom filter
+    bool compression_enabled; /// whether to use libsnappy compression or not
+
+    // don't change these ones. No, seriously
+    int block_restart_interval;
+    bool error_if_exists;
+    bool paranoid_checks;
+
+    options_t() :
+      write_buffer_size(0), //< 0 means default
+      max_open_files(0), //< 0 means default
+      cache_size(0), //< 0 means no cache (default)
+      block_size(0), //< 0 means default
+      bloom_size(0), //< 0 means no bloom filter (default)
+      compression_enabled(true), //< set to false for no compression
+      block_restart_interval(0), //< 0 means default
+      error_if_exists(false), //< set to true if you want to check nonexistence
+      paranoid_checks(false) //< set to true if you want paranoid checks
+    {}
+  } options;
+
+  LevelDBStore(const string &path) :
+    path(path),
+    db_cache(NULL),
+    filterpolicy(NULL),
+    options()
+  {}
+
+  ~LevelDBStore() {}
 
   /// Opens underlying db
   int open(ostream &out) {