From ac8bef6781b880b15c688a4ebfe9c669c67d8d7c Mon Sep 17 00:00:00 2001 From: Gleb Natapov Date: Tue, 28 Jan 2020 16:51:03 +0200 Subject: [PATCH] commitlog: fix flushing an entry marked as "sync" in periodic mode After 546556b71bf9e3f9f31f1a6f we can have mixed writes into commitlog, some do flush immediately some do not. If non flushing write races with flushing one and becomes responsible for writing back its buffer into a file flush will be skipped which will cause assert in batch_cycle() to trigger since flush position will not be advanced. Fix that by checking that flush was skipped and in this case flush explicitly our file position. Fixes #5670 Message-Id: <20200128145103.GI26048@scylladb.com> (cherry picked from commit c654ffe34bd925f0ca186cd16ae8d2756fe5e3eb) --- db/commitlog/commitlog.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/db/commitlog/commitlog.cc b/db/commitlog/commitlog.cc index 7410856dd0..cb2be09405 100644 --- a/db/commitlog/commitlog.cc +++ b/db/commitlog/commitlog.cc @@ -807,7 +807,12 @@ public: // (Note: wait_for_pending(pos) waits for operation _at_ pos (and before), replay_position rp(me->_desc.id, position_type(fp)); return me->_pending_ops.wait_for_pending(rp, timeout).then([me, fp] { - assert(me->_flush_pos > fp); + assert(me->_segment_manager->cfg.mode != sync_mode::BATCH || me->_flush_pos > fp); + if (me->_flush_pos <= fp) { + // previous op we were waiting for was not sync one, so it did not flush + // force flush here + return me->do_flush(fp); + } return make_ready_future(me); }); }