zhangxffff opened a new issue, #13811:
URL: https://github.com/apache/gluten/issues/13811

   ### Bug description
   
   TPC-DS Q6 and Q10 can fail on Apache Gluten `main` when a broadcast exchange 
consumes columnar shuffle data through the Bolt backend. The task fails in 
`LowCopyNettyJniByteInputStream.read()` with `IllegalReferenceCountException: 
refCnt: 0`. This was observed on commit `5bc4512674`.
   
   ### Background
   
   Originally, `ShuffleStreamReader.nextStream()` closed the previous stream 
before returning the next one. That worked for a sequential reader because 
requesting block B meant the consumer had finished with block A.
   
   On July 10, 2026, PR #12370 introduced asynchronous shuffle reads for Velox 
GPU execution. The goal was to keep the GPU supplied with data while CPU 
workers fetched, decompressed, and deserialized shuffle blocks in parallel. 
Under that model, one worker can request B while another is still reading A. 
Closing A in the shared JVM iterator would interrupt that worker. The PR 
therefore moved responsibility for closing each stream to its native consumer 
and updated the Velox synchronous reader to close its stream at EOF. [PR 
#12370](https://github.com/apache/gluten/pull/12370) · [JVM reader 
change](https://github.com/apache/gluten/commit/fc756ffae8ad5fb9d6c33248e975d17336b2cde7#diff-56ea9448daefabc64a2e9092852322a4eda12a7b73d82d22311dcea613454815)
 · [Velox EOF 
handling](https://github.com/apache/gluten/blob/fc756ffae8ad5fb9d6c33248e975d17336b2cde7/cpp/velox/shuffle/VeloxShuffleReader.cc#L512-L523)
   
   The Bolt backend was integrated on September 10 in PR #12454. Its sequential 
reader uses the same JVM iterator together with Spark’s 
`ShuffleBlockFetcherIterator`. At EOF, Bolt executes `deserializer_ = 
nextDeserializer_()`. The right-hand side fetches B before the assignment 
destroys A’s deserializer. When A’s stream closes, Spark releases its *current* 
buffer, which now belongs to B. The next read from B can therefore encounter a 
zero reference count, even on a single thread. [Bolt integration 
#12454](https://github.com/apache/gluten/pull/12454) · [Bolt EOF 
handling](https://github.com/apache/gluten/blob/5bc4512674922d154ec72bf1251dd5f5f85b5da9/cpp/bolt/shuffle/BoltShuffleReaderWrapper.h#L49-L56)
 · [Spark buffer 
release](https://github.com/apache/spark/blob/v3.5.1/core/src/main/scala/org/apache/spark/storage/ShuffleBlockFetcherIterator.scala#L1337-L1355)
   
   ### Expected behavior and reproduction
   
   The Bolt sequential reader should close A **before** asking Spark for B. A 
native regression test demonstrates the ordering with two single-partition 
blocks written by `BoltShuffleWriter`, containing `1` and `2`. On `204bf2b3f7`, 
the fetch callback finds A still open when B is requested. Resetting the 
exhausted deserializer before fetching the next block makes the assertion pass, 
and the reader returns both values in order.
   
   Drafted with AI assistance.
   


-- 
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