Repository navigation
fix(export): stream chunks incrementally for database dumps to prevent OOM (#59) - #317
Open
MilindChatrabhuji wants to merge 1 commit into
Open
MilindChatrabhuji wants to merge 1 commit into
MilindChatrabhuji wants to merge 1 commit into
Conversation
…t OOM (outerbase#59) - Replace monolithic string concatenation and Blob response with ReadableStream<Uint8Array> - Read table rows in chunked batches (CHUNK_SIZE = 1000) using LIMIT and OFFSET pagination - Correctly format SQL NULL, booleans, and escaped strings in INSERT statements - Expand test suite in src/export/dump.test.ts to verify chunked pagination, type serialization, streaming reader, and stream error handling
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.
Overview
Fixes #59
Currently,
/export/dumploads the entire database into memory, formats it into SQL statements via string concatenation, and converts the whole dataset into a singleBlob. On large databases (e.g. 100MB+ or up to 10GB) or inside Cloudflare Workers / Durable Objects with strict memory limits (128MB), this causes out-of-memory (OOM) errors and execution timeouts.Solution
Incremental Streaming via
ReadableStream:Blobcreation withReadableStream<Uint8Array>.SQLite format 3\0), table DDL statements, and rowINSERTstatements incrementally usingTextEncoder.Content-Type: application/x-sqlite3,Content-Disposition: attachment; filename="database_dump.sql").Chunked Pagination (
CHUNK_SIZE = 1000):SELECT * FROM <table> LIMIT 1000 OFFSET <offset>;so peak memory consumption is strictlyType Serialization & SQL Quoting:
nullandundefinedasNULL(preventing invalid SQL syntax).1and0).'${val.replace(/'/g, "''")}').Comprehensive Unit Tests:
NULL, boolean, and numeric types.ReadableStreamreader (getReader()).controller.error(err)).Verification
npx vitest run src/export/dump.test.ts(9 of 9 tests passing).npx prettier --check "src/export/dump.ts" "src/export/dump.test.ts"(clean pass).Bounty Claim
@algora-pbc /claim #59