1
0
mirror of https://github.com/git/git.git synced 2024-10-21 08:08:16 +02:00
git/Documentation/technical
Taylor Blau 95e8383bac midx.c: make changing the preferred pack safe
The previous patch demonstrates a bug where a MIDX's auxiliary object
order can become out of sync with a MIDX bitmap.

This is because of two confounding factors:

  - First, the object order is stored in a file which is named according
    to the multi-pack index's checksum, and the MIDX does not store the
    object order. This means that the object order can change without
    altering the checksum.

  - But the .rev file is moved into place with finalize_object_file(),
    which link(2)'s the file into place instead of renaming it. For us,
    that means that a modified .rev file will not be moved into place if
    MIDX's checksum was unchanged.

This fix is to force the MIDX's checksum to change when the preferred
pack changes but the set of packs contained in the MIDX does not. In
other words, when the object order changes, the MIDX's checksum needs to
change with it (regardless of whether the MIDX is tracking the same or
different packs).

This prevents a race whereby changing the object order (but not the
packs themselves) enables a reader to see the new .rev file with the old
MIDX, or similarly seeing the new bitmap with the old object order.

But why can't we just stop hardlinking the .rev into place instead
adding additional data to the MIDX? Suppose that's what we did. Then
when we go to generate the new bitmap, we'll load the old MIDX bitmap,
along with the MIDX that it references. That's fine, since the new MIDX
isn't moved into place until after the new bitmap is generated. But the
new object order *has* been moved into place. So we'll read the old
bitmaps in the new order when generating the new bitmap file, meaning
that without this secondary change, bitmap generation itself would
become a victim of the race described here.

This can all be prevented by forcing the MIDX's checksum to change when
the object order does. By embedding the entire object order into the
MIDX, we do just that. That is, the MIDX's checksum will change in
response to any perturbation of the underlying object order. In t5326,
this will cause the MIDX's checksum to update (even without changing the
set of packs in the MIDX), preventing the stale read problem.

Note that this makes it safe to continue to link(2) the MIDX .rev file
into place, since it is now impossible to have a .rev file that is
out-of-sync with the MIDX whose checksum it references. (But we will do
away with MIDX .rev files later in this series anyway, so this is
somewhat of a moot point).

In theory, it is possible to store a "fingerprint" of the full object
order here, so long as that fingerprint changes at least as often as the
full object order does. Some possibilities here include storing the
identity of the preferred pack, along with the mtimes of the
non-preferred packs in a consistent order. But storing a limited part of
the information makes it difficult to reason about whether or not there
are gaps between the two that would cause us to get bitten by this bug
again.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-27 12:07:52 -08:00
..
.gitignore
api-error-handling.txt
api-index-skel.txt
api-index.sh
api-merge.txt
api-parse-options.txt
api-simple-ipc.txt
api-trace2.txt trace2: increment event format version 2021-11-11 15:01:04 -08:00
bitmap-format.txt
bundle-format.txt
chunk-format.txt
commit-graph-format.txt
commit-graph.txt
directory-rename-detection.txt
hash-function-transition.txt
http-protocol.txt
index-format.txt
long-running-process-protocol.txt
multi-pack-index.txt midx.c: make changing the preferred pack safe 2022-01-27 12:07:52 -08:00
pack-format.txt midx.c: make changing the preferred pack safe 2022-01-27 12:07:52 -08:00
pack-heuristics.txt
pack-protocol.txt
packfile-uri.txt
parallel-checkout.txt
partial-clone.txt
protocol-capabilities.txt
protocol-common.txt
protocol-v2.txt Merge branch 'cw/protocol-v2-doc-fix' 2021-12-10 14:35:00 -08:00
racy-git.txt
reftable.txt
remembering-renames.txt
repository-version.txt
rerere.txt update documentation for new zdiff3 conflictStyle 2021-12-01 14:45:59 -08:00
send-pack-pipeline.txt
shallow.txt
signature-format.txt
sparse-index.txt
trivial-merge.txt