#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"
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;
return -EINVAL;
}
opt.create_if_missing = create_if_missing;
+ opt.wal_dir = path + ".wal";
status = rocksdb::DB::Open(opt, path, &db);
if (!status.ok()) {
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();