MCPcopy Create free account
hub / github.com/apache/impala / SpillPartition

Method SpillPartition

be/src/exec/grouping-aggregator.cc:941–976  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

939}
940
941Status GroupingAggregator::SpillPartition(bool more_aggregate_rows) {
942 int64_t max_freed_mem = 0;
943 int partition_idx = -1;
944
945 // Iterate over the partitions and pick the largest partition that is not spilled.
946 for (int i = 0; i < hash_partitions_.size(); ++i) {
947 if (hash_partitions_[i] == nullptr) continue;
948 if (hash_partitions_[i]->is_closed) continue;
949 if (hash_partitions_[i]->is_spilled()) continue;
950 // Pass 'true' because we need to keep the write block pinned. See Partition::Spill().
951 int64_t mem = hash_partitions_[i]->aggregated_row_stream->BytesPinned(true);
952 mem += hash_partitions_[i]->hash_tbl->ByteSize();
953 mem += hash_partitions_[i]->agg_fn_perm_pool->total_reserved_bytes();
954 DCHECK_GT(mem, 0); // At least the hash table buckets should occupy memory.
955 if (mem > max_freed_mem) {
956 max_freed_mem = mem;
957 partition_idx = i;
958 }
959 }
960 DCHECK_NE(partition_idx, -1) << "Should have been able to spill a partition to "
961 << "reclaim memory: "
962 << buffer_pool_client()->DebugString();
963 // Remove references to the destroyed hash table from 'hash_tbls_'.
964 // Additionally, we might be dealing with a rebuilt spilled partition, where all
965 // partitions point to a single in-memory partition. This also ensures that 'hash_tbls_'
966 // remains consistent in that case.
967 for (int i = 0; i < PARTITION_FANOUT; ++i) {
968 if (hash_partitions_[i] == hash_partitions_[partition_idx]) hash_tbls_[i] = nullptr;
969 }
970 Status status = hash_partitions_[partition_idx]->Spill(more_aggregate_rows);
971 // Try to save back the large write page reservation if it's used by a pinned partition.
972 if (status.ok() && large_write_page_reservation_.GetReservation() == 0) {
973 TrySaveLargeWritePageReservation();
974 }
975 return status;
976}
977
978Status GroupingAggregator::MoveHashPartitions(int64_t num_input_rows) {
979 DCHECK(!hash_partitions_.empty());

Callers

nothing calls this directly

Calls 9

BytesPinnedMethod · 0.80
total_reserved_bytesMethod · 0.80
sizeMethod · 0.45
is_spilledMethod · 0.45
ByteSizeMethod · 0.45
DebugStringMethod · 0.45
SpillMethod · 0.45
okMethod · 0.45
GetReservationMethod · 0.45

Tested by

no test coverage detected