]> git.ipfire.org Git - thirdparty/git.git/commit
packfile: explain ordering of how we look up auxiliary pack files
authorPatrick Steinhardt <ps@pks.im>
Wed, 28 May 2025 12:24:10 +0000 (14:24 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 28 May 2025 14:56:29 +0000 (07:56 -0700)
commit320572c43d7bc5afbcb8e5faf83b6eccfe6f4e32
tree59f08e26a626f6831fe25d4adf8b9b7135be096a
parent8613c2bb6cd16ef530dc5dd74d3b818a1ccbf1c0
packfile: explain ordering of how we look up auxiliary pack files

When adding a packfile to an object database we perform four syscalls:

  - Three calls to access(3p) are done to check for auxiliary data
    structures.

  - One call to stat(3p) is done to check for the ".pack" itself.

One curious bit is that we perform the access(3p) calls before checking
for the packfile itself, but if the packfile doesn't exist we discard
all results. The access(3p) calls are thus essentially wasted, so one
may be triggered to reorder those calls so that we can short-circuit the
other syscalls in case the packfile does not exist.

The order in which we look up files is quite important though to help
avoid races:

  - When installing a packfile we move auxiliary data structures into
    place before we install the ".idx" file.

  - When deleting a packfile we first delete the ".idx" and ".pack"
    files before deleting auxiliary data structures.

As such, to avoid any races with concurrently created or deleted packs
we need to make sure that we _first_ read auxiliary data structures
before we read the corresponding ".idx" or ".pack" file. Otherwise it
may easily happen that we return a populated but misclassified pack.

Add a comment to `add_packed_git()` to make future readers aware of this
ordering requirement.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
packfile.c