]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Added checks for compacting BlueFS log for flush and fsync ops
authorAdam Kupczyk <akupczyk@redhat.com>
Mon, 8 Jun 2020 10:41:58 +0000 (12:41 +0200)
committerNathan Cutler <ncutler@suse.com>
Sat, 15 Aug 2020 15:04:28 +0000 (17:04 +0200)
This partially fixes https://tracker.ceph.com/issues/45903

Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
(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

src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h

index a5d2ade5ebe8374916a35c11e45055412965e2c6..417c1e0f68717a52ac5d8baf9b7f4cae9bc449cb 100644 (file)
@@ -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<ceph::mutex>& 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)
index 516ede84189177ff101deb29e8a6ac706086c77f..eddabf7344f25f42019a1791260cf1fb931e1e1e 100644 (file)
@@ -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<ceph::mutex>& l);
+  int _flush(FileWriter *h, bool force, bool *flushed = nullptr);
   int _fsync(FileWriter *h, std::unique_lock<ceph::mutex>& 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<ceph::mutex>& 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<ceph::mutex>& l);
 
   void set_slow_device_expander(BlueFSDeviceExpander* a) {
     slow_dev_expander = a;
@@ -554,8 +556,9 @@ public:
   void handle_discard(unsigned dev, interval_set<uint64_t>& 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) {