Commit 72d00eff authored by yiwu-arbug's avatar yiwu-arbug Committed by Yi Wu

Sync titan directory when adding blob files (#136)

Summary:
When adding new blob file, titan directory need to be fsync, otherwise files can be lost after power outage.

Test Plan:
run `strace -yfe fsync ./titan_titan_db_test --gtest_filter=*.Snapshot` and see titan directory being fsync-ed in the output.
Signed-off-by: 's avatarYi Wu <yiwu@pingcap.com>
parent 4ea03273
...@@ -74,6 +74,10 @@ class TitanDBImpl::FileManager : public BlobFileManager { ...@@ -74,6 +74,10 @@ class TitanDBImpl::FileManager : public BlobFileManager {
Slice(file.first->largest_key()).ToString(true).c_str()); Slice(file.first->largest_key()).ToString(true).c_str());
edit.AddBlobFile(file.first); edit.AddBlobFile(file.first);
} }
s = db_->directory_->Fsync();
if (!s.ok()) {
return s;
}
{ {
MutexLock l(&db_->mutex_); MutexLock l(&db_->mutex_);
...@@ -232,6 +236,10 @@ Status TitanDBImpl::OpenImpl(const std::vector<TitanCFDescriptor>& descs, ...@@ -232,6 +236,10 @@ Status TitanDBImpl::OpenImpl(const std::vector<TitanCFDescriptor>& descs,
if (!s.ok()) { if (!s.ok()) {
return s; return s;
} }
s = env_->NewDirectory(dirname_, &directory_);
if (!s.ok()) {
return s;
}
s = env_->LockFile(LockFileName(dirname_), &lock_); s = env_->LockFile(LockFileName(dirname_), &lock_);
if (!s.ok()) { if (!s.ok()) {
return s; return s;
......
...@@ -256,6 +256,7 @@ class TitanDBImpl : public TitanDB { ...@@ -256,6 +256,7 @@ class TitanDBImpl : public TitanDB {
EnvOptions env_options_; EnvOptions env_options_;
DBImpl* db_impl_; DBImpl* db_impl_;
TitanDBOptions db_options_; TitanDBOptions db_options_;
std::unique_ptr<Directory> directory_;
std::atomic<bool> initialized_{false}; std::atomic<bool> initialized_{false};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment