From 139ce39a00c9da50bf0424dc7abbf0dc0e2a13e3 Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Tue, 16 Sep 2025 12:24:54 +0300 Subject: [PATCH] mvcc: fix logic bug in MvStore::insert_version_raw() In insert_version_raw(), we correctly iterate the versions backwards because we want to find the newest version that is still older than the one we are inserting. However, the order of `.enumerate()` and `.rev()` was wrong, so the insertion position was calculated based on the position in the _reversed_ iterator, not the original iterator. --- core/mvcc/database/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/mvcc/database/mod.rs b/core/mvcc/database/mod.rs index 85d48b832..670b1bef0 100644 --- a/core/mvcc/database/mod.rs +++ b/core/mvcc/database/mod.rs @@ -1609,8 +1609,8 @@ impl MvStore { // we can either switch to a tree-like structure, or at least use partition_point() // which performs a binary search for the insertion point. let mut position = 0_usize; - for (i, v) in versions.iter().rev().enumerate() { - if self.get_begin_timestamp(&v.begin) < self.get_begin_timestamp(&row_version.begin) { + for (i, v) in versions.iter().enumerate().rev() { + if self.get_begin_timestamp(&v.begin) <= self.get_begin_timestamp(&row_version.begin) { position = i + 1; break; }