Avoid blob db call Sync() while writing

Summary:
The FsyncFiles background job call Fsync() periodically for blob files. However it can access WritableFileWriter concurrently with a Put() or Write(). And WritableFileWriter does not support concurrent access. It will lead to WritableFileWriter buffer being flush with same content twice, and blob file end up corrupted. Fixing by simply let FsyncFiles hold write_mutex_.
Closes https://github.com/facebook/rocksdb/pull/2685

Differential Revision: D5561908

Pulled By: yiwu-arbug

fbshipit-source-id: f0bb5bcab0e05694e053b8c49eab43640721e872
main
Yi Wu 7 years ago committed by Facebook Github Bot
parent 627c9f1abb
commit 0d4a2b7330
  1. 11
      utilities/blob_db/blob_db_impl.cc

@ -545,12 +545,7 @@ Status BlobDBImpl::CreateWriterLocked(const std::shared_ptr<BlobFile>& bfile) {
std::string fpath(bfile->PathName()); std::string fpath(bfile->PathName());
std::unique_ptr<WritableFile> wfile; std::unique_ptr<WritableFile> wfile;
// We are having issue that we write duplicate blob to blob file and the bug Status s = env_->ReopenWritableFile(fpath, &wfile, env_options_);
// is related to writable file buffer. Force no buffer until we fix the bug.
EnvOptions env_options = env_options_;
env_options.writable_file_max_buffer_size = 0;
Status s = env_->ReopenWritableFile(fpath, &wfile, env_options);
if (!s.ok()) { if (!s.ok()) {
ROCKS_LOG_ERROR(db_options_.info_log, ROCKS_LOG_ERROR(db_options_.info_log,
"Failed to open blob file for write: %s status: '%s'" "Failed to open blob file for write: %s status: '%s'"
@ -561,7 +556,7 @@ Status BlobDBImpl::CreateWriterLocked(const std::shared_ptr<BlobFile>& bfile) {
} }
std::unique_ptr<WritableFileWriter> fwriter; std::unique_ptr<WritableFileWriter> fwriter;
fwriter.reset(new WritableFileWriter(std::move(wfile), env_options)); fwriter.reset(new WritableFileWriter(std::move(wfile), env_options_));
uint64_t boffset = bfile->GetFileSize(); uint64_t boffset = bfile->GetFileSize();
if (debug_level_ >= 2 && boffset) { if (debug_level_ >= 2 && boffset) {
@ -1570,6 +1565,8 @@ std::pair<bool, int64_t> BlobDBImpl::CheckSeqFiles(bool aborted) {
std::pair<bool, int64_t> BlobDBImpl::FsyncFiles(bool aborted) { std::pair<bool, int64_t> BlobDBImpl::FsyncFiles(bool aborted) {
if (aborted) return std::make_pair(false, -1); if (aborted) return std::make_pair(false, -1);
MutexLock l(&write_mutex_);
std::vector<std::shared_ptr<BlobFile>> process_files; std::vector<std::shared_ptr<BlobFile>> process_files;
{ {
ReadLock rl(&mutex_); ReadLock rl(&mutex_);

Loading…
Cancel
Save