Commit d7fd093
Use per-batch retry block in R2C with lightweight OOM recovery (#14428)
Fixes #14368
### Description
PR #13842 wrapped each row in `RowToColumnarIterator.buildBatch` with
`withRetryNoSplit` + `withRestoreOnRetry`, which introduced significant
per-row overhead (~19x slower) from JNI calls, synchronized blocks, and
object allocations on every row — even in the common no-OOM path.
This PR replaces the per-row retry framework usage with a single
per-batch retry block and a lightweight catch-based OOM recovery:
**Design: per-batch retry block + inline OOM handling**
The conversion loop runs inside `RmmRapidsRetryIterator.withRetryBlock`,
which enters the RMM retry block once per batch (not per row). A per-row
`captureState()` / `restoreState()` on the column builders enables
rollback on OOM — these are lightweight offset snapshots with negligible
overhead.
On OOM, a single catch arm handles all cases:
| Scenario | Action |
|----------|--------|
| RetryOOM/SplitAndRetryOOM with rows already converted
(non-RequireSingleBatch) | Emit partial batch, save failed row as
`pendingRow` for next batch |
| RetryOOM with no rows yet (or RequireSingleBatch) |
`blockUntilMemoryFreed()` — wait for spill, then while-loop retries
naturally |
| SplitAndRetryOOM with no rows yet | Propagate — can't split a single
row |
This is an **optimistic strategy**: pay minimal overhead (one
`captureState` per row) in the common case, and only block/wait when
absolutely necessary.
**New retry framework utilities**
Two general-purpose methods are added to `RmmRapidsRetryIterator` for
incremental operations where partial progress is valuable (doesn't fit
the standard atomic-retry model of `withRetryNoSplit`):
- `withRetryBlock[T](fn: => T): T` — manages the retry block lifecycle
without automatic retry
- `blockUntilMemoryFreed()` — follows the standard protocol (exit retry
block → `blockThreadUntilReady` → re-enter) for use within
`withRetryBlock`
**Other changes**
- `ENABLE_R2C_RETRY` config default flipped from `false` to `true` —
retry is now on by default with negligible overhead. The config is
retained as an internal kill-switch to disable retry if needed.
- Removed `RetryableRowConverter` class — no longer needed without
per-row `withRetryNoSplit`
**Performance**
[Benchmark
script](#14368 (comment))
| Configuration | Median | vs no-retry |
|---------------|--------|-------------|
| No retry | 829 ms | baseline |
| Per-row retry (old) | 15,526 ms | **~19x slower** |
| Per-batch retry (this PR) | 876 ms | **~5% slower** |
### Checklists
- [x] This PR has added documentation for new or modified features or
behaviors.
- [x] This PR has added new tests or modified existing tests to cover
new code paths.
- `test simple GPU/CPU OOM retry` — OOM during conversion with
RequireSingleBatch
- `test CPU OOM retry preserves all rows for non-RequireSingleBatch` —
emit-early path
- `test first-row CPU OOM with TargetSize/RequireSingleBatch falls back
to retry` — blockUntilMemoryFreed path
- `test CPU SplitAndRetryOOM emit-early for non-RequireSingleBatch` —
SplitAndRetryOOM emit-early path
- `test simple OOM split and retry` — SplitAndRetryOOM propagation
- [x] Performance testing has been performed and its results are added
in the PR description. Or, an issue has been filed with a link in the PR
description.
---------
Signed-off-by: Haoyang Li <haoyangl@nvidia.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 5f7aa22 commit d7fd093
4 files changed
Lines changed: 208 additions & 172 deletions
File tree
- sql-plugin/src/main/scala/com/nvidia/spark/rapids
- tests/src/test/scala/com/nvidia/spark/rapids
Lines changed: 110 additions & 128 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | | - | |
| 21 | + | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
578 | 577 | | |
579 | 578 | | |
580 | 579 | | |
581 | | - | |
| 580 | + | |
582 | 581 | | |
583 | 582 | | |
584 | 583 | | |
| |||
592 | 591 | | |
593 | 592 | | |
594 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
595 | 597 | | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
600 | 606 | | |
601 | 607 | | |
602 | 608 | | |
| |||
606 | 612 | | |
607 | 613 | | |
608 | 614 | | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
626 | 619 | | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
652 | 653 | | |
653 | 654 | | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
654 | 678 | | |
655 | 679 | | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
656 | 715 | | |
657 | 716 | | |
658 | | - | |
| 717 | + | |
| 718 | + | |
659 | 719 | | |
660 | 720 | | |
661 | 721 | | |
| |||
693 | 753 | | |
694 | 754 | | |
695 | 755 | | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
763 | | - | |
764 | | - | |
765 | | - | |
766 | | - | |
767 | | - | |
768 | | - | |
769 | | - | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | | - | |
774 | 756 | | |
775 | 757 | | |
776 | 758 | | |
| |||
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
446 | 445 | | |
447 | 446 | | |
448 | | - | |
| 447 | + | |
449 | 448 | | |
450 | 449 | | |
451 | 450 | | |
| |||
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
191 | 229 | | |
192 | 230 | | |
193 | 231 | | |
| |||
0 commit comments