Derrick Stolee [off-list ref] writes:
My first reaction is to not write into .git/objects/ directly, but
instead make a .git/objects/tmp/ directory and write within that
directory. The idea is to prevent leaving stale files in the
.git/objects/ directory if the process terminates strangely (say,
a power outage or segfault).
Even if we know the name of the object we are writing beforehand, I
do not think it is a good idea to open-write-close the final object
file. The approach we already use everywhere is to write into a
tmpfile/lockfile and rename it to the final name
object-file.c::write_loose_object() uses create_tmpfile() to prepare
a temporary file whose name begins with "tmp_obj_", so that "gc" can
recognize stale ones and remove them.
If this was an interesting idea to pursue, it does leave a question:
should we clean up the tmp/ directory when it is empty? That would
require adding a check in finalize_object_file() that is probably
best left unchecked (the lstat() would add a cost per loose object
write that is probably too costly). I would rather leave an empty
tmp/ directory than add that cost per loose object write.
I am not sure why we want a new tmp/ directory.
On 11/29/2021 3:44 PM, Junio C Hamano wrote:
Derrick Stolee [off-list ref] writes:
quoted
My first reaction is to not write into .git/objects/ directly, but
instead make a .git/objects/tmp/ directory and write within that
directory. The idea is to prevent leaving stale files in the
.git/objects/ directory if the process terminates strangely (say,
a power outage or segfault).
Even if we know the name of the object we are writing beforehand, I
do not think it is a good idea to open-write-close the final object
file. The approach we already use everywhere is to write into a
tmpfile/lockfile and rename it to the final name
object-file.c::write_loose_object() uses create_tmpfile() to prepare
a temporary file whose name begins with "tmp_obj_", so that "gc" can
recognize stale ones and remove them.
The only difference is that the tmp_obj_* file would go into the
loose object directory corresponding to the first two hex characters
of the OID, but that no longer happens now.
quoted
If this was an interesting idea to pursue, it does leave a question:
should we clean up the tmp/ directory when it is empty? That would
require adding a check in finalize_object_file() that is probably
best left unchecked (the lstat() would add a cost per loose object
write that is probably too costly). I would rather leave an empty
tmp/ directory than add that cost per loose object write.
I am not sure why we want a new tmp/ directory.
I'm just thinking of a case where this fails repeatedly I would
rather have those failed tmp_obj_* files isolated in their own
directory. It's an extremely minor point, so I'm fine to drop
the recommendation.
Thanks,
-Stolee
On Tue, Nov 30, 2021 at 6:18 AM Derrick Stolee [off-list ref] wrote:
On 11/29/2021 3:44 PM, Junio C Hamano wrote:
quoted
Derrick Stolee [off-list ref] writes:
quoted
My first reaction is to not write into .git/objects/ directly, but
instead make a .git/objects/tmp/ directory and write within that
directory. The idea is to prevent leaving stale files in the
.git/objects/ directory if the process terminates strangely (say,
a power outage or segfault).
Even if we know the name of the object we are writing beforehand, I
do not think it is a good idea to open-write-close the final object
file. The approach we already use everywhere is to write into a
tmpfile/lockfile and rename it to the final name
object-file.c::write_loose_object() uses create_tmpfile() to prepare
a temporary file whose name begins with "tmp_obj_", so that "gc" can
recognize stale ones and remove them.
The only difference is that the tmp_obj_* file would go into the
loose object directory corresponding to the first two hex characters
of the OID, but that no longer happens now.
At the beginning of this patch, I did save the temporary object in a
two hex characters directory of "null_oid", but this is also a very
strange behavior. "Gc" will indeed clean up these tmp_obj_* files, no
matter if they are in .git/objects/ or .git/objects/xx.
Thanks,
-Han Xin