]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reftable/stack: expose option to disable auto-compaction
authorJustin Tobler <jltobler@gmail.com>
Mon, 8 Apr 2024 16:16:53 +0000 (16:16 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Apr 2024 19:11:10 +0000 (12:11 -0700)
The reftable stack already has a variable to configure whether or not to
run auto-compaction, but it is inaccessible to users of the library.
There exist use cases where a caller may want to have more control over
auto-compaction.

Move the `disable_auto_compact` option into `reftable_write_options` to
allow external callers to disable auto-compaction. This will be used in
a subsequent commit.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/reftable-writer.h
reftable/stack.c
reftable/stack.h
reftable/stack_test.c

index 7c7cae5f99b7cd4c2be74707bb550366e1088a35..155bf0bbe2a3b0310f6c5a8bd0db11545f73d6dd 100644 (file)
@@ -46,6 +46,9 @@ struct reftable_write_options {
         *   is a single line, and add '\n' if missing.
         */
        unsigned exact_log_message : 1;
+
+       /* boolean: Prevent auto-compaction of tables. */
+       unsigned disable_auto_compact : 1;
 };
 
 /* reftable_block_stats holds statistics for a single block type */
index dde50b61d696befd29bb16452e0e2588f0823761..1a7cdad12c92a0cc06220050b68da7a45f88fb03 100644 (file)
@@ -680,7 +680,7 @@ int reftable_addition_commit(struct reftable_addition *add)
        if (err)
                goto done;
 
-       if (!add->stack->disable_auto_compact) {
+       if (!add->stack->config.disable_auto_compact) {
                /*
                 * Auto-compact the stack to keep the number of tables in
                 * control. It is possible that a concurrent writer is already
index d919455669ede0b2872a2d19ee12870479ab99ab..c862053025f1f0241592092afd8b90e530ab33fb 100644 (file)
@@ -19,7 +19,6 @@ struct reftable_stack {
        int list_fd;
 
        char *reftable_dir;
-       int disable_auto_compact;
 
        struct reftable_write_options config;
 
index 7b2a8b1afd588db31f9a3d26d0486923cd540ce7..fc14b1d1f5e1caef7e416afbf8e7510adc76617a 100644 (file)
@@ -315,7 +315,7 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void)
                 * we can ensure that we indeed honor this setting and have
                 * better control over when exactly auto compaction runs.
                 */
-               st->disable_auto_compact = i != n;
+               st->config.disable_auto_compact = i != n;
 
                err = reftable_stack_new_addition(&add, st);
                EXPECT_ERR(err);
@@ -487,6 +487,7 @@ static void test_reftable_stack_add(void)
        struct reftable_write_options cfg = {
                .exact_log_message = 1,
                .default_permissions = 0660,
+               .disable_auto_compact = 1,
        };
        struct reftable_stack *st = NULL;
        char *dir = get_tmp_dir(__LINE__);
@@ -498,7 +499,6 @@ static void test_reftable_stack_add(void)
 
        err = reftable_new_stack(&st, dir, cfg);
        EXPECT_ERR(err);
-       st->disable_auto_compact = 1;
 
        for (i = 0; i < N; i++) {
                char buf[256];
@@ -925,7 +925,9 @@ static void test_empty_add(void)
 
 static void test_reftable_stack_auto_compaction(void)
 {
-       struct reftable_write_options cfg = { 0 };
+       struct reftable_write_options cfg = {
+               .disable_auto_compact = 1,
+       };
        struct reftable_stack *st = NULL;
        char *dir = get_tmp_dir(__LINE__);
 
@@ -935,7 +937,6 @@ static void test_reftable_stack_auto_compaction(void)
        err = reftable_new_stack(&st, dir, cfg);
        EXPECT_ERR(err);
 
-       st->disable_auto_compact = 1; /* call manually below for coverage. */
        for (i = 0; i < N; i++) {
                char name[100];
                struct reftable_ref_record ref = {
@@ -984,7 +985,7 @@ static void test_reftable_stack_add_performs_auto_compaction(void)
                 * we can ensure that we indeed honor this setting and have
                 * better control over when exactly auto compaction runs.
                 */
-               st->disable_auto_compact = i != n;
+               st->config.disable_auto_compact = i != n;
 
                strbuf_reset(&refname);
                strbuf_addf(&refname, "branch-%04d", i);