reftable/stack: add mechanism to notify callers on reload

Reftable stacks are reloaded in two cases: - When calling `reftable_stack_reload()`, if the stat-cache tells us that the stack has been modified. - When committing a reftable addition. While callers can figure out the second case, they do not have a mechanism to figure out whether `reftable_stack_reload()` led to an actual reload of the on-disk data. All they can do is thus to assume that data is always being reloaded in that case. Improve the situation by introducing a new `on_reload()` callback to the reftable options. If provided, the function will be invoked every time the stack has indeed been reloaded. This allows callers to invalidate data that depends on the current stack data. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 26, 2024 at 07:42 UTC eb22c1b46b85f7fac8467f991890d50853e4ca4d
2 files changed +13
reftable/reftable-writer.h
+9
@@ -68,6 +68,15 @@ struct reftable_write_options {
68 * fsync(3P) when unset.
69 */
70 int (*fsync)(int fd);
71 +
72 + /*
73 + * Callback function to execute whenever the stack is being reloaded.
74 + * This can be used e.g. to discard cached information that relies on
75 + * the old stack's data. The payload data will be passed as argument to
76 + * the callback.
77 + */
78 + void (*on_reload)(void *payload);
79 + void *on_reload_payload;
80 };
81
82 /* reftable_block_stats holds statistics for a single block type */
reftable/stack.c
+4
@@ -548,6 +548,10 @@ out:
548 close(fd);
549 free_names(names);
550 free_names(names_after);
551 +
552 + if (st->opts.on_reload)
553 + st->opts.on_reload(st->opts.on_reload_payload);
554 +
555 return err;
556 }
557