reftable/stack: update stats on failed full compaction

When auto-compaction fails due to a locking error, we update the statistics to indicate this failure. We're not doing the same when performing a full compaction. Fix this inconsistency by using `stack_compact_range_stats()`, which handles the stat update for us. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 8, 2024 at 16:06 UTC 5f0ed603a1653f2394c468814bde4b0dca2cff45
2 files changed +8 -9
reftable/stack.c
+7 -7
@@ -1205,13 +1205,6 @@ done:
1205 return err;
1206 }
1207
1208 -int reftable_stack_compact_all(struct reftable_stack *st,
1209 - struct reftable_log_expiry_config *config)
1210 -{
1211 - return stack_compact_range(st, 0, st->merged->stack_len ?
1212 - st->merged->stack_len - 1 : 0, config);
1213 -}
1214 -
1208 static int stack_compact_range_stats(struct reftable_stack *st,
1209 size_t first, size_t last,
1210 struct reftable_log_expiry_config *config)
@@ -1222,6 +1215,13 @@ static int stack_compact_range_stats(struct reftable_stack *st,
1215 return err;
1216 }
1217
1218 +int reftable_stack_compact_all(struct reftable_stack *st,
1219 + struct reftable_log_expiry_config *config)
1220 +{
1221 + size_t last = st->merged->stack_len ? st->merged->stack_len - 1 : 0;
1222 + return stack_compact_range_stats(st, 0, last, config);
1223 +}
1224 +
1225 static int segment_size(struct segment *s)
1226 {
1227 return s->end - s->start;
reftable/stack_test.c
+1 -2
@@ -1005,8 +1005,7 @@ static void test_reftable_stack_compaction_with_locked_tables(void)
1005 */
1006 err = reftable_stack_compact_all(st, NULL);
1007 EXPECT(err == REFTABLE_LOCK_ERROR);
1008 - /* TODO: this is wrong, we should get notified about the failure. */
1009 - EXPECT(st->stats.failures == 0);
1008 + EXPECT(st->stats.failures == 1);
1009 EXPECT(st->merged->stack_len == 3);
1010
1011 reftable_stack_destroy(st);