git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/2] Retry attempts to acquire the packed-refs lock

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
May 1, 2015, 14:52 UTC
Message-ID
<1430491977-25817-1-git-send-email-mhagger@alum.mit.edu>

At GitHub we were seeing occasional lock contention over packed-refs. It wasn't very common, but when you have as much git traffic as we have, anything that *can* happen *will* happen.

The problem is that Git only tries to acquire locks a single time. If that attempt fails, the whole process fails. So, for example, if two processes are trying to delete two different references, one of them can fail due to inability to acquire the packed-refs lock, even though it could have succeeded if it had just waited a moment.

This patch series adds a new function, hold_lock_file_for_update_timeout(), which retries the lock acquisition for a specified length of time. The retries necessarily have to use polling, which it does using a quadratic backoff with a random component. It might be a bit overengineered for this single purpose, but I wanted it to be usable in other contexts without second thoughts.

This patch series also changes lock_packed_refs() to call the new function with a timeout of 1 second (by default; the timeout is configurable) and adds some tests that the retry and timeout are working.

It might be that there are other call sites that would benefit from retrying lock acquisition (the index file?), but this patch series only applies the new functionality to packed-refs.lock.

We have a patch similar to this one running on our servers at GitHub, with no problems observed so far.

This series applies to master. It is also available from my GitHub repository:

    https://github.com/mhagger/git branch lockfile-retry
Michael Haggerty (2):
  lockfile: allow file locking to be retried with a timeout
  lock_packed_refs(): allow retries when acquiring the packed-refs lock
 Documentation/config.txt |  6 ++++
 lockfile.c               | 79 ++++++++++++++++++++++++++++++++++++++++++++++--
 lockfile.h               | 16 ++++++++--
 refs.c                   | 12 +++++++-
 t/t3210-pack-refs.sh     | 17 +++++++++++
 5 files changed, 125 insertions(+), 5 deletions(-)
-- 
2.1.4
Next: Michael Haggerty
Message 1 of 18 in “Retry attempts to acquire the packed-refs lock”
  1. 0/2 Retry attempts to acquire the packed-refs lockMichael Haggerty, May 1, 2015
  2. 1/2 lockfile: allow file locking to be retried with a timeoutMichael Haggerty, May 1, 2015
  3. Junio C HamanoMay 11, 2015
  4. 2/2 lock_packed_refs(): allow retries when acquiring the packed-refs lockMichael Haggerty, May 1, 2015
  5. Johannes SixtMay 1, 2015
  6. Michael HaggertyMay 2, 2015
  7. Johannes SixtMay 2, 2015
  8. Michael HaggertyMay 11, 2015
  9. Stefan BellerMay 1, 2015
  10. Jeff KingMay 1, 2015
  11. Michael HaggertyMay 2, 2015
  12. Stefan BellerMay 4, 2015
  13. Jeff KingMay 5, 2015
  14. Michael HaggertyMay 11, 2015
  15. Jeff KingMay 11, 2015
  16. Stefan BellerMay 11, 2015
  17. Stefan BellerMay 11, 2015
  18. Junio C HamanoMay 3, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.