feat(helpers): streaming bulk-ingest with bounded memory - #495
Conversation
✅MegaLinter analysis: Success
Notices📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining See detailed reports in MegaLinter artifacts MegaLinter is graciously provided by OX Security |
JoshMock
left a comment
There was a problem hiding this comment.
Very nice. Just one question but LGTM regardless. 👏
| let bufBytes = 0 | ||
|
|
||
| const submitBatch = async (body: string): Promise<void> => { | ||
| await sem.acquire() |
There was a problem hiding this comment.
Nice. Very similar to how the bulk helper is implemented in the JS client. 👏
| reporter.report(res.total, res.errors) | ||
| }).catch(err => { | ||
| errors.push(err) | ||
| }).finally(() => sem.release()) |
There was a problem hiding this comment.
If this is released in a finally, is there any situation where one batch would completely fail to be ingested, but others would? If so, does the errors array capture enough detail to help identify what data has not been ingested? Or do we just assume they'd follow up with another bulk ingest that upserts to handle failures?
There was a problem hiding this comment.
thanks for catching this! i was focused on the happy path and missed that a fully failed batch wasn't being counted anywhere, so the summary would undercount... and only the first failed batch's error ever surfaced, so a second failure would've been silently lost.
fixed both: every batch's doc count gets counted now no matter what happens, and the error message lists every failed batch instead of just the first one.
|
A few things an agent review noted that might be worth running down. It went pretty hardcore so feel free to file some as follow-ups using your discretion.
|
|
went through the rest of these. fixed in this pr:
filed as a follow-up: #498, the added tests for all three fixes plus the missing-file/empty-file/header-only-csv edge cases. |
Replaces the buffered
readFileSync+splitIntoBatchesapproach with line-by-line streaming bounded toflush_bytes * concurrencybytes, so ingesting large files no longer requires loading the full dataset into memory. Concurrency is controlled with a semaphore that provides backpressure. NDJSON, JSON arrays, and CSV are all supported.Closes #443