Skip to content

Commit eb22c1b

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 96e7cb8 commit eb22c1b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

reftable/reftable-writer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ struct reftable_write_options {
6868
* fsync(3P) when unset.
6969
*/
7070
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;
7180
};
7281

7382
/* reftable_block_stats holds statistics for a single block type */

reftable/stack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st,
548548
close(fd);
549549
free_names(names);
550550
free_names(names_after);
551+
552+
if (st->opts.on_reload)
553+
st->opts.on_reload(st->opts.on_reload_payload);
554+
551555
return err;
552556
}
553557

0 commit comments

Comments
 (0)