Skip to content

Commit 2517f59

Browse files
committed
refactor
1 parent 55e47c6 commit 2517f59

File tree

4 files changed

+19
-53
lines changed

4 files changed

+19
-53
lines changed

velox/exec/Merge.cpp

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -625,21 +625,6 @@ std::unique_ptr<SourceMerger> SpillMerger::createSourceMerger(
625625
type, std::move(streams), maxOutputBatchRows, maxOutputBatchBytes, pool);
626626
}
627627

628-
// static.
629-
void SpillMerger::asyncReadFromSpillFileStream(
630-
const std::weak_ptr<SpillMerger>& mergeHolder,
631-
size_t streamIdx) {
632-
TestValue::adjust(
633-
"facebook::velox::exec::SpillMerger::asyncReadFromSpillFileStream",
634-
static_cast<void*>(0));
635-
const auto merger = mergeHolder.lock();
636-
if (merger == nullptr) {
637-
LOG(ERROR) << "SpillMerger is destroyed, abandon reading from batch stream";
638-
return;
639-
}
640-
merger->readFromSpillFileStream(mergeHolder, streamIdx);
641-
}
642-
643628
void SpillMerger::readFromSpillFileStream(
644629
const std::weak_ptr<SpillMerger>& mergeHolder,
645630
size_t streamIdx) {
@@ -656,54 +641,45 @@ void SpillMerger::readFromSpillFileStream(
656641

657642
if (*error_.rlock() != nullptr) {
658643
ContinueFuture future{ContinueFuture::makeEmpty()};
659-
LOG(ERROR) << "MACDUAN " << streamIdx << " th source end, push null.";
644+
LOG(ERROR) << "Stop the " << streamIdx << " th source on error.";
660645
sources_[streamIdx]->enqueue(nullptr, &future);
661646
return;
662647
}
663648

664649
RowVectorPtr vector;
665650
ContinueFuture future{ContinueFuture::makeEmpty()};
666651
if (!batchStreams_[streamIdx]->nextBatch(vector)) {
667-
LOG(ERROR) << "MACDUAN " << streamIdx
668-
<< " th source reach th end, push null.";
669-
670652
VELOX_CHECK_NULL(vector);
671653
sources_[streamIdx]->enqueue(nullptr, &future);
672654
VELOX_CHECK(!future.valid());
673655
return;
674656
}
657+
675658
const auto blockingReason =
676659
sources_[streamIdx]->enqueue(std::move(vector), &future);
677-
// TODO: add async error handling.
678660
if (blockingReason == BlockingReason::kNotBlocked) {
679661
VELOX_CHECK(!future.valid());
680662
readFromSpillFileStream(mergeHolder, streamIdx);
681663
} else {
682664
VELOX_CHECK(future.valid());
683-
std::move(future).via(executor_).thenTry([this, mergeHolder, streamIdx](
684-
folly::Try<folly::Unit>&&
685-
t) {
686-
const auto merger = mergeHolder.lock();
687-
if (merger == nullptr) {
688-
LOG(ERROR)
689-
<< "SpillMerger is destroyed, abandon reading from batch stream";
690-
return;
691-
}
692-
if (t.hasException()) {
693-
LOG(ERROR) << "Stop the " << streamIdx
694-
<< "th batch stream producer on error: "
695-
<< t.exception().what();
696-
*error_.wlock() = std::make_exception_ptr(t.exception());
697-
ContinueFuture future{ContinueFuture::makeEmpty()};
698-
sources_[streamIdx]->enqueue(nullptr, &future);
699-
} else {
700-
readFromSpillFileStream(mergeHolder, streamIdx);
701-
}
702-
});
665+
std::move(future).via(executor_).thenTry(
666+
[this, mergeHolder, streamIdx](folly::Try<folly::Unit>&& t) {
667+
const auto merger = mergeHolder.lock();
668+
if (merger == nullptr) {
669+
return;
670+
}
671+
if (t.hasException()) {
672+
LOG(ERROR) << "Stop the " << streamIdx << " th source on error.";
673+
*error_.wlock() = std::make_exception_ptr(t.exception());
674+
ContinueFuture future{ContinueFuture::makeEmpty()};
675+
sources_[streamIdx]->enqueue(nullptr, &future);
676+
} else {
677+
readFromSpillFileStream(mergeHolder, streamIdx);
678+
}
679+
});
703680
}
704681
} catch (const std::exception& e) {
705-
LOG(ERROR) << "MACDUAN " << streamIdx << " th catch exception. "
706-
<< e.what();
682+
LOG(ERROR) << "The " << streamIdx << " th catch exception. " << e.what();
707683
*error_.wlock() = std::current_exception();
708684
readFromSpillFileStream(mergeHolder, streamIdx);
709685
}
@@ -713,11 +689,7 @@ void SpillMerger::scheduleAsyncSpillFileStreamReads() {
713689
VELOX_CHECK_EQ(batchStreams_.size(), sources_.size());
714690
for (auto i = 0; i < batchStreams_.size(); ++i) {
715691
executor_->add([&, streamIdx = i]() {
716-
try {
717-
readFromSpillFileStream(std::weak_ptr(shared_from_this()), streamIdx);
718-
} catch (...) {
719-
*error_.wlock() = std::current_exception();
720-
}
692+
readFromSpillFileStream(std::weak_ptr(shared_from_this()), streamIdx);
721693
});
722694
}
723695
}

velox/exec/Merge.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,6 @@ class SpillMerger : public std::enable_shared_from_this<SpillMerger> {
321321
uint64_t maxOutputBatchBytes,
322322
velox::memory::MemoryPool* pool);
323323

324-
void asyncReadFromSpillFileStream(
325-
const std::weak_ptr<SpillMerger>& mergeHolder,
326-
size_t streamIdx);
327-
328324
void readFromSpillFileStream(
329325
const std::weak_ptr<SpillMerger>& mergeHolder,
330326
size_t streamIdx);

velox/exec/MergeSource.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ class LocalMergeSource : public MergeSource {
124124

125125
if (data_.empty()) {
126126
if (atEnd_) {
127-
LOG(ERROR) << "Macduan atEnd";
128127
return BlockingReason::kNotBlocked;
129128
}
130129

velox/exec/tests/MergerTest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ TEST_F(MergerTest, spillMergerException) {
455455
"facebook::velox::exec::SpillMerger::readFromSpillFileStream",
456456
std::function<void(void*)>([&](void* /*unused*/) {
457457
if (cnt++ == 3) {
458-
// LOG(ERROR) << "Throw SpillMerger::readFromSpillFileStream fail";
459458
VELOX_FAIL("SpillMerger::readFromSpillFileStream fail");
460459
}
461460
}));

0 commit comments

Comments
 (0)