Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: reload: bin: Add opt-out option to ensure thread safety on hot reloading #7509

Merged
merged 2 commits into from Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/fluent-bit/flb_config.h
Expand Up @@ -257,6 +257,7 @@ struct flb_config {
#endif /* FLB_HAVE_CHUNK_TRACE */

int enable_hot_reload;
int ensure_thread_safety_on_hot_reloading;

/* Co-routines */
unsigned int coro_stack_size;
Expand Down Expand Up @@ -337,6 +338,7 @@ enum conf_type {
#endif /* FLB_HAVE_CHUNK_TRACE */

#define FLB_CONF_STR_HOT_RELOAD "Hot_Reload"
#define FLB_CONF_STR_HOT_RELOAD_ENSURE_THREAD_SAFETY "Hot_Reload.Ensure_Thread_Safety"

/* DNS */
#define FLB_CONF_DNS_MODE "dns.mode"
Expand Down
7 changes: 7 additions & 0 deletions src/flb_config.c
Expand Up @@ -177,6 +177,10 @@ struct flb_service_config service_configs[] = {
FLB_CONF_TYPE_BOOL,
offsetof(struct flb_config, enable_hot_reload)},

{FLB_CONF_STR_HOT_RELOAD_ENSURE_THREAD_SAFETY,
FLB_CONF_TYPE_BOOL,
offsetof(struct flb_config, ensure_thread_safety_on_hot_reloading)},

{NULL, FLB_CONF_TYPE_OTHER, 0} /* end of array */
};

Expand Down Expand Up @@ -268,6 +272,9 @@ struct flb_config *flb_config_init()
config->sched_cap = FLB_SCHED_CAP;
config->sched_base = FLB_SCHED_BASE;

/* reload */
config->ensure_thread_safety_on_hot_reloading = FLB_TRUE;

#ifdef FLB_HAVE_SQLDB
mk_list_init(&config->sqldb_list);
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/flb_reload.c
Expand Up @@ -380,6 +380,10 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts)
return -3;
}

if (old_config->ensure_thread_safety_on_hot_reloading) {
old_config->grace = -1;
}

/* Normally, we should create a service section before using this cf
* context. However, this context of config format will be used
* for copying contents from other one. So, we just need to create
Expand Down
8 changes: 7 additions & 1 deletion src/fluent-bit.c
Expand Up @@ -150,6 +150,7 @@ static void flb_help(int rc, struct flb_config *config)
print_opt("-q, --quiet", "quiet mode");
print_opt("-S, --sosreport", "support report for Enterprise customers");
print_opt("-Y, --enable-hot-reload", "enable for hot reloading");
print_opt("-W, --disable-thread-safety-on-hot-reloading", "disable thread safety on hot reloading");
print_opt("-V, --version", "show version number");
print_opt("-h, --help", "print this help");

Expand Down Expand Up @@ -804,6 +805,7 @@ int flb_main(int argc, char **argv)
#ifdef FLB_HAVE_CHUNK_TRACE
{ "enable-chunk-trace", no_argument, NULL, 'Z' },
#endif
{ "disable-thread-safety-on-hot-reload", no_argument, NULL, 'W' },
{ NULL, 0, NULL, 0 }
};

Expand All @@ -830,7 +832,7 @@ int flb_main(int argc, char **argv)
/* Parse the command line options */
while ((opt = getopt_long(argc, argv,
"b:c:dDf:C:i:m:o:R:F:p:e:"
"t:T:l:vw:qVhJL:HP:s:SYZ",
"t:T:l:vw:qVhJL:HP:s:SWYZ",
long_opts, NULL)) != -1) {

switch (opt) {
Expand Down Expand Up @@ -988,6 +990,10 @@ int flb_main(int argc, char **argv)
case 'Y':
flb_cf_section_property_add(cf_opts, service->properties, FLB_CONF_STR_HOT_RELOAD, 0, "on", 0);
break;
case 'W':
flb_cf_section_property_add(cf_opts, service->properties,
FLB_CONF_STR_HOT_RELOAD_ENSURE_THREAD_SAFETY, 0, "off", 0);
break;
#ifdef FLB_HAVE_CHUNK_TRACE
case 'Z':
flb_cf_section_property_add(cf_opts, service->properties, FLB_CONF_STR_ENABLE_CHUNK_TRACE, 0, "on", 0);
Expand Down