Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions rivetkit-typescript/packages/sqlite-native/src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,15 +837,14 @@ unsafe extern "C" fn kv_io_truncate(p_file: *mut sqlite3_file, size: sqlite3_int
}
}

let mut keys_to_delete = Vec::new();
let mut chunk_idx = last_chunk_to_keep + 1;
while chunk_idx <= last_existing_chunk {
keys_to_delete.push(kv::get_chunk_key(file.file_tag, chunk_idx as u32).to_vec());
chunk_idx += 1;
}

for chunk in keys_to_delete.chunks(KV_MAX_BATCH_KEYS) {
if ctx.kv_delete(chunk.to_vec()).is_err() {
if last_chunk_to_keep < last_existing_chunk {
if ctx
.kv_delete_range(
kv::get_chunk_key(file.file_tag, (last_chunk_to_keep + 1) as u32).to_vec(),
kv::get_chunk_key_range_end(file.file_tag).to_vec(),
)
.is_err()
{
return SQLITE_IOERR_TRUNCATE;
}
}
Expand Down
13 changes: 4 additions & 9 deletions rivetkit-typescript/packages/sqlite-vfs/src/vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1324,15 +1324,10 @@ class SqliteSystem implements SqliteVfsRegistration {
}
}

// Delete chunks beyond the new size
const keysToDelete: Uint8Array[] = [];
for (let i = lastChunkToKeep + 1; i <= lastExistingChunk; i++) {
keysToDelete.push(this.#chunkKey(file, i));
}

for (let b = 0; b < keysToDelete.length; b += KV_MAX_BATCH_KEYS) {
await options.deleteBatch(
keysToDelete.slice(b, b + KV_MAX_BATCH_KEYS),
if (lastChunkToKeep < lastExistingChunk) {
await options.deleteRange(
this.#chunkKey(file, lastChunkToKeep + 1),
getChunkKeyRangeEnd(file.fileTag),
);
}
} catch (error) {
Expand Down
Loading