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

Method ensureInputFits

bolt/exec/GroupingSet.cpp:954–1038  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

952 table_->decideHashMode(0, true);
953 }
954 return pool_.currentBytes() > maxBytes;
955}
956
957uint64_t GroupingSet::allocatedBytes() const {
958 if (table_) {
959 return table_->allocatedBytes();
960 }
961
962 return stringAllocator_.retainedSize() + rows_.allocatedBytes();
963}
964
965const HashLookup& GroupingSet::hashLookup() const {
966 return *lookup_;
967}
968
969void GroupingSet::ensureInputFits(const RowVectorPtr& input) {
970 // Spilling is considered if this is a partial(prefer) or a final or single
971 // aggregation and spillPath is set.
972 if ((isPartial_ && preferPartialSpill_ == false) || spillConfig_ == nullptr) {
973 return;
974 }
975
976 const auto numDistinct = table_->numDistinct();
977 if (numDistinct == 0) {
978 // Table is empty. Nothing to spill.
979 return;
980 }
981
982 auto* rows = table_->rows();
983 auto [freeRows, outOfLineFreeBytes] = rows->freeSpace();
984 const auto outOfLineBytes =
985 rows->stringAllocator().retainedSize() - outOfLineFreeBytes;
986 const auto outOfLineBytesPerRow = outOfLineBytes / numDistinct;
987 const int64_t flatBytes = input->usedSize();
988
989 // Test-only spill path.
990 if (spillConfig_->testSpillPct > 0 &&
991 (folly::hasher<uint64_t>()(++spillTestCounter_)) % 100 <=
992 spillConfig_->testSpillPct) {
993 spill();
994 return;
995 }
996
997 const auto currentUsage = pool_.currentBytes();
998 if (spillMemoryThreshold_ != 0 && currentUsage > spillMemoryThreshold_) {
999 spill();
1000 return;
1001 }
1002
1003 const auto minReservationBytes =
1004 currentUsage * spillConfig_->minSpillableReservationPct / 100;
1005 const auto availableReservationBytes = pool_.availableReservation();
1006 const auto tableIncrementBytes = table_->hashTableSizeIncrease(input->size());
1007 const auto incrementBytes =
1008 rows->sizeIncrement(input->size(), outOfLineBytes ? flatBytes * 2 : 0) +
1009 tableIncrementBytes;
1010
1011 // First to check if we have sufficient minimal memory reservation.

Callers

nothing calls this directly

Calls 15

succinctBytesFunction · 0.85
hashTableSizeIncreaseMethod · 0.80
sizeIncrementMethod · 0.80
numDistinctMethod · 0.45
rowsMethod · 0.45
freeSpaceMethod · 0.45
retainedSizeMethod · 0.45
stringAllocatorMethod · 0.45
usedSizeMethod · 0.45
currentBytesMethod · 0.45
availableReservationMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected