From 8959063c9c98be4c97b6724ef5135aa4a40363a0 Mon Sep 17 00:00:00 2001 From: Yanqin Jin Date: Fri, 14 Sep 2018 13:17:12 -0700 Subject: [PATCH] Store the return value of Fsync for check Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/4361 Differential Revision: D9803723 Pulled By: riversand963 fbshipit-source-id: 5a0d4cd3e57fd195571dcd5822895ee00547fa6a --- db/compaction_job.cc | 8 ++++---- db/flush_job.cc | 4 ++-- util/filename.cc | 2 +- utilities/backupable/backupable_db.cc | 18 +++++++++--------- utilities/blob_db/blob_db_impl.cc | 6 +++++- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/db/compaction_job.cc b/db/compaction_job.cc index ada49103c..b0a19ead4 100644 --- a/db/compaction_job.cc +++ b/db/compaction_job.cc @@ -593,10 +593,6 @@ Status CompactionJob::Run() { thread.join(); } - if (output_directory_) { - output_directory_->Fsync(); - } - compaction_stats_.micros = env_->NowMicros() - start_micros; MeasureTime(stats_, COMPACTION_TIME, compaction_stats_.micros); @@ -611,6 +607,10 @@ Status CompactionJob::Run() { } } + if (status.ok() && output_directory_) { + status = output_directory_->Fsync(); + } + if (status.ok()) { thread_pool.clear(); std::vector files_meta; diff --git a/db/flush_job.cc b/db/flush_job.cc index c7a299ece..1fee162ab 100644 --- a/db/flush_job.cc +++ b/db/flush_job.cc @@ -371,8 +371,8 @@ Status FlushJob::WriteLevel0Table() { s.ToString().c_str(), meta_.marked_for_compaction ? " (needs compaction)" : ""); - if (output_file_directory_ != nullptr) { - output_file_directory_->Fsync(); + if (s.ok() && output_file_directory_ != nullptr) { + s = output_file_directory_->Fsync(); } TEST_SYNC_POINT("FlushJob::WriteLevel0Table"); db_mutex_->Lock(); diff --git a/util/filename.cc b/util/filename.cc index d9516fd76..32289aecb 100644 --- a/util/filename.cc +++ b/util/filename.cc @@ -377,7 +377,7 @@ Status SetCurrentFile(Env* env, const std::string& dbname, } if (s.ok()) { if (directory_to_fsync != nullptr) { - directory_to_fsync->Fsync(); + s = directory_to_fsync->Fsync(); } } else { env->DeleteFile(tmp); diff --git a/utilities/backupable/backupable_db.cc b/utilities/backupable/backupable_db.cc index 3a880cbe9..4cafc6ab1 100644 --- a/utilities/backupable/backupable_db.cc +++ b/utilities/backupable/backupable_db.cc @@ -874,19 +874,19 @@ Status BackupEngineImpl::CreateNewBackupWithMetadata( GetAbsolutePath(GetPrivateFileRel(new_backup_id, false)), &backup_private_directory); if (backup_private_directory != nullptr) { - backup_private_directory->Fsync(); + s = backup_private_directory->Fsync(); } - if (private_directory_ != nullptr) { - private_directory_->Fsync(); + if (s.ok() && private_directory_ != nullptr) { + s = private_directory_->Fsync(); } - if (meta_directory_ != nullptr) { - meta_directory_->Fsync(); + if (s.ok() && meta_directory_ != nullptr) { + s = meta_directory_->Fsync(); } - if (shared_directory_ != nullptr) { - shared_directory_->Fsync(); + if (s.ok() && shared_directory_ != nullptr) { + s = shared_directory_->Fsync(); } - if (backup_directory_ != nullptr) { - backup_directory_->Fsync(); + if (s.ok() && backup_directory_ != nullptr) { + s = backup_directory_->Fsync(); } } diff --git a/utilities/blob_db/blob_db_impl.cc b/utilities/blob_db/blob_db_impl.cc index 50c9a0784..8ea4bacd9 100644 --- a/utilities/blob_db/blob_db_impl.cc +++ b/utilities/blob_db/blob_db_impl.cc @@ -1732,7 +1732,11 @@ std::pair BlobDBImpl::DeleteObsoleteFiles(bool aborted) { // directory change. Fsync if (file_deleted) { - dir_ent_->Fsync(); + Status s = dir_ent_->Fsync(); + if (!s.ok()) { + ROCKS_LOG_ERROR(db_options_.info_log, "Failed to sync dir %s: %s", + blob_dir_.c_str(), s.ToString().c_str()); + } } // put files back into obsolete if for some reason, delete failed