make insert idx re-entrant

This commit is contained in:
Pere Diaz Bou
2025-04-09 15:01:40 +02:00
parent d9453f6e06
commit 12899034c9
2 changed files with 18 additions and 1 deletions

View File

@@ -3885,6 +3885,13 @@ impl BTreeCursor {
fn get_immutable_record(&self) -> std::cell::RefMut<'_, Option<ImmutableRecord>> {
self.reusable_immutable_record.borrow_mut()
}
pub fn is_write_in_progress(&self) -> bool {
match self.state {
CursorState::Write(_) => true,
_ => false,
}
}
}
#[cfg(debug_assertions)]

View File

@@ -3761,7 +3761,17 @@ pub fn op_idx_insert_async(
} else {
flags.has(IdxInsertFlags::USE_SEEK)
};
// insert record as key
// To make this reentrant in case of `moved_before` = false, we need to check if the previous cursor.insert started
// a write/balancing operation. If it did, it means we already moved to the place we wanted.
let moved_before = if cursor.is_write_in_progress() {
true
} else {
moved_before
};
// Start insertion of row. This might trigger a balance procedure which will take care of moving to different pages,
// therefore, we don't want to seek again if that happens, meaning we don't want to return on io without moving to `Await` opcode
// because it could trigger a movement to child page after a balance root which will leave the current page as the root page.
return_if_io!(cursor.insert(&BTreeKey::new_index_key(record), moved_before));
}
state.pc += 1;