From: Adam Kupczyk Date: Mon, 8 Jun 2020 10:41:58 +0000 (+0200) Subject: os/bluestore: Added checks for compacting BlueFS log for flush and fsync ops X-Git-Tag: v14.2.17~63^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=440783c4d6ffa62b708bf03d8ee4e35987d33026;p=ceph.git os/bluestore: Added checks for compacting BlueFS log for flush and fsync ops This fixes https://tracker.ceph.com/issues/46194 Signed-off-by: Adam Kupczyk (cherry picked from commit fab0c7148e84b1612e8e422e1876643a7cd4070b) Conflicts: src/os/bluestore/BlueFS.cc src/os/bluestore/BlueFS.h --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 3575953a56a7..61ece25b2a10 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -2548,11 +2548,24 @@ void BlueFS::wait_for_aio(FileWriter *h) } #endif -int BlueFS::_flush(FileWriter *h, bool force) +int BlueFS::_flush(FileWriter *h, bool force, std::unique_lock& l) +{ + bool flushed = false; + int r = _flush(h, force, &flushed); + if (r == 0 && flushed) { + _maybe_compact_log(l); + } + return r; +} + +int BlueFS::_flush(FileWriter *h, bool force, bool *flushed) { h->buffer_appender.flush(); uint64_t length = h->buffer.length(); uint64_t offset = h->pos; + if (flushed) { + *flushed = false; + } if (!force && length < cct->_conf->bluefs_min_flush_size) { dout(10) << __func__ << " " << h << " ignoring, length " << length @@ -2569,7 +2582,11 @@ int BlueFS::_flush(FileWriter *h, bool force) << std::hex << offset << "~" << length << std::dec << " to " << h->file->fnode << dendl; ceph_assert(h->pos <= h->file->fnode.size); - return _flush_range(h, offset, length); + int r = _flush_range(h, offset, length); + if (flushed) { + *flushed = true; + } + return r; } int BlueFS::_truncate(FileWriter *h, uint64_t offset) @@ -2857,8 +2874,14 @@ void BlueFS::sync_metadata(bool avoid_compact) dout(10) << __func__ << " done in " << (ceph_clock_now() - start) << dendl; } - if (!avoid_compact && - !cct->_conf->bluefs_replay_recovery_disable_compact && + if (!avoid_compact) { + _maybe_compact_log(l); + } +} + +void BlueFS::_maybe_compact_log(std::unique_lock& l) +{ + if (!cct->_conf->bluefs_replay_recovery_disable_compact && _should_compact_log()) { if (cct->_conf->bluefs_compact_log_sync) { _compact_log_sync(); diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index e564e031334f..86748e4afb09 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -362,7 +362,8 @@ private: PExtentVector* extents); int _flush_range(FileWriter *h, uint64_t offset, uint64_t length); - int _flush(FileWriter *h, bool force); + int _flush(FileWriter *h, bool focce, std::unique_lock& l); + int _flush(FileWriter *h, bool force, bool *flushed = nullptr); int _fsync(FileWriter *h, std::unique_lock& l); #ifdef HAVE_LIBAIO @@ -513,6 +514,8 @@ public: /// sync any uncommitted state to disk void sync_metadata(bool avoid_compact); + /// test and compact log, if necessary + void _maybe_compact_log(std::unique_lock& l); void set_slow_device_expander(BlueFSDeviceExpander* a) { slow_dev_expander = a; @@ -549,9 +552,10 @@ public: // handler for discard event void handle_discard(unsigned dev, interval_set& to_release); - void flush(FileWriter *h) { - std::lock_guard l(lock); - _flush(h, false); + void flush(FileWriter *h, bool force = false) { + std::unique_lock l(lock); + int r = _flush(h, force, l); + ceph_assert(r == 0); } void flush_range(FileWriter *h, uint64_t offset, uint64_t length) { std::lock_guard l(lock); @@ -559,7 +563,9 @@ public: } int fsync(FileWriter *h) { std::unique_lock l(lock); - return _fsync(h, l); + int r = _fsync(h, l); + _maybe_compact_log(l); + return r; } int read(FileReader *h, FileReaderBuffer *buf, uint64_t offset, size_t len, bufferlist *outbl, char *out) {