Fix TiFlash hang issue after #9072#9424
Conversation
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
|
/cc @SeaRise |
|
@windtalker: GitHub didn't allow me to request PR reviews from the following users: SeaRise. Note that only pingcap members and repo collaborators can review this PR, and authors cannot review their own PRs. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
That's amazing! |
have no chance to be notified |
|
How about modifying the waitForWritable method of ExchangeWriter so that it returns WaitResult::Ready even if the tunnel is not ready, as long as the cache has not reached the limit? Then, when sink->write detects that the tunnel is not ready, it returns WaitResult::WAIT_FOR_NOTIFY. This way, when the sink is notified, it will definitely write to the mpmcqueue, preventing any hang-ups? |
BY "even if the tunnel is not ready" you mean the tunnel is not connected or the tunnel is full? |
I mean tunnel is full. |
|
Considering this case:
So query will hang, right? |
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
Current pr makes sure that operator will send data to all tunnels, even if there is no actually data to send. |
|
Another possible fix from @SeaRise
|
| block.clear(); | ||
| tracked_packet->addChunk(codec_stream->getString()); | ||
| codec_stream->clear(); | ||
| if (block) |
There was a problem hiding this comment.
This is added for debug, there is no need to add this. I will remove it.
| auto should_notify = false; | ||
| { | ||
| std::lock_guard lock(mu); | ||
| should_notify = status != MPMCQueueStatus::CANCELLED && !isFullWithoutLock(); | ||
| } | ||
| if (should_notify) | ||
| pipe_writer_cv.notifyOne(); |
There was a problem hiding this comment.
how about just pipe_writer_cv.notifyOne()?
| *dag_context_ptr); | ||
| for (const auto & block : blocks) | ||
| dag_writer->write(block); | ||
| dag_writer->doWrite(block); |
There was a problem hiding this comment.
| dag_writer->doWrite(block); | |
| dag_writer->write(block); |
seems useless change
| virtual void prepare(const Block &){}; | ||
| virtual void write(const Block & block) = 0; | ||
| // return true if write is actually write the data | ||
| virtual bool doWrite(const Block & block) = 0; |
There was a problem hiding this comment.
how about moving to protected?
| } | ||
|
|
||
| // return true if flush is actually flush data | ||
| virtual bool doFlush() = 0; |
| // 2. encode all blocks | ||
| for (const auto & block : source_blocks) | ||
| dag_writer->write(block); | ||
| dag_writer->doWrite(block); |
| // 2. encode all blocks | ||
| for (const auto & block : source_blocks) | ||
| dag_writer->write(block); | ||
| dag_writer->doWrite(block); |
| block.clear(); | ||
| tracked_packet->addChunk(codec_stream->getString()); | ||
| codec_stream->clear(); | ||
| if (block) |
There was a problem hiding this comment.
| if (block) | |
| if likely (block && block.rows() > 0) |
There was a problem hiding this comment.
No need to add these check because write() makes sure the block has data before it push the block into blocks
Signed-off-by: xufei <xufeixw@mail.ustc.edu.cn>
After some offline discussion, we decide to use this pr as a quick fix for the hang issue, and will refine the whole tunnel write process using the above idea. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: gengliqi, SeaRise The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What problem does this PR solve?
Issue Number: close #9413
Problem Summary:
What is changed and how it works?
The root casue of the hang issue introduced by #9072 is
ExchangeSenderSinkOpeventually write data toLooseBoundedMPMCQueue, althoughLooseBoundedMPMCQueueis named withLooseBounded, it actually has a upper boundMPPTunnel(which holds aLooseBoundedMPMCQueue), all theExchangeSenderSinkOpwill try to write data to the sameLooseBoundedMPMCQueueconcurrentlyLooseBoundedMPMCQueueis full),ExchangeSenderSinkOpwill register itself to the pipeline notify furture(thetunnelSender)LooseBoundedMPMCQueueread a message fromLooseBoundedMPMCQueueExchangeSenderSinkOpis notified in stage 4, it is not 100% sure that theExchangeSenderSinkOpwill write data toLooseBoundedMPMCQueuebecauseExchangeSenderSinkOponly callswriter->write(block);to write the data, and insidewriter->write(block)the data can be cached inwriterinstead of writting toLooseBoundedMPMCQueueblockis empty, it will callwriter->flush()to flush the cached data, and if there is no cached data, it will not write toLooseBoundedMPMCQueueMExchangeSenderSinkOp, and theLooseBoundedMPMCQueuehas a limited size ofN, whereM > N, and all theMExchangeSenderSinkOptries to write to a fullLooseBoundedMPMCQueueat the same time. Then all theMExchangeSenderSinkOpare registered to the pipeline notify future. As described in stage 4, the pipeline notify future only notify one task at a time when the consumer ofLooseBoundedMPMCQueueread a message fromLooseBoundedMPMCQueue, then at mostNExchangeSenderSinkOpwill be notified. If all the notifiedNExchangeSenderSinkOpdo not write data toLooseBoundedMPMCQueue, then theLooseBoundedMPMCQueuebecome empty queue, and there is stillM - NExchangeSenderSinkOpwaiting on the pipeline notify future. SinceLooseBoundedMPMCQueueis empty, all theM - NExchangeSenderSinkOphave no chance to be notified. Then the whole query hangs.There is 2 possible fix
LooseBoundedMPMCQueue, triger a notification if current queue is emptyExchangeSenderSinkOpis notified, theExchangeSenderSinkOpshould either write data toLooseBoundedMPMCQueue, or try to notify anotherExchangeSenderSinkOpThe first fix should be earier, but consider that
ExchangeReceiverwill also using the notify way after #9073, the first fix may not work in the furture, so this pr use the second fix.Check List
Tests
Side effects
Documentation
Release note