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: v15.2.5~25^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=16130c6e6b87b07f0e2c8f38c4d64adf054551ee;p=ceph.git os/bluestore: Added checks for compacting BlueFS log for flush and fsync ops This partially fixes https://tracker.ceph.com/issues/45903 Signed-off-by: Adam Kupczyk (cherry picked from commit fab0c7148e84b1612e8e422e1876643a7cd4070b) Conflicts: src/os/bluestore/BlueFS.cc - commits are being backported to octopus in the wrong order: 7b01af4d95bfa789b3b3247d016431fdbfd844a4 went into master before this commit, yet it has already been backported to octopus src/os/bluestore/BlueFS.h - dropped duplicate _maybe_compact_log declaration added by c4312689ab7d32239d8b91684e3f57e9c032ea2f in favor of the one from master added by fab0c7148e84b1612e8e422e1876643a7cd4070b --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index a5d2ade5ebe..417c1e0f687 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -2908,11 +2908,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 @@ -2929,7 +2942,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) diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index 516ede84189..eddabf7344f 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -352,7 +352,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 @@ -365,7 +366,6 @@ private: uint64_t jump_to = 0); uint64_t _estimate_log_size(); bool _should_compact_log(); - void _maybe_compact_log(std::unique_lock& l); enum { REMOVE_DB = 1, @@ -517,6 +517,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; @@ -554,8 +556,9 @@ public: void handle_discard(unsigned dev, interval_set& to_release); void flush(FileWriter *h, bool force = false) { - std::lock_guard l(lock); - _flush(h, force); + 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); @@ -563,7 +566,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) {