]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/RocksDBStore: set up $path.wal -> $path symlink
authorSage Weil <sage@redhat.com>
Mon, 5 Oct 2015 20:00:37 +0000 (16:00 -0400)
committerSage Weil <sage@redhat.com>
Mon, 16 Nov 2015 18:23:15 +0000 (13:23 -0500)
If $path.wal doesn't exist, create it and symlink it to $path.
Set wal_dir to that.  This makes it easy to move the wal content
elsewhere later, or to pre-create the .wal dir.

Signed-off-by: Sage Weil <sage@redhat.com>
src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h

index 6dfde87a8900eb3c8aafae5a2f040307c8ccbb7c..a6d071e48aaf6f467bff5ec53aac8fbeb0aaa5f2 100644 (file)
@@ -6,6 +6,9 @@
 #include <string>
 #include <memory>
 #include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "rocksdb/db.h"
 #include "rocksdb/table.h"
@@ -107,6 +110,26 @@ int RocksDBStore::init(string _options_str)
   return 0;
 }
 
+int RocksDBStore::create_and_open(ostream &out)
+{
+  // create tertiary paths
+  string wal_path = path + ".wal";
+  struct stat st;
+  int r = ::stat(wal_path.c_str(), &st);
+  if (r < 0)
+    r = -errno;
+  if (r == -ENOENT) {
+    unsigned slashoff = path.rfind('/');
+    string target = path.substr(slashoff + 1);
+    r = ::symlink(target.c_str(), wal_path.c_str());
+    if (r < 0) {
+      out << "failed to symlink " << wal_path << " to " << target;
+      return -errno;
+    }
+  }
+  return do_open(out, true);
+}
+
 int RocksDBStore::do_open(ostream &out, bool create_if_missing)
 {
   rocksdb::Options opt;
@@ -117,6 +140,7 @@ int RocksDBStore::do_open(ostream &out, bool create_if_missing)
     return -EINVAL;
   }
   opt.create_if_missing = create_if_missing;
+  opt.wal_dir = path + ".wal";
 
   status = rocksdb::DB::Open(opt, path, &db);
   if (!status.ok()) {
index 257bb2d1c24bef8038f6645d307749c6832c2e33..90523c451b71ce94594669df7dde611cd56543a3 100644 (file)
@@ -124,9 +124,7 @@ public:
     return do_open(out, false);
   }
   /// Creates underlying db if missing and opens it
-  int create_and_open(ostream &out) {
-    return do_open(out, true);
-  }
+  int create_and_open(ostream &out);
 
   void close();