From ed8261a0fe09b7fc28a52cfa183dd92564e5cb68 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Wed, 27 Feb 2019 14:45:00 -0500 Subject: [PATCH 1/2] database: immediately flush tables with no memtables. If a table has no data, it may still take a long time to flush. This is because before we even try to flush, we need go acquire a permit and that can take a while if there is a long running flush already queued. We can special case the situation in which there is no data in any of the memtables owned by table and return immediately. Signed-off-by: Glauber Costa --- database.cc | 2 +- database.hh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/database.cc b/database.cc index 3cddc05fdf..a0a89367a1 100644 --- a/database.cc +++ b/database.cc @@ -1282,7 +1282,7 @@ future<> dirty_memory_manager::shutdown() { } future<> memtable_list::request_flush() { - if (!may_flush()) { + if (empty() || !may_flush()) { return make_ready_future<>(); } else if (!_flush_coalescing) { _flush_coalescing = shared_promise<>(); diff --git a/database.hh b/database.hh index bd3319857a..a107505cb7 100644 --- a/database.hh +++ b/database.hh @@ -201,6 +201,14 @@ public: return bool(_seal_immediate_fn); } + bool empty() const { + for (auto& m : _memtables) { + if (!m->empty()) { + return false; + } + } + return true; + } shared_memtable back() { return _memtables.back(); } From c2c6c71398470995a739fc35bc5347de8d4148b5 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Wed, 27 Feb 2019 15:09:57 -0500 Subject: [PATCH 2/2] truncate: do not flush memtables if auto_snapshot is false. Right now we flush memtables if the table is durable (which in practice it almost always is). We are truncating, so we don't want the data. We should only flush if auto_snapshot is true. Signed-off-by: Glauber Costa --- database.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/database.cc b/database.cc index a0a89367a1..ba911f9484 100644 --- a/database.cc +++ b/database.cc @@ -1683,9 +1683,8 @@ future<> database::truncate(sstring ksname, sstring cfname, timestamp_func tsf) future<> database::truncate(const keyspace& ks, column_family& cf, timestamp_func tsf, bool with_snapshot) { return cf.run_async([this, &ks, &cf, tsf = std::move(tsf), with_snapshot] { - const auto durable = ks.metadata()->durable_writes(); const auto auto_snapshot = with_snapshot && get_config().auto_snapshot(); - const auto should_flush = durable || auto_snapshot; + const auto should_flush = auto_snapshot; // Force mutations coming in to re-acquire higher rp:s // This creates a "soft" ordering, in that we will guarantee that