| 635 | } |
| 636 | |
| 637 | void SpillMerger::readFromSpillFileStream( |
| 638 | const std::weak_ptr<SpillMerger>& mergeHolder, |
| 639 | size_t streamIdx) { |
| 640 | TestValue::adjust( |
| 641 | "bytedance::bolt::exec::SpillMerger::readFromSpillFileStream", |
| 642 | static_cast<void*>(0)); |
| 643 | const auto merger = mergeHolder.lock(); |
| 644 | if (merger == nullptr) { |
| 645 | LOG(ERROR) << "SpillMerger is destroyed, abandon reading from batch stream"; |
| 646 | return; |
| 647 | } |
| 648 | try { |
| 649 | if (hasError()) { |
| 650 | finishSource(streamIdx); |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | RowVectorPtr vector; |
| 655 | if (!batchStreams_[streamIdx]->nextBatch(vector)) { |
| 656 | BOLT_CHECK_NULL(vector); |
| 657 | finishSource(streamIdx); |
| 658 | return; |
| 659 | } |
| 660 | |
| 661 | ContinueFuture future{ContinueFuture::makeEmpty()}; |
| 662 | const auto blockingReason = |
| 663 | sources_[streamIdx]->enqueue(std::move(vector), &future); |
| 664 | if (blockingReason == BlockingReason::kNotBlocked) { |
| 665 | BOLT_CHECK(!future.valid()); |
| 666 | readFromSpillFileStream(mergeHolder, streamIdx); |
| 667 | } else { |
| 668 | BOLT_CHECK(future.valid()); |
| 669 | std::move(future) |
| 670 | .via(executor_) |
| 671 | .thenValue([this, mergeHolder, streamIdx](auto&&) { |
| 672 | readFromSpillFileStream(mergeHolder, streamIdx); |
| 673 | }) |
| 674 | .thenError( |
| 675 | folly::tag_t<std::exception>{}, |
| 676 | [this, mergeHolder, streamIdx](const std::exception& e) { |
| 677 | const auto merger = mergeHolder.lock(); |
| 678 | if (merger != nullptr) { |
| 679 | LOG(ERROR) << "Stop the " << streamIdx |
| 680 | << " th source on error: " << e.what(); |
| 681 | setError(std::make_exception_ptr(e)); |
| 682 | finishSource(streamIdx); |
| 683 | } |
| 684 | }); |
| 685 | } |
| 686 | } catch (const std::exception& e) { |
| 687 | LOG(ERROR) << "The " << streamIdx |
| 688 | << " spill stream failed with error: " << e.what(); |
| 689 | setError(std::current_exception()); |
| 690 | finishSource(streamIdx); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | void SpillMerger::scheduleAsyncSpillFileStreamReads() { |