airborne12 commented on code in PR #70593:
URL: https://github.com/apache/doris/pull/70593#discussion_r4750490070


##########
be/src/storage/index/inverted/snii/writer/logical_index_writer.cpp:
##########
@@ -1071,6 +1171,25 @@ Status LogicalIndexWriter::finalize_build() {
     std::vector<uint64_t>().swap(term_hashes_); // release
     term_hashes_reservation_.reset();
 
+    // The gram summary is written only where it can skip blocks 
(dict_gram_summary.h).
+    gram_summary_bytes_.clear();
+    gram_summary_built_ = false;
+    if (dict_gram_summary_enabled_ && gram_summary_.prunes()) {
+        ByteSink summary_sink;
+        gram_summary_.finish(&summary_sink);

Review Comment:
   Confirmed and fixed in a498b38737f.
   
   `finish()` built the gram order, row offsets, encoded rows, a section buffer 
and a copy of it without a reservation, and only the retained section was 
charged afterwards, so a near-cap merge could overrun its workspace and then 
fail on the late charge.
   
   - `DictGramSummaryBuilder::serialization_sizes()` gives the exact section 
size and the scratch `finish()` takes (the gram order). `finish()` now writes 
straight into the caller's sink, so the rows, offsets and section are no longer 
staged and copied. The section bytes are unchanged.
   - `LogicalIndexWriter::build_dict_gram_summary_section()` checks the 
dictionary ratio before serializing, then reserves the scratch and the section 
as the null bitmap and bsbf paths do. On `MEM_LIMIT_EXCEEDED` it leaves the 
optional summary out instead of failing the build.
   
   Tests:
   - `SniiDictGramSummaryWalk.SummaryThatCannotBeReservedIsLeftOut` finishes a 
streamed session under a hard-limit reporter while another session takes every 
byte it frees, one byte short of what finishing takes. Before the fix it failed 
with `[MEM_LIMIT_EXCEEDED] SNII memory reservation exceeds limit: request=15768 
current=1073726057 cap=1073741824`. Now the session finishes without the 
summary, and a contains expansion still returns every matching term.
   - `SniiDictGramSummary.SerializationSizesMatchTheSection` checks that 
`finish()` writes exactly `serialization_sizes().section_bytes` into a sink 
reserved to that size, without regrowing it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to