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

[PATCH 0/3] compat/mingw: implement POSIX-style atomic renames

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 23, 2024, 15:04 UTC
Message-ID
<cover.1729695349.git.ps@pks.im>
Hi,

so after chatting with Johannes recently I decided to have another stab at the failures we've seen on Windows with the reftable backend. A quick refresher: reftables use a central "tables.lock" file that gets updated via renames such that the update itself is atomic. This causes issues on Windows when there are many concurrent readers/writers because Windows does not allow you to rename a file over another file that is held open by another process by default. This issue is surfaced by t0610, where we spawn a 100 concurrent git-update-ref(1) processes.

This patch series aims to fix the issue on Windows by implementing POSIX-style atomic renames. The first two patches refactor the code such that we use `FILE_SHARE_DELETE` to open files, which allows other processes to delete the file even while we have an open handle. This sharing mode is also important in the context of renames, which are treated like a deletion of the replaced file. The third patch then reimplements renames via `SetFileAttributesByHandle(FileRenameInfoEx)`, which has a flag `FILE_RENAME_FLAG_POSIX_SEMANTICS`. When set, Windows allows us to replace files during a rename which still have an open handle.

There's one catch: this is only supported in Windows 10 and newer. On one hand this means that we have to provide the required definitions ourselves, as we cannot bump the Windows SDK version. On the other hand we also have to support the case where older Windows versions now fail at runtime due to `FileRenameInfoEx` being unsupported. But overall this isn't too bad, I'd say. Johannes has also kindly tested the fallback logic for me on Windows 8.1.

With these changes t0610 now passes on my Windows 10 machine, but this may also have a positive impact on other parts of Git where we might have previously failed.

Thanks!
Patrick
Patrick Steinhardt (3):
  compat/mingw: share file handles created via `CreateFileW()`
  compat/mingw: allow deletion of most opened files
  compat/mingw: support POSIX semantics for atomic renames
 compat/mingw.c             | 146 +++++++++++++++++++++++++++++++++++--
 t/t0610-reftable-basics.sh |   8 +-
 2 files changed, 145 insertions(+), 9 deletions(-)
-- 
2.47.0.118.gfd3785337b.dirty
Next: Patrick Steinhardt
Message 1 of 44 in “compat/mingw: implement POSIX-style atomic renames”
  1. 0/3 compat/mingw: implement POSIX-style atomic renamesPatrick Steinhardt, Oct 23, 2024
  2. 1/3 compat/mingw: share file handles created via `CreateFileW()`Patrick Steinhardt, Oct 23, 2024
  3. Kristoffer HaugsbakkOct 23, 2024
  4. Taylor BlauOct 23, 2024
  5. Taylor BlauOct 23, 2024
  6. Taylor BlauOct 23, 2024
  7. Patrick SteinhardtOct 24, 2024
  8. Johannes SixtOct 27, 2024
  9. Taylor BlauOct 27, 2024
  10. 2/3 compat/mingw: allow deletion of most opened filesPatrick Steinhardt, Oct 23, 2024
  11. Kristoffer HaugsbakkOct 23, 2024
  12. Taylor BlauOct 23, 2024
  13. Patrick SteinhardtOct 24, 2024
  14. Taylor BlauOct 23, 2024
  15. 3/3 compat/mingw: support POSIX semantics for atomic renamesPatrick Steinhardt, Oct 23, 2024
  16. Kristoffer HaugsbakkOct 23, 2024
  17. Patrick SteinhardtOct 24, 2024
  18. Kristoffer HaugsbakkOct 24, 2024
  19. Patrick SteinhardtOct 24, 2024
  20. Taylor BlauOct 23, 2024
  21. Taylor BlauOct 23, 2024
  22. 0/3 compat/mingw: implement POSIX-style atomic renamesPatrick Steinhardt, Oct 24, 2024
  23. 1/3 compat/mingw: share file handles created via `CreateFileW()`Patrick Steinhardt, Oct 24, 2024
  24. 2/3 compat/mingw: allow deletion of most opened filesPatrick Steinhardt, Oct 24, 2024
  25. Johannes SixtOct 27, 2024
  26. Patrick SteinhardtOct 27, 2024
  27. Taylor BlauOct 27, 2024
  28. Taylor BlauOct 27, 2024
  29. 3/3 compat/mingw: support POSIX semantics for atomic renamesPatrick Steinhardt, Oct 24, 2024
  30. Johannes SixtOct 27, 2024
  31. Patrick SteinhardtOct 27, 2024
  32. Johannes SixtOct 27, 2024
  33. Patrick SteinhardtOct 27, 2024
  34. Johannes SixtOct 27, 2024
  35. Taylor BlauOct 27, 2024
  36. Taylor BlauOct 24, 2024
  37. Johannes SixtOct 27, 2024
  38. 0/3 compat/mingw: implement POSIX-style atomic renamesPatrick Steinhardt, Oct 27, 2024
  39. 1/3 compat/mingw: share file handles created via `CreateFileW()`Patrick Steinhardt, Oct 27, 2024
  40. 2/3 compat/mingw: allow deletion of most opened filesPatrick Steinhardt, Oct 27, 2024
  41. 3/3 compat/mingw: support POSIX semantics for atomic renamesPatrick Steinhardt, Oct 27, 2024
  42. Junio C HamanoNov 6, 2024
  43. Johannes SixtNov 6, 2024
  44. Junio C HamanoNov 6, 2024

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.