MCPcopy Create free account
hub / github.com/apache/arrow / CheckScannerBackpressure

Function CheckScannerBackpressure

cpp/src/arrow/dataset/scanner_test.cc:585–636  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

583 });
584
585void CheckScannerBackpressure(std::shared_ptr<MockDataset> dataset, ScanV2Options options,
586 int maxConcurrentFragments, int maxConcurrentBatches,
587 ::arrow::internal::ThreadPool* thread_pool) {
588 // Start scanning
589 acero::Declaration scan_decl = acero::Declaration("scan2", std::move(options));
590 Future<RecordBatchVector> batches_fut =
591 acero::DeclarationToBatchesAsync(std::move(scan_decl));
592
593 auto get_num_inspected = [&] {
594 int num_inspected = 0;
595 for (const auto& frag : dataset->fragments_) {
596 if (frag->has_inspected()) {
597 num_inspected++;
598 }
599 }
600 return num_inspected;
601 };
602 BusyWait(10, [&] {
603 return get_num_inspected() == static_cast<int>(maxConcurrentFragments);
604 });
605 SleepABit();
606 ASSERT_EQ(get_num_inspected(), static_cast<int>(maxConcurrentFragments));
607
608 int total_batches = 0;
609 for (const auto& frag : dataset->fragments_) {
610 total_batches += frag->fragment_scanner_->NumBatches();
611 frag->FinishInspection();
612 frag->FinishScanBegin();
613 }
614
615 int batches_scanned = 0;
616 while (batches_scanned < total_batches) {
617 MockScanTask* next_task_to_deliver = nullptr;
618 thread_pool->WaitForIdle();
619 int batches_started = 0;
620 for (const auto& frag : dataset->fragments_) {
621 for (int i = 0; i < frag->fragment_scanner_->NumBatches(); i++) {
622 if (frag->HasBatchStarted(i)) {
623 batches_started++;
624 if (next_task_to_deliver == nullptr && !frag->HasBatchDelivered(i)) {
625 next_task_to_deliver = &frag->fragment_scanner_->scan_tasks_[i];
626 }
627 }
628 }
629 }
630 ASSERT_LE(batches_started - batches_scanned, maxConcurrentBatches)
631 << " too many scan tasks were allowed to run";
632 ASSERT_NE(next_task_to_deliver, nullptr);
633 next_task_to_deliver->batch_future.MarkFinished(next_task_to_deliver->batch);
634 batches_scanned++;
635 }
636}
637
638TEST(TestNewScanner, Backpressure) {
639 constexpr int kNumFragments = 4;

Callers 1

TESTFunction · 0.85

Calls 12

BusyWaitFunction · 0.85
SleepABitFunction · 0.85
has_inspectedMethod · 0.80
FinishInspectionMethod · 0.80
FinishScanBeginMethod · 0.80
WaitForIdleMethod · 0.80
HasBatchStartedMethod · 0.80
HasBatchDeliveredMethod · 0.80
DeclarationClass · 0.50
NumBatchesMethod · 0.45
MarkFinishedMethod · 0.45

Tested by

no test coverage detected