Skip to content

Commit

Permalink
plugin_proxy: Add pre registration callback for hot-reloading state h…
Browse files Browse the repository at this point in the history
…andling

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Oct 3, 2023
1 parent 0df0575 commit bb9ff31
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/fluent-bit/flb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ struct flb_config {
int ensure_thread_safety_on_hot_reloading;
unsigned int hot_reloaded_count;
int shutdown_by_hot_reloading;
int hot_reloading;

/* Co-routines */
unsigned int coro_stack_size;
Expand Down
1 change: 1 addition & 0 deletions src/flb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ struct flb_config *flb_config_init()
config->ensure_thread_safety_on_hot_reloading = FLB_TRUE;
config->hot_reloaded_count = 0;
config->shutdown_by_hot_reloading = FLB_FALSE;
config->hot_reloading = FLB_FALSE;

#ifdef FLB_HAVE_SQLDB
mk_list_init(&config->sqldb_list);
Expand Down
11 changes: 11 additions & 0 deletions src/flb_plugin_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,19 @@ int flb_plugin_proxy_register(struct flb_plugin_proxy *proxy,
{
int ret;
int (*cb_register)(struct flb_plugin_proxy_def *);
int (*cb_pre_register)(int);
struct flb_plugin_proxy_def *def = proxy->def;

/* Lookup the pre registration callback */
cb_pre_register = flb_plugin_proxy_symbol(proxy, "FLBPluginPreRegister");
if (cb_pre_register != NULL) {
/* Prepare the registration if available */
ret = cb_pre_register(config->hot_reloading);
if (ret == -1) {
return -1;
}
}

/* Lookup the registration callback */
cb_register = flb_plugin_proxy_symbol(proxy, "FLBPluginRegister");
if (!cb_register) {
Expand Down
3 changes: 3 additions & 0 deletions src/flb_reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts)
reloaded_count = ctx->config->hot_reloaded_count + 1;
/* Mark shutdown reason as hot_reloading */
ctx->config->shutdown_by_hot_reloading = FLB_TRUE;
/* Mark hot reloading */
new_config->hot_reloading = FLB_TRUE;

#ifdef FLB_HAVE_STREAM_PROCESSOR
/* Inherit stream processor definitions from command line */
Expand Down Expand Up @@ -513,6 +515,7 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts)
if (ret == 0) {
new_config->hot_reloaded_count = reloaded_count;
flb_debug("[reload] hot reloaded %d time(s)", reloaded_count);
new_config->hot_reloading = FLB_FALSE;
}

return 0;
Expand Down

0 comments on commit bb9ff31

Please sign in to comment.