Skip to content

Commit

Permalink
config: reload: bin: Add opt-in option to ensure thread safety on hot…
Browse files Browse the repository at this point in the history
… reloading

Signed-off-by: Hiroshi Hatake <hatake@calyptia.com>
  • Loading branch information
cosmo0920 committed Jun 1, 2023
1 parent 3fdd42c commit 43547c7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
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
4 changes: 4 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
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, --ensure-thread-safety-on-hot-reloading", "ensure 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
{ "ensure-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, "on", 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

0 comments on commit 43547c7

Please sign in to comment.