feat: Add batched processing for SQLite converter to prevent OOM#78
Merged
Conversation
The SQLite to PostgreSQL converter now processes rows in batches instead of loading the entire table into memory. This enables migration of large SQLite databases (7M+ rows) without running out of memory. Changes: - Add BatchedTableReader struct for rowid-based pagination - Add read_table_batch() function for memory-efficient reading - Add convert_table_batched() async function that reads, converts, and inserts in batches - Update init_sqlite_to_postgres() to use batched processing - Use calculate_optimal_batch_size() for memory-based batch sizing - Add comprehensive tests for batched reader functionality Memory usage now stays constant regardless of table size. Batch size automatically adjusts based on available system memory (25% of free RAM, clamped between 1,000 and 50,000 rows). Fixes #77
b74b840 to
a9f466d
Compare
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BatchedTableReaderwith rowid-based pagination to read tables in chunksProblem
The SQLite converter previously loaded all rows into memory before inserting to PostgreSQL. For large tables (e.g., 7.2M rows in a 2.3GB file), this required 8-16GB of RAM, making the tool unusable on typical machines.
Solution
Now processes rows in batches:
Memory usage stays constant regardless of table size.
Changes
src/sqlite/reader.rs: AddBatchedTableReaderstruct andread_table_batch()functionsrc/sqlite/converter.rs: Addconvert_table_batched()async functionsrc/commands/init.rs: Updateinit_sqlite_to_postgres()to use batched processingTesting
Fixes #77