From b8eb4ed9cd8db966e5afcb8ef3e1ac475b332be2 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Thu, 6 Jul 2017 18:33:44 +0200 Subject: [PATCH] commitlog: Discard active but unused segments on shutdown So that they are not left on disk even though we did a clean shutdown. First part of the fix is to ensure that closed segments are recognized as not allocating (_closed flag). Not doing this prevents them from being collected by discard_unused_segments(). Second part is to actually call discard_unused_segments() on shutdown after all segments were shut down, so that those whose position are cleared can be removed. Fixes #2550. Message-Id: <1499358825-17855-1-git-send-email-tgrabiec@scylladb.com> (cherry picked from commit 6555a2f50b152713bc27e0a17a2537fed262978a) --- db/commitlog/commitlog.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/commitlog/commitlog.cc b/db/commitlog/commitlog.cc index 6ec5521a43..c2fe02429b 100644 --- a/db/commitlog/commitlog.cc +++ b/db/commitlog/commitlog.cc @@ -511,6 +511,7 @@ public: if (shutdown) { auto me = shared_from_this(); return _gate.close().then([me] { + me->_closed = true; return me->sync().finally([me] { // When we get here, nothing should add ops, // and we should have waited out all pending. @@ -1319,6 +1320,7 @@ future<> db::commitlog::segment_manager::shutdown() { return _gate.close().then(std::bind(&segment_manager::sync_all_segments, this, true)); }); }).finally([this] { + discard_unused_segments(); // Now that the gate is closed and requests completed we are sure nobody else will pop() return clear_reserve_segments().finally([this] { return std::move(_reserve_replenisher).then_wrapped([this] (auto f) {