MCPcopy Create free account
hub / github.com/bytedance/bolt / reclaim

Method reclaim

bolt/exec/HashAggregation.cpp:739–797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

737}
738
739void HashAggregation::reclaim(
740 uint64_t targetBytes,
741 memory::MemoryReclaimer::Stats& stats) {
742 BOLT_CHECK(canReclaim());
743 BOLT_CHECK(!nonReclaimableSection_);
744
745 if (groupingSet_ == nullptr) {
746 return;
747 }
748
749 // for partial aggregation, if preferPartialSpill_ is false, do not spill
750 if (isPartialStep_ && !preferPartialSpill_) {
751 return;
752 }
753
754 updateEstimatedOutputRowSize();
755
756 if (noMoreInput_) {
757 if (groupingSet_->hasSpilled()) {
758 LOG(WARNING)
759 << "Can't reclaim from aggregation operator which has spilled and is under output processing, pool "
760 << pool()->name()
761 << ", memory usage: " << succinctBytes(pool()->currentBytes())
762 << ", reservation: " << succinctBytes(pool()->reservedBytes());
763 return;
764 }
765 if (isDistinct_) {
766 ++stats.numNonReclaimableAttempts;
767 LOG(WARNING)
768 << "Can't reclaim from distinct aggregation operator which is under output processing, pool "
769 << pool()->name()
770 << ", memory usage: " << succinctBytes(pool()->currentBytes())
771 << ", reservation: " << succinctBytes(pool()->reservedBytes());
772 // Since we have seen all the input, we can safely reset the hash table.
773 groupingSet_->resetTable();
774 // Release the minimum reserved memory.
775 pool()->release();
776 return;
777 }
778
779 // Spill all the rows starting from the next output row pointed by
780 // 'resultIterator_'.
781 groupingSet_->spill(resultIterator_);
782 // NOTE: we will only spill once during the output processing stage so
783 // record stats here.
784 recordSpillStats();
785 } else {
786 BOLT_CHECK(
787 !isDistinct_ || (input_ == nullptr && !newDistincts_),
788 "Unexpected input when spill distinct aggregation");
789 // TODO: support fine-grain disk spilling based on 'targetBytes' after
790 // having row container memory compaction support later.
791 groupingSet_->spill();
792 }
793 BOLT_CHECK_EQ(groupingSet_->numRows(), 0);
794 BOLT_CHECK_EQ(groupingSet_->numDistinct(), 0);
795 // Release the minimum reserved memory.
796 pool()->release();

Callers

nothing calls this directly

Calls 11

succinctBytesFunction · 0.85
resetTableMethod · 0.80
poolFunction · 0.50
hasSpilledMethod · 0.45
nameMethod · 0.45
currentBytesMethod · 0.45
reservedBytesMethod · 0.45
releaseMethod · 0.45
spillMethod · 0.45
numRowsMethod · 0.45
numDistinctMethod · 0.45

Tested by

no test coverage detected