From 69d8e4eff45938c24eded875df7be0871936a480 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 27 Jan 2010 11:24:30 -0800 Subject: [PATCH] filestore: fix journal flush --- src/os/FileJournal.cc | 14 +++++++++++++- src/os/FileJournal.h | 4 +++- src/os/FileStore.cc | 3 +++ src/os/Journal.h | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 3d03b6811a16e..f7b0b17a0e8ad 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -545,6 +545,17 @@ void FileJournal::do_write(bufferlist& bl) } } +void FileJournal::flush() +{ + write_lock.Lock(); + while ((!writeq.empty() || writing) && !write_stop) { + dout(10) << "flush waiting for writeq to empty and writes to complete" << dendl; + write_empty_cond.Wait(write_lock); + } + write_lock.Unlock(); + dout(10) << "flush done" << dendl; +} + void FileJournal::write_thread_entry() { @@ -556,6 +567,7 @@ void FileJournal::write_thread_entry() if (writeq.empty()) { // sleep dout(20) << "write_thread_entry going to sleep" << dendl; + write_empty_cond.Signal(); write_cond.Wait(write_lock); dout(20) << "write_thread_entry woke up" << dendl; continue; @@ -568,7 +580,7 @@ void FileJournal::write_thread_entry() prepare_multi_write(bl); do_write(bl); } - + write_empty_cond.Signal(); write_lock.Unlock(); dout(10) << "write_thread_entry finish" << dendl; } diff --git a/src/os/FileJournal.h b/src/os/FileJournal.h index d217c50ef9d82..93c97a00e8fee 100644 --- a/src/os/FileJournal.h +++ b/src/os/FileJournal.h @@ -100,7 +100,7 @@ private: // write thread Mutex write_lock; - Cond write_cond; + Cond write_cond, write_empty_cond; bool write_stop; Cond commit_cond; @@ -157,6 +157,8 @@ private: int open(__u64 last_seq); void close(); + void flush(); + bool is_writeable() { return read_pos == 0; } diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 0c8b1ab8e3b10..c64aaf4c0e67b 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -1391,6 +1391,9 @@ void FileStore::sync_and_flush() dout(10) << "sync_and_flush" << dendl; sync(); + if (journal) + journal->flush(); + if (g_conf.filestore_journal_writeahead) { dout(10) << "sync_and_flush waiting for journal finisher" << dendl; finisher.wait_for_empty(); diff --git a/src/os/Journal.h b/src/os/Journal.h index 26455908cd545..0584e66a2ba51 100644 --- a/src/os/Journal.h +++ b/src/os/Journal.h @@ -37,6 +37,8 @@ public: virtual int open(__u64 last_seq) = 0; virtual void close() = 0; + virtual void flush() = 0; + void set_wait_on_full(bool b) { wait_on_full = b; } // writes -- 2.39.5