From 8398ad011735cb2230f141b7fea2b1d6bee65e5f Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 27 Nov 2021 01:11:50 +0300 Subject: [PATCH] Fix #36 - Fix old version data sometimes overriding new version data Reproduction case: - v3 = (offset 4kb, length 16kb) - v2 = (offset 24kb, length 16kb) - v1 = (offset 16kb, length 16kb) - At the third step it was inserting 16..24kb instead of 20..24kb --- src/blockstore_flush.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/blockstore_flush.cpp b/src/blockstore_flush.cpp index 08cf194a..9af37436 100644 --- a/src/blockstore_flush.cpp +++ b/src/blockstore_flush.cpp @@ -743,12 +743,15 @@ bool journal_flusher_co::scan_dirty(int wait_base) offset = dirty_it->second.offset; end_offset = dirty_it->second.offset + dirty_it->second.len; it = v.begin(); - while (1) + while (end_offset > offset) { for (; it != v.end(); it++) - if (it->offset >= offset) + if (it->offset+it->len > offset) break; - if (it == v.end() || it->offset > offset && it->len > 0) + // If all items end before offset or if the found item starts after end_offset, just insert the buffer + // If (offset < it->offset < end_offset) insert (offset..it->offset) part + // If (it->offset <= offset <= it->offset+it->len) then just skip to it->offset+it->len + if (it == v.end() || it->offset > offset) { submit_offset = dirty_it->second.location + offset - dirty_it->second.offset; submit_len = it == v.end() || it->offset >= end_offset ? end_offset-offset : it->offset-offset; @@ -772,7 +775,7 @@ bool journal_flusher_co::scan_dirty(int wait_base) } } offset = it->offset+it->len; - if (it == v.end() || offset >= end_offset) + if (it == v.end()) break; } }