From c654ffe34bd925f0ca186cd16ae8d2756fe5e3eb 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> --- 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 d76ea0d48e..841d497649 100644 --- a/db/commitlog/commitlog.cc +++ b/db/commitlog/commitlog.cc @@ -806,7 +806,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); }); }