From: Sage Weil Date: Mon, 5 Oct 2015 20:00:37 +0000 (-0400) Subject: os/RocksDBStore: set up $path.wal -> $path symlink X-Git-Tag: v10.0.1~39^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=eddb00bd4f505d168cdbd53a8574313628fe8b91;p=ceph.git os/RocksDBStore: set up $path.wal -> $path symlink 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 --- diff --git a/src/kv/RocksDBStore.cc b/src/kv/RocksDBStore.cc index 6dfde87a8900..a6d071e48aaf 100644 --- a/src/kv/RocksDBStore.cc +++ b/src/kv/RocksDBStore.cc @@ -6,6 +6,9 @@ #include #include #include +#include +#include +#include #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()) { diff --git a/src/kv/RocksDBStore.h b/src/kv/RocksDBStore.h index 257bb2d1c24b..90523c451b71 100644 --- a/src/kv/RocksDBStore.h +++ b/src/kv/RocksDBStore.h @@ -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();