Repository navigation
Conversation
After a document with a lot of text the next segment reserved a hundred times its size, gigabytes for a small batch.
The file size limit does not bound the text, Tika can turn a binary it takes for text into more text than the file size.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 15 |
🟢 Coverage 88.89% diff coverage · +0.02% coverage variation
Metric Results Coverage variation ✅ +0.02% coverage variation (-1.00%) Diff coverage ✅ 88.89% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (2112327) 95362 29790 31.24% Head commit (eca787e) 95389 (+27) 29816 (+26) 31.26% (+0.02%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#4132) 27 24 88.89% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
Release plan for this one: The text limit adds a new setting, You could argue for shipping the limit as a patch too. It's a safety limit against a memory problem, and the default is chosen so ordinary documents aren't affected. Still, it's a new option and a small change in what gets indexed, so to stay on the safe side I'd put it in the next feature release. The zapx change is a different case. It adds no config and only changes how much memory indexing uses, and on its own it already prevents the OOM from #4066 (9.2 GiB down to 1.9 GiB in the reproducer, and no more OOM kill with the default batch size). I'd backport just that commit to the stable branch as a patch release, so affected installs get the fix without waiting for the feature release. @micbar do you agree with that? |
A forced reindex in #4066 got the server OOM-killed at over 9 GB. The memory went up on a small JPEG, right after a 9.7 MiB Paint.NET file was indexed.
Two problems add up. Tika takes the
.pdnfile fortext/plain, because it starts with an ASCII XML header, and returns the whole file as text: 18.5 MB from a 9.7 MiB file.SEARCH_CONTENT_EXTRACTION_SIZE_LIMITonly checks the file size, so all of it got indexed. That document is bigger than the 16 MiB batch limit, so it gets a segment of its own. zapx then sized the buffer for the next segment as the previous segment's bytes per document times (documents + 100). For the next file that was 101 times the large segment, about 8.5 GB reserved for a single small JPEG.What changes:
SEARCH_CONTENT_EXTRACTION_TEXT_LIMIT, default 16 MiB. That matches the most a batch holds, so a single document never costs more than a full batch. The cut doesn't split a character and goes back to the last space when that's close. The text is cut before language detection, so Tika doesn't get the full text sent back either.0turns the limit off.Peak RSS indexing the extracted text of a synthetic
.pdnfile with the same layout as the reporter's (PDN3magic, XML header with a base64 thumbnail, compressed data), between 2000 small documents before it and 3000 after:SEARCH_BATCH_SIZE=1Real text needs about 60 MiB per MB at peak, text from a binary taken for text about 110 MiB per MB. So at the 16 MiB limit that comes to roughly 1 GiB for real text and up to 1.9 GiB for binary garbage.
Unit tests cover the cut and the zapx coverage, and a test checks that the document after a large one no longer allocates hundreds of MB.
Fixes #4066
Assisted by Claude Opus 5.5