Skip to content

Commit ac53791

Browse files
committed
Patch Turso effective_temp_store to always return Memory
The disk-temp pager has a state-dependent `short read on page N` bug that breaks testCreateTemporaryTable + testTemporaryTableHasPriorityOverStandardTable mid-suite. Setting PRAGMA temp_store = MEMORY at runtime fixes those tests but crashes testReconstructTable in Turso's pager — `set_temp_store` calls `bump_prepare_context_generation` which seems to corrupt state testReconstructTable depends on later (project_turso_testreconstructtable_fragile). Patch `effective_temp_store` in core/connection.rs to return `TempStore::Memory` unconditionally, at compile time. This forces `create_temp_database` to take the MemoryIO branch always, but without going through any runtime mutator, so prepared-statement caches and other transient state aren't invalidated.
1 parent 472d4c4 commit ac53791

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,50 @@ jobs:
595595
print('patched CreateTrigger to preserve original SQL text')
596596
PY_TRIGGER_SQL
597597
598+
# Force temp tables to use MemoryIO under all conditions, to
599+
# bypass the disk-temp pager's state-dependent
600+
# `short read on page N` bug that breaks
601+
# testCreateTemporaryTable + testTemporaryTableHasPriorityOverStandardTable.
602+
#
603+
# Setting this via runtime PRAGMA temp_store = MEMORY crashes
604+
# testReconstructTable in the pager (memory:
605+
# project_turso_testreconstructtable_fragile). Instead, patch
606+
# `effective_temp_store` so it returns `TempStore::Memory`
607+
# unconditionally — a compile-time change that doesn't go
608+
# through `set_temp_store` / `bump_prepare_context_generation`,
609+
# so testReconstructTable's prepared-statement cache is
610+
# untouched.
611+
python3 - <<'PY_TEMP_MEMORY'
612+
p = 'core/connection.rs'
613+
s = open(p).read()
614+
old = (
615+
" fn effective_temp_store(&self) -> crate::TempStore {\n"
616+
" let temp_store = self.get_temp_store();\n"
617+
" #[cfg(feature = \"fs\")]\n"
618+
" {\n"
619+
" temp_store\n"
620+
" }\n"
621+
" #[cfg(not(feature = \"fs\"))]\n"
622+
" {\n"
623+
" let _ = temp_store;\n"
624+
" crate::TempStore::Memory\n"
625+
" }\n"
626+
" }\n"
627+
)
628+
new = (
629+
" fn effective_temp_store(&self) -> crate::TempStore {\n"
630+
" // Always use MemoryIO for temp tables: avoids a state-dependent\n"
631+
" // `short read on page N` bug in the disk-temp pager that breaks\n"
632+
" // testCreateTemporaryTable mid-suite under PHPUnit.\n"
633+
" let _ = self.get_temp_store();\n"
634+
" crate::TempStore::Memory\n"
635+
" }\n"
636+
)
637+
assert old in s, 'effective_temp_store block not found'
638+
open(p, 'w').write(s.replace(old, new, 1))
639+
print('patched effective_temp_store to always return TempStore::Memory')
640+
PY_TEMP_MEMORY
641+
598642
echo '--- Patched stub! macro ---'
599643
sed -n '/macro_rules! stub/,/^}$/p' sqlite3/src/lib.rs
600644

0 commit comments

Comments
 (0)