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

Careful object writing..

From
Linus Torvalds <torvalds@osdl.org>
Date
May 3, 2005, 19:15 UTC
Message-ID
<Pine.LNX.4.58.0505031204030.26698@ppc970.osdl.org>

I just pushed out the commit that tries to finally actually write the sha1 objects the right way in a shared object directory environment.

I used to be lazy, and just do "O_CREAT | O_EXCL" on the final name, but that obviously is not very nice when it can result in other people seeing objects that haven't been fully finalized yet.

So now I do it "right", and create a temporary file in the "top" object directory, and then when it's all done, I do a "link()" to the final place and unlink the original.

I also change the permission to 0444 before it gets its final name.
Two notes:
 - because the objects all get created initially in .git/objects rather 
   than in the subdirectory they get moved to, you can't use symlinks 
   to other filesystems for the 256 object subdirectories. The object 
   directory has to be one filesystem (but it doesn't have to be the same 
   one as you actually keep your working ddirectories on, of course)
 - The upside of this is that filesystem block allocators should do the 
   right thing. Instead of spreading the objects out (because they are in 
   different directories), they should be created together.

Anyway, somebody should double-check the thing. It _should_ now work correctly over NFS etc too, and everything should be nice and atomic (and with any half-way decent filesystem, it also means that even if you have a system crash in the middle, you'll never see half-created objects).

NOTE NOTE NOTE! I have _not_ updated all the helper stuff that also write objects. So things like "git-http-pull" etc will still write objects directly into the object directory, and that can cause problems with shared usage. Same goes for "write_sha1_from_fd()" that rpull.c uses. I hope somebody will take a look at those issues..

Anyway, at least the really core operations should now really be "thread-safe" in a shared object directory environment.

		Linus
Next: Chris Wedgwood
Message 1 of 19 in “Careful object writing..”
  1. Linus TorvaldsMay 3, 2005
  2. Chris WedgwoodMay 3, 2005
  3. Linus TorvaldsMay 3, 2005
  4. Chris WedgwoodMay 3, 2005
  5. Linus TorvaldsMay 3, 2005
  6. Daniel BarkalowMay 3, 2005
  7. Jan HarkesMay 3, 2005
  8. Linus TorvaldsMay 3, 2005
  9. Jan HarkesMay 3, 2005
  10. Linus TorvaldsMay 3, 2005
  11. Linus TorvaldsMay 3, 2005
  12. H. Peter AnvinMay 3, 2005
  13. Alex RiesenMay 3, 2005
  14. Linus TorvaldsMay 3, 2005
  15. Alex RiesenMay 3, 2005
  16. Junio C HamanoMay 3, 2005
  17. Careful object pullingDaniel Barkalow, May 4, 2005
  18. Morten WelinderMay 4, 2005
  19. Daniel BarkalowMay 4, 2005

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.