Re: [PATCH v2 03/19] midx: teach `nth_midxed_pack_int_id()` about incremental MIDXs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 17, 2024 at 05:12:04PM -0400, Taylor Blau wrote:

> [^1]: As a reminder, this means that the object is identified among the
>   objects contained in all layers of the incremental MIDX chain, not any
>   particular layer. For example, consider MIDX chain with two individual
>   MIDXs, one with 4 objects and another with 3 objects. If the MIDX with
>   4 objects appears earlier in the chain, then asking for pack "6" would
>   return the second object in the MIDX with 3 objects.

I think this is "object 6" in the final sentence?

Otherwise, the explanation lays things out pretty well. Let's look at
the code.

> +static uint32_t midx_for_object(struct multi_pack_index **_m, uint32_t pos)
> +{
> +	struct multi_pack_index *m = *_m;
> +	while (m && pos < m->num_objects_in_base)
> +		m = m->base_midx;

OK, so given a global position, we walk backwards until we find the
correct midx...

> +	if (!m)
> +		BUG("NULL multi-pack-index for object position: %"PRIu32, pos);
> +
> +	if (pos >= m->num_objects + m->num_objects_in_base)
> +		die(_("invalid MIDX object position, MIDX is likely corrupt"));

...and we double check that the given base claims to have that position.
Seems obvious.

> +	*_m = m;
> +
> +	return pos - m->num_objects_in_base;

And then we adjust it into a per-midx position.

> @@ -334,8 +351,10 @@ off_t nth_midxed_offset(struct multi_pack_index *m, uint32_t pos)
>  
>  uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos)
>  {
> -	return get_be32(m->chunk_object_offsets +
> -			(off_t)pos * MIDX_CHUNK_OFFSET_WIDTH);
> +	pos = midx_for_object(&m, pos);
> +
> +	return m->num_packs_in_base + get_be32(m->chunk_object_offsets +
> +					       (off_t)pos * MIDX_CHUNK_OFFSET_WIDTH);
>  }

OK, so now this function translates a global position into a local one,
and then we get the pack id for the local midx/pos, and then turn it
back into a global pack id.

That all makes sense, but you definitely have to read carefully to make
sure which positions/ids are global within the chain and which are local
to a midx.

I wonder if the type system can help us annotate them, but I suspect it
becomes awkward. Just typedef-ing them to uint32_t means the compiler
won't warn us when we use one in the wrong spot. Sticking them in
structs would solve that, but then using them is painful. Let's keep
reading and see if it's even an issue in practice.

-Peff




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux