pub(crate) fn unbilled_sample_buffers(
series: &Series,
billed: &HashSet<usize>,
) -> (Vec<usize>, usize)Expand description
The Arrow allocations series’ samples live in that billed does not hold yet, and the bytes
they hold.
sample_slice_bytes counts the rows a chunk holds, which is the figure of a caller that bills
the samples without the allocations they are slices of. That is exact only when the chunks of a
series are non-overlapping slices that add up to the buffers they point into. It is wrong in both
directions otherwise: a chunk holding one row of a large batch keeps the whole buffer resident
while its rows are eight bytes, and two chunks whose slices overlap hold the bytes between them
once while each is charged for them. What is resident is the allocation, and an allocation is one
however many chunks slice it, so it is counted once, by the first chunk to reference it –
exactly as unbilled_tables counts a histogram table.
Counting every chunk for the whole buffer it slices would need no identity at all, but it
over-estimates by the number of chunks: a series handed over as a thousand slices of one buffer
would be charged that buffer a thousand times, which refuses an input whose buffers do fit the
pool. The identity is therefore read, and read from Arrow’s own handle on the allocation
([Buffer::data_ptr]): every slice of one buffer reports the address of the allocation it points
into, whatever its offset inside it, and the address names that allocation for as long as it is
remembered – a chunk referencing a buffer keeps it alive, so no later allocation can be given
the same address. The bytes are the buffer’s capacity, which is the allocation and not the slice,
plus the one slot the identity takes in the set that remembers it. The caller counts the figure
as it stands and adds the identities to billed once the chunk is retained, which is what makes
the two halves agree.
Every array a chunk holds samples in contributes: the values of a float segment, the indices of a histogram one, both of a mixed one, and the validity bitmap beside each of them – a bitmap is an allocation of its own, and no figure that counts rows can see it. A buffer two segments or two fields of the one chunk reference is listed once.