Unverified Commit 3b267dc5 authored by yiwu-arbug's avatar yiwu-arbug Committed by GitHub

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 01f293da
......@@ -74,6 +74,10 @@ class TitanDBImpl::FileManager : public BlobFileManager {
Slice(file.first->largest_key()).ToString(true).c_str());
edit.AddBlobFile(file.first);
}
s = db_->directory_->Fsync();
if (!s.ok()) {
return s;
}
{
MutexLock l(&db_->mutex_);
......@@ -232,6 +236,10 @@ Status TitanDBImpl::OpenImpl(const std::vector<TitanCFDescriptor>& descs,
if (!s.ok()) {
return s;
}
s = env_->NewDirectory(dirname_, &directory_);
if (!s.ok()) {
return s;
}
s = env_->LockFile(LockFileName(dirname_), &lock_);
if (!s.ok()) {
return s;
......
......@@ -256,6 +256,7 @@ class TitanDBImpl : public TitanDB {
EnvOptions env_options_;
DBImpl* db_impl_;
TitanDBOptions db_options_;
std::unique_ptr<Directory> directory_;
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