Skip to content

Commit 135f491

Browse files
KarthikNayakgitster
authored andcommitted
reftable/stack: return stack segments directly
The `stack_table_sizes_for_compaction()` function returns individual sizes of each reftable table. This function is only called by `reftable_stack_auto_compact()` to decide which tables need to be compacted, if any. Modify the function to directly return the segments, which avoids the extra step of receiving the sizes only to pass it to `suggest_compaction_segment()`. A future commit will also add functionality for checking whether auto-compaction is necessary without performing it. This change allows code re-usability in that context. Signed-off-by: Karthik Nayak <[email protected]> Acked-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 31177a8 commit 135f491

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

reftable/stack.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,37 +1626,38 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
16261626
return seg;
16271627
}
16281628

1629-
static uint64_t *stack_table_sizes_for_compaction(struct reftable_stack *st)
1629+
static int stack_segments_for_compaction(struct reftable_stack *st,
1630+
struct segment *seg)
16301631
{
16311632
int version = (st->opts.hash_id == REFTABLE_HASH_SHA1) ? 1 : 2;
16321633
int overhead = header_size(version) - 1;
16331634
uint64_t *sizes;
16341635

16351636
REFTABLE_CALLOC_ARRAY(sizes, st->merged->tables_len);
16361637
if (!sizes)
1637-
return NULL;
1638+
return REFTABLE_OUT_OF_MEMORY_ERROR;
16381639

16391640
for (size_t i = 0; i < st->merged->tables_len; i++)
16401641
sizes[i] = st->tables[i]->size - overhead;
16411642

1642-
return sizes;
1643+
*seg = suggest_compaction_segment(sizes, st->merged->tables_len,
1644+
st->opts.auto_compaction_factor);
1645+
reftable_free(sizes);
1646+
1647+
return 0;
16431648
}
16441649

16451650
int reftable_stack_auto_compact(struct reftable_stack *st)
16461651
{
16471652
struct segment seg;
1648-
uint64_t *sizes;
1653+
int err;
16491654

16501655
if (st->merged->tables_len < 2)
16511656
return 0;
16521657

1653-
sizes = stack_table_sizes_for_compaction(st);
1654-
if (!sizes)
1655-
return REFTABLE_OUT_OF_MEMORY_ERROR;
1656-
1657-
seg = suggest_compaction_segment(sizes, st->merged->tables_len,
1658-
st->opts.auto_compaction_factor);
1659-
reftable_free(sizes);
1658+
err = stack_segments_for_compaction(st, &seg);
1659+
if (err)
1660+
return err;
16601661

16611662
if (segment_size(&seg) > 0)
16621663
return stack_compact_range(st, seg.start, seg.end - 1,

0 commit comments

Comments
 (0)