Skip to content

Commit 4a09139

Browse files
committed
fix tunable default update
Signed-off-by: Emelia Lei <wlei29@bloomberg.net>
1 parent 0cad820 commit 4a09139

File tree

12 files changed

+24
-4
lines changed

12 files changed

+24
-4
lines changed

db/db_tunables.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ extern int gbl_all_prepare_abort;
193193
extern int gbl_all_prepare_leak;
194194
extern int gbl_flush_on_prepare;
195195
extern int gbl_debug_sleep_before_prepare;
196+
static char *gbl_debug_default_string_update = "debug_default_string_update_value";
196197
extern int gbl_wait_for_prepare_seqnum;
197198
extern int gbl_flush_replicant_on_prepare;
198199
extern int gbl_slow_rep_log_get_loop;
@@ -1407,6 +1408,14 @@ int register_tunable(comdb2_tunable *tunable)
14071408
/* Keep tunable names in lower case (to be consistent). */
14081409
tunable_tolower(t->name);
14091410

1411+
// Ensure the initial value for tunables without an update function
1412+
// is heap-allocated so the default update handler can safely free() it.
1413+
if ((tunable->type == TUNABLE_STRING || tunable->type == TUNABLE_RAW) && !tunable->update) {
1414+
if (tunable->var && *(char **)tunable->var) {
1415+
*((char **)tunable->var) = strdup(*(char **)tunable->var);
1416+
}
1417+
}
1418+
14101419
t->descr = tunable->descr;
14111420

14121421
if (tunable->type >= TUNABLE_INVALID) {

db/db_tunables.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ REGISTER_TUNABLE("sleep_before_dispatch", "Sleep before dispatching on master. (
333333
&gbl_debug_sleep_before_dispatch, EXPERIMENTAL | INTERNAL, NULL, NULL, NULL, NULL);
334334
REGISTER_TUNABLE("debug_sleep_before_prepare", "Sleep for 5 seconds before preparing. (Default: off)", TUNABLE_BOOLEAN,
335335
&gbl_debug_sleep_before_prepare, EXPERIMENTAL | INTERNAL, NULL, NULL, NULL, NULL);
336+
REGISTER_TUNABLE("debug_default_string_update", "Test default string update handler. (Default: debug_default_string_update_value)",
337+
TUNABLE_STRING, &gbl_debug_default_string_update, EXPERIMENTAL | INTERNAL, NULL, NULL, NULL, NULL);
336338

337339
REGISTER_TUNABLE("disable_prefault_udp", "Disables 'enable_prefault_udp'", TUNABLE_BOOLEAN, &gbl_prefault_udp,
338340
INVERSE_VALUE | NOARG, NULL, NULL, NULL, NULL);

tests/readearly_string_tunable.test/lrl.options

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/readearly_string_tunable.test/t00.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/readearly_string_tunable.test/t00.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
iam_metrics_namespace comdb2-iam-test
2+
debug_default_string_update comdb2-string-tunable-test
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(value='comdb2-iam-test')
2+
(value='comdb2-string-tunable-test')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Verify that setting a string tunable via LRL does not crash.
2+
SELECT value FROM comdb2_tunables WHERE name = 'iam_metrics_namespace';
3+
PUT TUNABLE mask_internal_tunables 0
4+
SELECT value FROM comdb2_tunables WHERE name = 'debug_default_string_update';

0 commit comments

Comments
 (0)