Minimal patches to let reftable pass the CI builds
cover Minimal patches to let reftable pass the CI builds
These patches fix the PR build failures at
https://github.com/git/git/pull/847/checks?check_run_id=1460683728, and are designed to be squashed into the 16 patches of the libreftable v3 patch series as submitted at
https://lore.kernel.org/git/[email protected]/
.
A smaller form of the first patch was offered on the mailing list on May 4th:
https://lore.kernel.org/git/ff60fde10919b6b8c54ecb8f38b710fac37624e3.1588599086.git.gitgitgadget@gmail.com/
. The next three patches were presented to the mailing list on October 2nd:
https://lore.kernel.org/git/[email protected]/
, and
https://lore.kernel.org/git/[email protected]/
. Some of the patches required slight adjustments to accommodate for context changes.
Going forward, I would like to avoid the impression that it is the responsibility of the Git for Windows maintainer to keep the CI build passing on Windows. I am happy to assist in case it is unclear how to fix certain issues. I am not happy having to implement and test those fixes myself. How can we ensure this doesn't happen in the future?
Johannes Schindelin (6):
fixup! reftable: rest of library
fixup! reftable: utility functions
fixup! reftable: rest of library
fixup! reftable: rest of library
fixup! reftable: rest of library
fixup! reftable: rest of library
contrib/buildsystems/CMakeLists.txt | 14 +++++++-- reftable/dump.c | 36 ++++++++++------------- reftable/stack.c | 37 ++++++++++++++++++------ reftable/stack_test.c | 44 ++++++++++++++++++----------- 4 files changed, 82 insertions(+), 49 deletions(-)
base-commit: 6229da992e43f4a2d6f4ccaccf2dbbdf11bd5a4a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-801%2Fdscho%2Freftable-on-windows-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-801/dscho/reftable-on-windows-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/801
Signature · 1 line
gitgitgadget
PATCH 1/6 fixup! reftable: rest of library
From: Johannes Schindelin <[email protected]>
Close the file descriptors to obsolete files before trying to delete or rename them. This is actually required on Windows.
Note: this patch is just a band-aid to get the tests pass on Windows. The fact that it is needed raises concerns about the overall resource
handling: are file descriptors closed properly whenever appropriate, or are they closed much later (which can lead to rename() problems on Windows, and risks running into ulimits)?
Also, a reftable_stack_destroy() call had to be moved in test_reftable_stack_uptodate() to avoid the prompt complaining that a .ref file could not be deleted on Windows. This raises the question whether the code does the right thing when two concurrent processes want to access the reftable, and one wants to compact it. At the moment, it does not appear to fail gracefully.
--- reftable/stack.c | 37 ++++++++++++++++++++++++++++--------- reftable/stack_test.c | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-)
reftable/stack.c +28 -9
@@ -212,7 +212,6 @@ static int reftable_stack_reload_once(struct reftable_stack *st, char **names, goto done; new_tables =NULL ; - st->readers_len = new_readers_len;if (st->merged !=NULL ) {merged_table_release (st->merged);reftable_merged_table_free (st->merged);
@@ -220,6 +219,7 @@ static int reftable_stack_reload_once(struct reftable_stack *st, char **names,if (st->readers !=NULL ) {reftable_free (st->readers); } + st->readers_len = new_readers_len; st->readers = new_readers; new_readers =NULL ; new_readers_len =0 ;
@@ -939,14 +939,6 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,strbuf_addstr (&new_table_path,"/" );strbuf_addbuf (&new_table_path, &new_table_name); -if (!is_empty_table) { - err =rename (temp_tab_file_name.buf, new_table_path.buf); -if (err <0 ) { - err =REFTABLE_IO_ERROR ; - goto done; - } - } -for (i =0 ; i < first; i++) {strbuf_addstr (&ref_list_contents, st->readers[i]->name);strbuf_addstr (&ref_list_contents,"\n" );
@@ -960,6 +952,32 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,strbuf_addstr (&ref_list_contents,"\n" ); } +/* +* Now release the merged tables and readers +*/ +if (st->merged !=NULL ) { +reftable_merged_table_free (st->merged); + st->merged =NULL ; + } + +if (st->readers !=NULL ) { +int i =0 ; +for (i =0 ; i < st->readers_len; i++) { +reader_close (st->readers[i]); +reftable_reader_free (st->readers[i]); + } + st->readers_len =0 ; +FREE_AND_NULL (st->readers); + } + +if (!is_empty_table) { + err =rename (temp_tab_file_name.buf, new_table_path.buf); +if (err <0 ) { + err =REFTABLE_IO_ERROR ; + goto done; + } + } + err =write (lock_file_fd, ref_list_contents.buf, ref_list_contents.len);if (err <0 ) { err =REFTABLE_IO_ERROR ;
@@ -1242,6 +1260,7 @@ static int stack_check_addition(struct reftable_stack *st,free (refs);reftable_iterator_destroy (&it); +reader_close (rd);reftable_reader_free (rd);return err; }
reftable/stack_test.c +1 -1
@@ -159,12 +159,12 @@ static void test_reftable_stack_uptodate(void) err =reftable_stack_add (st2, &write_test_ref, &ref2);EXPECT (err ==REFTABLE_LOCK_ERROR ); +reftable_stack_destroy (st1); err =reftable_stack_reload (st2);EXPECT_ERR (err); err =reftable_stack_add (st2, &write_test_ref, &ref2);EXPECT_ERR (err); -reftable_stack_destroy (st1);reftable_stack_destroy (st2);clear_dir (dir); }
Signature · 1 line
gitgitgadget
PATCH 6/6 fixup! reftable: rest of library
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
The stack_test hard-codes /tmp/. That is a particular problem on Windows where the temp directory is never at that location.
Let's not do that, but instead use TMPDIR as we do in similar scenarios in the rest of Git's source code.
--- reftable/stack_test.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-)
reftable/stack_test.c +24 -14
@@ -28,9 +28,19 @@ static void clear_dir(const char *dirname)strbuf_release (&path); } +static char *get_tmp_template (const char *prefix) +{ +static struct strbuf path =STRBUF_INIT ; +const char *tmp =getenv ("TMPDIR" ); + +strbuf_reset (&path); +strbuf_addf (&path,"%s/%s.XXXXXX" , tmp ? tmp :"/tmp" , prefix); +return path.buf; +} +static void test_read_file (void ) { -char fn[256 ] ="/tmp/stack.test_read_file.XXXXXX" ; +char *fn =get_tmp_template ("stack.test_read_file" );int fd =mkstemp (fn);char out[1024 ] ="line1\n\nline2\nline3" ;int n, err;
@@ -99,7 +109,7 @@ static int write_test_log(struct reftable_writer *wr, void *arg)static void test_reftable_stack_add_one (void ) { -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ;int err;
@@ -132,7 +142,7 @@ static void test_reftable_stack_uptodate(void)struct reftable_write_options cfg = {0 };struct reftable_stack *st1 =NULL ;struct reftable_stack *st2 =NULL ; -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );int err;struct reftable_ref_record ref1 = { .refname ="HEAD" ,
@@ -171,7 +181,7 @@ static void test_reftable_stack_uptodate(void)static void test_reftable_stack_transaction_api (void ) { -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ;int err;
@@ -216,7 +226,7 @@ static void test_reftable_stack_validate_refname(void)struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ;int err; -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );int i;struct reftable_ref_record ref = { .refname ="a/b" ,
@@ -254,7 +264,7 @@ static int write_error(struct reftable_writer *wr, void *arg)static void test_reftable_stack_update_index_check (void ) { -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ;int err;
@@ -284,7 +294,7 @@ static void test_reftable_stack_update_index_check(void)static void test_reftable_stack_lock_failure (void ) { -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ;int err, i;
@@ -309,7 +319,7 @@ static void test_reftable_stack_add(void) .exact_log_message = 1, };struct reftable_stack *st =NULL ; -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );struct reftable_ref_record refs[2 ] = { {NULL } };struct reftable_log_record logs[2 ] = { {NULL } };int N =ARRAY_SIZE (refs);
@@ -385,7 +395,7 @@ static void test_reftable_stack_log_normalize(void) 0, };struct reftable_stack *st =NULL ; -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );uint8_t h1[SHA1_SIZE ] = {0x01 }, h2[SHA1_SIZE ] = {0x02 };
@@ -436,7 +446,7 @@ static void test_reftable_stack_log_normalize(void)static void test_reftable_stack_tombstone (void ) {int i =0 ; -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ;int err;
@@ -511,7 +521,7 @@ static void test_reftable_stack_tombstone(void)static void test_reftable_stack_hash_id (void ) { -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ;int err;
@@ -621,7 +631,7 @@ static void test_suggest_compaction_segment_nothing(void)static void test_reflog_expire (void ) { -char dir[256 ] ="/tmp/stack.test_reflog_expire.XXXXXX" ; +char *dir =get_tmp_template ("stack.test_reflog_expire" );struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ;struct reftable_log_record logs[20 ] = { {NULL } };
@@ -701,7 +711,7 @@ static void test_empty_add(void)struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ;int err; -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );struct reftable_stack *st2 =NULL ;EXPECT (mkdtemp (dir));
@@ -723,7 +733,7 @@ static void test_reftable_stack_auto_compaction(void) {struct reftable_write_options cfg = {0 };struct reftable_stack *st =NULL ; -char dir[256 ] ="/tmp/stack_test.XXXXXX" ; +char *dir =get_tmp_template ("stack_test" );int err, i;int N =100 ;EXPECT (mkdtemp (dir));
Signature · 1 line
gitgitgadget
PATCH 2/6 fixup! reftable: utility functions
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
Let's not forget our CMake configuration.
--- contrib/buildsystems/CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
contrib/buildsystems/CMakeLists.txt +12 -2
@@ -591,6 +591,12 @@ parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS") list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") add_library(xdiff STATIC ${libxdiff_SOURCES}) +#reftable +parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS") + +list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") +add_library(reftable STATIC ${reftable_SOURCES}) + if(WIN32) if(NOT MSVC)#use windres when compiling with gcc and clang add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
@@ -613,7 +619,7 @@ endif() #link all required libraries to common-main add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c) -target_link_libraries(common-main libgit xdiff ${ZLIB_LIBRARIES}) +target_link_libraries(common-main libgit xdiff reftable ${ZLIB_LIBRARIES}) if(Intl_FOUND) target_link_libraries(common-main ${Intl_LIBRARIES}) endif()
@@ -848,11 +854,15 @@ if(BUILD_TESTING) add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c) target_link_libraries(test-fake-ssh common-main) +#reftable-tests +parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS") +list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") + #test-tool parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS") list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/") -add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES}) +add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES} ${test-reftable_SOURCES}) target_link_libraries(test-tool common-main) set_target_properties(test-fake-ssh test-tool
Signature · 1 line
gitgitgadget
PATCH 4/6 fixup! reftable: rest of library
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
Avoid using getopt(): it might be POSIX, but Git's audience is much larger than POSIX. MSVC, for example, does not support getopt().
Without this patch, the vs-build job of our CI/PR builds would simply fail completely.
--- reftable/dump.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
reftable/dump.c +13 -19
@@ -167,40 +167,34 @@ static void print_help(void)int reftable_dump_main (int argc,char *const *argv) {int err =0 ; -int opt;int opt_dump_table =0 ;int opt_dump_stack =0 ;int opt_compact =0 ; -const char *arg =NULL ; -while ((opt =getopt (argc, argv,"2chts" )) !=-1 ) { -switch (opt) { -case '2' : - hash_id =0x73323536 ; +const char *arg =NULL , *argv0 = argv[0 ]; + +for (; argc >1 ; argv++, argc--) +if (*argv[1 ] !='-' )break ; -case 't' : +else if (!strcmp ("-2" , argv[1 ])) + hash_id =0x73323536 ; +else if (!strcmp ("-t" , argv[1 ])) opt_dump_table =1 ; -break ; -case 's' : +else if (!strcmp ("-s" , argv[1 ])) opt_dump_stack =1 ; -break ; -case 'c' : +else if (!strcmp ("-c" , argv[1 ])) opt_compact =1 ; -break ; -case '?' : -case 'h' : +else if (!strcmp ("-?" , argv[1 ]) || !strcmp ("-h" , argv[1 ])) {print_help ();return 2 ; -break ; } - } -if (argv[optind] ==NULL ) { +if (argc !=2 ) {fprintf (stderr,"need argument\n" );print_help ();return 2 ; } - arg = argv[optind]; + arg = argv[1 ];if (opt_dump_table) { err =dump_table (arg);
@@ -211,7 +205,7 @@ int reftable_dump_main(int argc, char *const *argv) }if (err <0 ) { -fprintf (stderr,"%s: %s: %s\n" , argv[0 ], arg, +fprintf (stderr,"%s: %s: %s\n" , argv0, arg,reftable_error_str (err));return 1 ; }
Signature · 1 line
gitgitgadget
PATCH 3/6 fixup! reftable: rest of library
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
0-sized arrays are actually not portable.
--- reftable/stack_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
reftable/stack_test.c +2 -2
@@ -579,11 +579,11 @@ static void test_sizes_to_segments(void)static void test_sizes_to_segments_empty (void ) { -uint64_t sizes[0 ]; +uint64_t sizes[1 ];int seglen =0 ;struct segment *segs = -sizes_to_segments (&seglen, sizes,ARRAY_SIZE (sizes)); +sizes_to_segments (&seglen, sizes,0 );EXPECT (seglen ==0 );reftable_free (segs); }
Signature · 1 line
gitgitgadget
PATCH 5/6 fixup! reftable: rest of library
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
Yet another instance of = {} initialization.
--- reftable/dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
reftable/dump.c +2 -2
@@ -82,7 +82,7 @@ static int dump_table(const char *tablename)static int compact_stack (const char *stackdir) {struct reftable_stack *stack =NULL ; -struct reftable_write_options cfg = {}; +struct reftable_write_options cfg = {0 };int err =reftable_new_stack (&stack, stackdir, cfg);if (err <0 )
@@ -101,7 +101,7 @@ static int compact_stack(const char *stackdir)static int dump_stack (const char *stackdir) {struct reftable_stack *stack =NULL ; -struct reftable_write_options cfg = {}; +struct reftable_write_options cfg = {0 };struct reftable_iterator it = {NULL };struct reftable_ref_record ref = {NULL };struct reftable_log_record log = {NULL };
Signature · 1 line
gitgitgadget
Quoted 18 lines · Johannes Schindelin via GitGitGadget
These patches fix the PR build failures at
https://github.com/git/git/pull/847/checks?check_run_id=1460683728, and are designed to be squashed into the 16 patches of the libreftable v3 patch series as submitted at
https://lore.kernel.org/git/[email protected]/
.A smaller form of the first patch was offered on the mailing list on May 4th:
https://lore.kernel.org/git/ff60fde10919b6b8c54ecb8f38b710fac37624e3.1588599086.git.gitgitgadget@gmail.com/
. The next three patches were presented to the mailing list on October 2nd:
https://lore.kernel.org/git/[email protected]/
, and
https://lore.kernel.org/git/[email protected]/
. Some of the patches required slight adjustments to accommodate for context changes.
Quoted 5 lines
Going forward, I would like to avoid the impression that it is the responsibility of the Git for Windows maintainer to keep the CI build passing on Windows. I am happy to assist in case it is unclear how to fix certain issues. I am not happy having to implement and test those fixes myself. How can we ensure this doesn't happen in the future?
Thanks for the build system fix. I think it's OK to leave it to me to solve the logic problems in the C code that you found.
Would you mind if I massaged these contributions directly back into github.com/google/reftable? Google has a corporate CLA from Microsoft, it's OK to accept this from you. For better or worse, this is still where I'm developing reftable, until it has landed in git-core.
Signature · 11 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Re: [PATCH 3/6] fixup! reftable: rest of library
In reply to Johannes Schindelin via GitGitGadgetQuoted 3 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
0-sized arrays are actually not portable.
Definitely.
reftable/stack_test.c static void test_sizes_to_segments(void) · line 588
Quoted 11 lines
static void
test_sizes_to_segments_empty(void)
{reftable/stack_test.c +2
-2-uint64_t sizes[0 ]; +uint64_t sizes[1 ];int seglen =0 ;struct segment *segs = -sizes_to_segments (&seglen, sizes,ARRAY_SIZE (sizes)); +sizes_to_segments (&seglen, sizes,0 );EXPECT (seglen ==0 );reftable_free (segs);
I think passing:
sizes_to_segments(&seglen, NULL, 0);
may make the code more obvious. Unlike system functions like memcpy(), we can be assured of whether our functions avoid looking at a zero-length array (and size_to_segments does follow that rule).
This function, of course, is nonsense that real code would not do, and is just unit-testing sizes_to_segments. I'm not wild in general about having a parallel suite of C tests that does not interact with our usual tests, but it may be the least bad way to benefit from the unit-test coverage that reftable ships with. As a rule, I'd much rather see a tool exposing functionality to the command-line, which can then be driven independently. I recognize that can end up complicated, though.
-Peff
Re: [PATCH 6/6] fixup! reftable: rest of library
In reply to Johannes Schindelin via GitGitGadgetQuoted 7 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
The
stack_testhard-codes/tmp/. That is a particular problem on Windows where the temp directory is never at that location.Let's not do that, but instead use
TMPDIRas we do in similar scenarios in the rest of Git's source code.
Yeah, I noticed this, as well. This seems like a good band-aid, but it would probably be nice if the test tool was able to write into a specified directory (or even just the current directory). I don't see it being invoked anywhere, but presumably if we were to add support to our test suite, we'd have a script which invokes it within a scratch directory.
-Peff
Re: [PATCH 3/6] fixup! reftable: rest of library
In reply to Jeff KingQuoted 23 lines · Jeff King
Quoted 3 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
0-sized arrays are actually not portable.
Definitely.
reftable/stack_test.c static void test_sizes_to_segments(void) · line 588
Quoted 11 lines
static void
test_sizes_to_segments_empty(void)
{reftable/stack_test.c +2
-2-uint64_t sizes[0 ]; +uint64_t sizes[1 ];int seglen =0 ;struct segment *segs = -sizes_to_segments (&seglen, sizes,ARRAY_SIZE (sizes)); +sizes_to_segments (&seglen, sizes,0 );EXPECT (seglen ==0 );reftable_free (segs);I think passing:
Quoted 7 lines
sizes_to_segments(&seglen, NULL, 0);may make the code more obvious. Unlike system functions like
memcpy(), we can be assured of whether our functions avoid looking at a zero-length array (andsize_to_segmentsdoes follow that rule).This function, of course, is nonsense that real code would not do, and
This test was added because 'real' code did this. In particular, if you initialize a stack of reftables, the stack has zero elements. The test was for the following bugfix
https://github.com/google/reftable/commit/b2e42ecb54e413e494c1fcc13c21e24422645007
Changing the array size to 1 here also prevents Valgrind to mark a regression as a OOB write.
Signature · 7 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Re: [PATCH 3/6] fixup! reftable: rest of library
Quoted 10 lines · Han-Wen Nienhuys
Quoted 9 lines
I think passing:
sizes_to_segments(&seglen, NULL, 0);may make the code more obvious. Unlike system functions like
memcpy(), we can be assured of whether our functions avoid looking at a zero-length array (andsize_to_segmentsdoes follow that rule).This function, of course, is nonsense that real code would not do, and
Quoted 8 lines
This test was added because 'real' code did this. In particular, if you initialize a stack of reftables, the stack has zero elements. The test was for the following bugfix
https://github.com/google/reftable/commit/b2e42ecb54e413e494c1fcc13c21e24422645007
Changing the array size to 1 here also prevents Valgrind to mark a regression as a OOB write.
Sorry to be unclear. I meant that real code would not allocate a static zero-length array (though it might do so on the heap). I agree that making sure the function behaves in the 0-segment case is quite reasonable.
Passing NULL actually makes the test more rigorous IMHO (because it is a strict superset of failure modes, and is something an actual caller might do if it were dynamically growing an array that started at NULL).
-Peff
Hi Han-Wen,
Quoted 26 lines · Han-Wen Nienhuys
Quoted 18 lines · Johannes Schindelin via GitGitGadget
These patches fix the PR build failures at
https://github.com/git/git/pull/847/checks?check_run_id=1460683728, and are designed to be squashed into the 16 patches of the libreftable v3 patch series as submitted at
https://lore.kernel.org/git/[email protected]/
.A smaller form of the first patch was offered on the mailing list on May 4th:
https://lore.kernel.org/git/ff60fde10919b6b8c54ecb8f38b710fac37624e3.1588599086.git.gitgitgadget@gmail.com/
. The next three patches were presented to the mailing list on October 2nd:
https://lore.kernel.org/git/[email protected]/
, and
https://lore.kernel.org/git/[email protected]/
. Some of the patches required slight adjustments to accommodate for context changes.Quoted 5 lines
Going forward, I would like to avoid the impression that it is the responsibility of the Git for Windows maintainer to keep the CI build passing on Windows. I am happy to assist in case it is unclear how to fix certain issues. I am not happy having to implement and test those fixes myself. How can we ensure this doesn't happen in the future?
Quoted 5 lines
Thanks for the build system fix. I think it's OK to leave it to me to solve the logic problems in the C code that you found.
Would you mind if I massaged these contributions directly back into github.com/google/reftable?
Whatever works best for you.
Quoted 3 lines
Google has a corporate CLA from Microsoft, it's OK to accept this from you. For better or worse, this is still where I'm developing reftable, until it has landed in git-core.
Ciao,
Dscho
Re: [PATCH 6/6] fixup! reftable: rest of library
In reply to Jeff KingHi Peff,
Quoted 7 lines · Jeff King
Quoted 5 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
The
stack_testhard-codes/tmp/. That is a particular problem on Windows where the temp directory is never at that location.
Quoted 6 lines
Quoted 2 lines
Let's not do that, but instead use
TMPDIRas we do in similar scenarios in the rest of Git's source code.Yeah, I noticed this, as well. This seems like a good band-aid, but it would probably be nice if the test tool was able to write into a specified directory (or even just the current directory).
You can force it to do that by setting TMPDIR to the path of the current directory...
Quoted 1 line
I don't see it being invoked anywhere,
It is invoked in t/t0032-reftable-unittest.sh:
https://github.com/dscho/git/blob/reftable-on-windows/t/t0032-reftable-unittest.sh
Quoted 2 lines
but presumably if we were to add support to our test suite, we'd have a script which invokes it within a scratch directory.
I agree that it would make most sense for t0032 to prefix the call to test-tool with TMPDIR=$PWD.
Ciao,
Dscho
Re: [PATCH 1/6] fixup! reftable: rest of library
In reply to Johannes Schindelin via GitGitGadgetQuoted 12 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Close the file descriptors to obsolete files before trying to delete or rename them. This is actually required on Windows.
Note: this patch is just a band-aid to get the tests pass on Windows. The fact that it is needed raises concerns about the overall resource
handling: are file descriptors closed properly whenever appropriate, or are they closed much later (which can lead torename()problems on Windows, and risks running into ulimits)?
Quoted 6 lines
Also, a
reftable_stack_destroy()call had to be moved intest_reftable_stack_uptodate()to avoid the prompt complaining that a.reffile could not be deleted on Windows. This raises the question whether the code does the right thing when two concurrent processes want to access the reftable, and one wants to compact it. At the moment, it does not appear to fail gracefully.
Thanks for the report; I have to look more closely at these fixes; I fear they might be incorrect.
The reftable spec doesn't treat this case in depth, and I think it was rather written for Unix-like semantics. In the Unix flavor, a process that wants to read can keep file descriptors open to keep reading from the ref DB at a consistent snapshot.
What is the approach that the rest of Git on Windows takes in these circumstances?
Consider processes P1 and P2, and the following sequence of actions
P1 opens ref DB (ie. opens a set of *.ref files for read) P2 opens ref DB, executes a transaction. Post-transaction, it compacts the reftable stack.
P2 exits
P1 exits
Currently, the compaction in P2 tries to delete the files obviated by the compaction. On Windows this currently fails, because you can't delete open files.
There are several options:
1) P2 should fail the compaction. This is bad because it will lead to degraded performance over time, and it's not obvious if you can anticipate that the deletion doesn't work.
2) P2 should retry deleting until it succeeds. This is bad, because a reader can starve writers.
3) on exit, P1 should check if its *.ref files are still in use, and delete them. This smells bad, because P1 is a read-only process, yet it executes writes. Also, do we have good on-exit hooks in Git?
4) On exit, P1 does nothing. Stale *.ref files are left behind. Some sort of GC process cleans things up asynchronously.
5) The ref DB should not keep files open, and should rather open and close files as needed; this means P1 doesn't keep files open for long, and P2 can retry safely.
I think 3) seems the cleanest to me (even though deleting in read process feels weird), but perhaps we could fallback to 5) on windows as well.
Thoughts?
What errno code does deleting an in-use file on Windows produce?
Quoted 103 lines
Signed-off-by Johannes Schindelin <[email protected]>--- reftable/stack.c | 37 ++++++++++++++++++++++++++++--------- reftable/stack_test.c | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-)reftable/stack.c +28
-9@@ -212,7 +212,6 @@ static int reftable_stack_reload_once(struct reftable_stack *st, char **names, goto done; new_tables =NULL ; - st->readers_len = new_readers_len;if (st->merged !=NULL ) {merged_table_release (st->merged);reftable_merged_table_free (st->merged);@@ -220,6 +219,7 @@ static int reftable_stack_reload_once(struct reftable_stack *st, char **names,if (st->readers !=NULL ) {reftable_free (st->readers); } + st->readers_len = new_readers_len; st->readers = new_readers; new_readers =NULL ; new_readers_len =0 ;@@ -939,14 +939,6 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,strbuf_addstr (&new_table_path,"/" );strbuf_addbuf (&new_table_path, &new_table_name); -if (!is_empty_table) { - err =rename (temp_tab_file_name.buf, new_table_path.buf); -if (err <0 ) { - err =REFTABLE_IO_ERROR ; - goto done; - } - } -for (i =0 ; i < first; i++) {strbuf_addstr (&ref_list_contents, st->readers[i]->name);strbuf_addstr (&ref_list_contents,"\n" );@@ -960,6 +952,32 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,strbuf_addstr (&ref_list_contents,"\n" ); } +/* +* Now release the merged tables and readers +*/ +if (st->merged !=NULL ) { +reftable_merged_table_free (st->merged); + st->merged =NULL ; + } + +if (st->readers !=NULL ) { +int i =0 ; +for (i =0 ; i < st->readers_len; i++) { +reader_close (st->readers[i]); +reftable_reader_free (st->readers[i]); + } + st->readers_len =0 ; +FREE_AND_NULL (st->readers); + } + +if (!is_empty_table) { + err =rename (temp_tab_file_name.buf, new_table_path.buf); +if (err <0 ) { + err =REFTABLE_IO_ERROR ; + goto done; + } + } + err =write (lock_file_fd, ref_list_contents.buf, ref_list_contents.len);if (err <0 ) { err =REFTABLE_IO_ERROR ;@@ -1242,6 +1260,7 @@ static int stack_check_addition(struct reftable_stack *st,free (refs);reftable_iterator_destroy (&it); +reader_close (rd);reftable_reader_free (rd);return err; }reftable/stack_test.c +1
-2@@ -159,12 +159,12 @@ static void test_reftable_stack_uptodate(void) err =reftable_stack_add (st2, &write_test_ref, &ref2);EXPECT (err ==REFTABLE_LOCK_ERROR ); +reftable_stack_destroy (st1); err =reftable_stack_reload (st2);EXPECT_ERR (err); err =reftable_stack_add (st2, &write_test_ref, &ref2);EXPECT_ERR (err); -reftable_stack_destroy (st1);reftable_stack_destroy (st2);clear_dir (dir); } --gitgitgadget
Signature · 11 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Re: [PATCH 6/6] fixup! reftable: rest of library
In reply to Johannes SchindelinQuoted 4 lines · Johannes Schindelin
Quoted 1 line
I don't see it being invoked anywhere,
It is invoked in
t/t0032-reftable-unittest.sh:
https://github.com/dscho/git/blob/reftable-on-windows/t/t0032-reftable-unittest.sh
Ah, thank you. I was looking at what Junio has queued in hn/reftable.
Quoted 5 lines
Quoted 2 lines
but presumably if we were to add support to our test suite, we'd have a script which invokes it within a scratch directory.
I agree that it would make most sense for t0032 to prefix the call to
test-toolwithTMPDIR=$PWD.
Yep, that would be fine.
I'm not sure if the long-term goal is to have this opaque unit-test program or not. If it is, I was likewise going to suggest that its ad-hoc output be replaced with TAP. But it looks like on your branch that "test-tool reftable" does not produce output at all. So I may be a bit behind on what the current state and forward plans are...
-Peff
Re: [PATCH 6/6] fixup! reftable: rest of library
Quoted 13 lines · Jeff King
Quoted 4 lines
Quoted 1 line
I don't see it being invoked anywhere,
It is invoked in
t/t0032-reftable-unittest.sh:
https://github.com/dscho/git/blob/reftable-on-windows/t/t0032-reftable-unittest.shAh, thank you. I was looking at what Junio has queued in hn/reftable.
Quoted 5 lines
Quoted 2 lines
but presumably if we were to add support to our test suite, we'd have a script which invokes it within a scratch directory.
I agree that it would make most sense for t0032 to prefix the call to
test-toolwithTMPDIR=$PWD.
Quoted 7 lines
Yep, that would be fine.
I'm not sure if the long-term goal is to have this opaque unit-test program or not. If it is, I was likewise going to suggest that its ad-hoc output be replaced with TAP. But it looks like on your branch that "test-tool reftable" does not produce output at all. So I may be a bit behind on what the current state and forward plans are...
The most important requirement is that something fails if the unittests don't work. I surmised that that meant running tests from test-helper in some way, so this is what happens now. Looking for "unit.?test" across the git codebase didn't turn up much info. Happy to explore other solutions if you can give me pointers.
Signature · 8 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Re: [PATCH 1/6] fixup! reftable: rest of library
In reply to Han-Wen NienhuysHi Han-Wen,
Quoted 21 lines · Han-Wen Nienhuys
Quoted 12 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Close the file descriptors to obsolete files before trying to delete or rename them. This is actually required on Windows.
Note: this patch is just a band-aid to get the tests pass on Windows. The fact that it is needed raises concerns about the overall resource
handling: are file descriptors closed properly whenever appropriate, or are they closed much later (which can lead torename()problems on Windows, and risks running into ulimits)?Quoted 6 lines
Also, a
reftable_stack_destroy()call had to be moved intest_reftable_stack_uptodate()to avoid the prompt complaining that a.reffile could not be deleted on Windows. This raises the question whether the code does the right thing when two concurrent processes want to access the reftable, and one wants to compact it. At the moment, it does not appear to fail gracefully.
Quoted 2 lines
Thanks for the report; I have to look more closely at these fixes; I fear they might be incorrect.
They might be incorrect, but less so than the previous state, as testified by the previously failing PR build.
Quoted 4 lines
The reftable spec doesn't treat this case in depth, and I think it was rather written for Unix-like semantics. In the Unix flavor, a process that wants to read can keep file descriptors open to keep reading from the ref DB at a consistent snapshot.
Thanks for the explanation. I actually knew that.
Quoted 2 lines
What is the approach that the rest of Git on Windows takes in these circumstances?
The rest of Git (whether on Windows or not) treats this as a no-no. You cannot keep a handle open to a file that is deleted.
Quoted 11 lines
Consider processes P1 and P2, and the following sequence of actions
P1 opens ref DB (ie. opens a set of *.ref files for read) P2 opens ref DB, executes a transaction. Post-transaction, it compacts the reftable stack.
P2 exits
P1 exitsCurrently, the compaction in P2 tries to delete the files obviated by the compaction. On Windows this currently fails, because you can't delete open files.
Indeed. So the design needs to be fixed, if it fails.
Quoted 16 lines
There are several options:
1) P2 should fail the compaction. This is bad because it will lead to degraded performance over time, and it's not obvious if you can anticipate that the deletion doesn't work.
2) P2 should retry deleting until it succeeds. This is bad, because a reader can starve writers.
3) on exit, P1 should check if its *.ref files are still in use, and delete them. This smells bad, because P1 is a read-only process, yet it executes writes. Also, do we have good on-exit hooks in Git?
4) On exit, P1 does nothing. Stale *.ref files are left behind. Some sort of GC process cleans things up asynchronously.
5) The ref DB should not keep files open, and should rather open and close files as needed; this means P1 doesn't keep files open for long, and P2 can retry safely.
Quoted 3 lines
I think 3) seems the cleanest to me (even though deleting in read process feels weird), but perhaps we could fallback to 5) on windows as well.
Traditionally, Git would fail gracefully (i.e. with a warning) to delete the stale files, and try again at a later stage (during git gc --auto, for example, or after the next compaction step).
Quoted 1 line
What errno code does deleting an in-use file on Windows produce?
I believe it would be EACCES. See
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/unlink-wunlink?view=msvc-160
for the documented behavior (I believe that an in-use file is treated the same way as a read-only file in this instance).
Ciao,
Dscho
Re: [PATCH 6/6] fixup! reftable: rest of library
In reply to Han-Wen NienhuysQuoted 11 lines · Han-Wen Nienhuys
Quoted 5 lines
I'm not sure if the long-term goal is to have this opaque unit-test program or not. If it is, I was likewise going to suggest that its ad-hoc output be replaced with TAP. But it looks like on your branch that "test-tool reftable" does not produce output at all. So I may be a bit behind on what the current state and forward plans are...
The most important requirement is that something fails if the unittests don't work. I surmised that that meant running tests from test-helper in some way, so this is what happens now. Looking for "unit.?test" across the git codebase didn't turn up much info. Happy to explore other solutions if you can give me pointers.
Normally we do a combination of:
- git plumbing exposes scriptable commands, and we make sure those work. This is a much coarser-grained unit than testing individual C functions, but produces resilient tests because that interface is user-visible and stable (and in fact seeing test breakages is often a sign that one will be breaking real users).
These are obviously driven by shell script tests emulating what users might run.
- for unit tests of individual data types where it's not appropriate to have a user-facing command, we often add a test-tool helper that exposes specific functions (e.g., t/helper/test-date.c exposes date parsing and formatting routines, test-oid-array.c exercises methods of that data type, etc).
The C parts of these are usually generic, and then are driven by shell scripts providing the actual data in individual tests (and handling success/failure, skipping tests, etc).
This is still coarser than you might get unit-testing inside C. E.g., you could not generally check the difference between passing an empty array vs NULL to a function. But our philosophy has generally been _not_ to test at that level. The C interfaces are internal, and Git is not that big a project. If there's a function whose caller does something unexpected, it's usually easier to fix the caller and add a test that triggers the caller's code path.
I agree that a test that simply runs a bunch of C code and either exits with failure or success is better than nothing, in the sense of finding tests. And wrapping that with a single test_expect_success does that. But it's unfortunate that we get none of the fine-grained control that the test suite provides, nor much support in debugging failing tests.
One middle ground would be for a battery of C tests to output TAP-compatible output (outputting "ok 1 - foo works", and "not ok 2 - bar does not work", etc). That at least gives more info on what fails, and does it in a way that the rest of the test suite can interpret (though not manipulate).
-Peff
Reftable locking on Windows (Re: [PATCH 1/6] fixup! reftable: rest of library)
In reply to Johannes SchindelinQuoted 30 lines · Johannes Schindelin
Quoted 11 lines
Consider processes P1 and P2, and the following sequence of actions
P1 opens ref DB (ie. opens a set of *.ref files for read) P2 opens ref DB, executes a transaction. Post-transaction, it compacts the reftable stack.
P2 exits
P1 exitsCurrently, the compaction in P2 tries to delete the files obviated by the compaction. On Windows this currently fails, because you can't delete open files.
Indeed. So the design needs to be fixed, if it fails.
Quoted 16 lines
There are several options:
1) P2 should fail the compaction. This is bad because it will lead to degraded performance over time, and it's not obvious if you can anticipate that the deletion doesn't work.
2) P2 should retry deleting until it succeeds. This is bad, because a reader can starve writers.
3) on exit, P1 should check if its *.ref files are still in use, and delete them. This smells bad, because P1 is a read-only process, yet it executes writes. Also, do we have good on-exit hooks in Git?
4) On exit, P1 does nothing. Stale *.ref files are left behind. Some sort of GC process cleans things up asynchronously.
5) The ref DB should not keep files open, and should rather open and close files as needed; this means P1 doesn't keep files open for long, and P2 can retry safely.
Quoted 7 lines
Quoted 3 lines
I think 3) seems the cleanest to me (even though deleting in read process feels weird), but perhaps we could fallback to 5) on windows as well.
Traditionally, Git would fail gracefully (i.e. with a warning) to delete the stale files, and try again at a later stage (during
git gc --auto, for example, or after the next compaction step).
So, how does this sound:
* add a void
set_warn_handler(void(*handler)(char const*))
The handler is called for non-fatal errors (eg. deleting an in-use .ref file during compaction), and can provide the warning.
* all .ref files will be prefixed with an 8-byte random string, to avoid that new *.ref files collide with unreferenced, stale *.ref files.
* in reftable_stack_close(), after closing files, we check if *.ref files we were reading have gone out of use. If so, delete those .ref files, printing a warning on EACCESS.
* an on-exit handler in git calls reftable_stack_close()
* provide a reftable_stack_gc(), which loads tables.list and then deletes all unused *.ref files that are older than tables.list.
Quoted 6 lines
Quoted 1 line
What errno code does deleting an in-use file on Windows produce?
I believe it would be
EACCES. See
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/unlink-wunlink?view=msvc-160
for the documented behavior (I believe that an in-use file is treated the same way as a read-only file in this instance).
your commit message says "to avoid the prompt complaining that a .ref file could not be deleted on Windows." AFAICT, this prompt is coming from windows itself, because the reftable library doesn't issue this type of warning. Is there a way to delete a file that just returns EACCESS if it fails, without triggering a prompt? Or is the prompt part of the "failing gracefully" behavior?
Signature · 7 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Re: Reftable locking on Windows (Re: [PATCH 1/6] fixup! reftable: rest of library)
Quoted 44 lines · Han-Wen Nienhuys
Quoted 30 lines · Johannes Schindelin
Quoted 11 lines
Consider processes P1 and P2, and the following sequence of actions
P1 opens ref DB (ie. opens a set of *.ref files for read) P2 opens ref DB, executes a transaction. Post-transaction, it compacts the reftable stack.
P2 exits
P1 exitsCurrently, the compaction in P2 tries to delete the files obviated by the compaction. On Windows this currently fails, because you can't delete open files.
Indeed. So the design needs to be fixed, if it fails.
Quoted 16 lines
There are several options:
1) P2 should fail the compaction. This is bad because it will lead to degraded performance over time, and it's not obvious if you can anticipate that the deletion doesn't work.
2) P2 should retry deleting until it succeeds. This is bad, because a reader can starve writers.
3) on exit, P1 should check if its *.ref files are still in use, and delete them. This smells bad, because P1 is a read-only process, yet it executes writes. Also, do we have good on-exit hooks in Git?
4) On exit, P1 does nothing. Stale *.ref files are left behind. Some sort of GC process cleans things up asynchronously.
5) The ref DB should not keep files open, and should rather open and close files as needed; this means P1 doesn't keep files open for long, and P2 can retry safely.Quoted 7 lines
Quoted 3 lines
I think 3) seems the cleanest to me (even though deleting in read process feels weird), but perhaps we could fallback to 5) on windows as well.
Traditionally, Git would fail gracefully (i.e. with a warning) to delete the stale files, and try again at a later stage (during
git gc --auto, for example, or after the next compaction step).So, how does this sound:
* add a void
Quoted 8 lines
set_warn_handler(void(*handler)(char const*))The handler is called for non-fatal errors (eg. deleting an in-use .ref file during compaction), and can provide the warning.
* all .ref files will be prefixed with an 8-byte random string, to avoid that new *.ref files collide with unreferenced, stale *.ref files.
Just trying to follow along here. Do you mean prefix the file name or the content of those *.ref files? In any case isn't this synonymous with proposing moving beyond reftable v1 (to the WIP v2, or a v1.1 with just this change?). The current spec seems to preclude prefixing either the file content or filename, but maybe I'm misreading it:
https://googlers.googlesource.com/sop/jgit/+/reftable/Documentation/technical/reftable.md#update-transactions
https://googlers.googlesource.com/sop/jgit/+/reftable/Documentation/technical/reftable.md#header
When the reftable format was initially being discussed I suggested somewhat flippantly (why not SQLite?). Partially because in trying to invent what's essentially a portable and concurrently updated database format we'd be likely to reinvent much of the same wheel.
So not to drag that whole thing up again as a proposal for a format replacement, but I wonder what SQLite would do in this scenario & others where desired DB semantics / transactions and FS/portability semantics clash. AFAIK the reftable has only been battle-tested in production under JGit so far (presumably Linux-only). Whereas SQLite has been ported to and widely used on Windows, HP/UX and probably other systems where Linux-specific assumptions don't apply.
Quoted 26 lines
* in
reftable_stack_close(), after closing files, we check if *.ref files we were reading have gone out of use. If so, delete those .ref files, printing a warning on EACCESS.* an on-exit handler in git calls
reftable_stack_close()* provide a
reftable_stack_gc(), which loads tables.list and then deletes all unused *.ref files that are older than tables.list.Quoted 6 lines
Quoted 1 line
What errno code does deleting an in-use file on Windows produce?
I believe it would be
EACCES. See
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/unlink-wunlink?view=msvc-160
for the documented behavior (I believe that an in-use file is treated the same way as a read-only file in this instance).your commit message says "to avoid the prompt complaining that a
.reffile could not be deleted on Windows." AFAICT, this prompt is coming from windows itself, because the reftable library doesn't issue this type of warning. Is there a way to delete a file that just returns EACCESS if it fails, without triggering a prompt? Or is the prompt part of the "failing gracefully" behavior?Signature · 2 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays.
Re: Reftable locking on Windows (Re: [PATCH 1/6] fixup! reftable: rest of library)
Quoted 39 lines · Ævar Arnfjörð Bjarmason
Quoted 30 lines
Quoted 18 lines
Indeed. So the design needs to be fixed, if it fails.
Quoted 16 lines
There are several options:
1) P2 should fail the compaction. This is bad because it will lead to degraded performance over time, and it's not obvious if you can anticipate that the deletion doesn't work.
2) P2 should retry deleting until it succeeds. This is bad, because a reader can starve writers.
3) on exit, P1 should check if its *.ref files are still in use, and delete them. This smells bad, because P1 is a read-only process, yet it executes writes. Also, do we have good on-exit hooks in Git?
4) On exit, P1 does nothing. Stale *.ref files are left behind. Some sort of GC process cleans things up asynchronously.
5) The ref DB should not keep files open, and should rather open and close files as needed; this means P1 doesn't keep files open for long, and P2 can retry safely.Quoted 7 lines
Quoted 3 lines
I think 3) seems the cleanest to me (even though deleting in read process feels weird), but perhaps we could fallback to 5) on windows as well.
Traditionally, Git would fail gracefully (i.e. with a warning) to delete the stale files, and try again at a later stage (during
git gc --auto, for example, or after the next compaction step).So, how does this sound:
* add a void
Quoted 8 lines
set_warn_handler(void(*handler)(char const*))The handler is called for non-fatal errors (eg. deleting an in-use .ref file during compaction), and can provide the warning.
* all .ref files will be prefixed with an 8-byte random string, to avoid that new *.ref files collide with unreferenced, stale *.ref files.
Quoted 5 lines
Just trying to follow along here. Do you mean prefix the file name or the content of those *.ref files? In any case isn't this synonymous with proposing moving beyond reftable v1 (to the WIP v2, or a v1.1 with just this change?). The current spec seems to preclude prefixing either the file content or filename, but maybe I'm misreading it:
This is about prefixing the filename with an uniquifying prefix. This is because the range of timestamps encompassed by the table doesn't uniquely identify the table.
Consider the following case:
State: 1 table "00001.ref"
Transaction 1: add ref xyz at timestamp 2
add ref abc at timestamp 2
=> 00002.ref
Transaction 2: add delete ref xyz at timestamp 3
=> 00003.ref
On compacting 00002 and 00003 together, you'll end up with a table for only "ref abc at timestamp 2". If you call that result 00002.ref again, there are two versions 00002.ref.
In the current spec with unix semantics, that's not a problem, because out of date tables are removed, and disappear once the last reader closes the file, but if we have to cater for a system
where removal that doesn't always work, we'd have to fix up things afterwards. That means we have to be able to tell apart these two versions of 00002.ref, and this is where a random prefix would help.
The exact naming of the tables is not central to the spec, as the table names to read are listed in tables.list, and systems can write filenames as they please. Maybe recommendations around filenames should be phrased as a "SHOULD" clause, with a "MUST" that each table has a globally unique name.
Quoted 8 lines
https://googlers.googlesource.com/sop/jgit/+/reftable/Documentation/technical/reftable.md#update-transactions
https://googlers.googlesource.com/sop/jgit/+/reftable/Documentation/technical/reftable.md#headerWhen the reftable format was initially being discussed I suggested somewhat flippantly (why not SQLite?). Partially because in trying to invent what's essentially a portable and concurrently updated database format we'd be likely to reinvent much of the same wheel.
Quoted 7 lines
So not to drag that whole thing up again as a proposal for a format replacement, but I wonder what SQLite would do in this scenario & others where desired DB semantics / transactions and FS/portability semantics clash. AFAIK the reftable has only been battle-tested in production under JGit so far (presumably Linux-only). Whereas SQLite has been ported to and widely used on Windows, HP/UX and probably other systems where Linux-specific assumptions don't apply.
I think it would be an interesting exercise to build a ref database on SQLite, and I wish it had been done before, because large part of the work of getting reftable to work with git proper, is disentangling the code with assumptions about the underlying ref storage system.
I agree that some of this is reinventing the wheel, and I wish that reftable had been based on another format (say, LevelDB) to get away from bit mangling, but I think SQlite is a tricky proposition, because SQLite is a system with considerable complexity of its own. You'd force all the other Git implementations (libgit2, Microsoft's C#, go-git, JGit, Dulwhich etc.) to find a way to implement SQLite support. That will be a difficult proposition for the implementations that try to avoid FFI.
You could also look at this from the positive side, which is that the transaction semantics of reftable are much easier to understand and verify than those of the files backend.
--
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays. --
Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado --
Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado