Skip to content

Commit

Permalink
Introduce a new server configuration, enable-debug-assert,
Browse files Browse the repository at this point in the history
which allows selectively enabling or disabling, at runtime,
expensive or risky assertions used primarily for debugging
and testing.

Signed-off-by: Ping Xie <[email protected]>
  • Loading branch information
PingXie committed May 31, 2024
1 parent f927565 commit 9dbad2f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -3191,7 +3191,9 @@ standardConfig static_configs[] = {
createTimeTConfig("repl-backlog-ttl", NULL, MODIFIABLE_CONFIG, 0, LONG_MAX, server.repl_backlog_time_limit, 60 * 60, INTEGER_CONFIG, NULL, NULL), /* Default: 1 hour */
createOffTConfig("auto-aof-rewrite-min-size", NULL, MODIFIABLE_CONFIG, 0, LLONG_MAX, server.aof_rewrite_min_size, 64 * 1024 * 1024, MEMORY_CONFIG, NULL, NULL),
createOffTConfig("loading-process-events-interval-bytes", NULL, MODIFIABLE_CONFIG | HIDDEN_CONFIG, 1024, INT_MAX, server.loading_process_events_interval_bytes, 1024 * 1024 * 2, INTEGER_CONFIG, NULL, NULL),
createBoolConfig("enable-debug-assert", NULL, MODIFIABLE_CONFIG, server.enable_debug_assert, 0, NULL, NULL),

/* Tls configs */
createIntConfig("tls-port", NULL, MODIFIABLE_CONFIG, 0, 65535, server.tls_port, 0, INTEGER_CONFIG, NULL, applyTLSPort), /* TCP port. */
createIntConfig("tls-session-cache-size", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.tls_ctx_config.session_cache_size, 20 * 1024, INTEGER_CONFIG, NULL, applyTlsCfg),
createIntConfig("tls-session-cache-timeout", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.tls_ctx_config.session_cache_timeout, 300, INTEGER_CONFIG, NULL, applyTlsCfg),
Expand Down
13 changes: 6 additions & 7 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,13 +701,11 @@ typedef enum {
#define serverAssert(_e) (likely(_e) ? (void)0 : (_serverAssert(#_e, __FILE__, __LINE__), valkey_unreachable()))
#define serverPanic(...) _serverPanic(__FILE__, __LINE__, __VA_ARGS__), valkey_unreachable()

/* The following macros provide assertions that are only executed during test builds and should be used to add
* assertions that are too computationally expensive or dangerous to run during normal operations. */
#ifdef DEBUG_ASSERTIONS
#define debugServerAssertWithInfo(...) serverAssertWithInfo(__VA_ARGS__)
#else
#define debugServerAssertWithInfo(...)
#endif
/* The following macro provides a conditional assertion that is only executed
* when the server config 'enable-debug-assert' is true. This is useful for adding
* assertions that are too computationally expensive or risky to run in normal
* operation, but are valuable for debugging or testing. */
#define debugServerAssertWithInfo(...) (server.enable_debug_assert ? serverAssertWithInfo(__VA_ARGS__) : (void)0)

/* latency histogram per command init settings */
#define LATENCY_HISTOGRAM_MIN_VALUE 1L /* >= 1 nanosec */
Expand Down Expand Up @@ -1680,6 +1678,7 @@ struct valkeyServer {
int enable_protected_configs; /* Enable the modification of protected configs, see PROTECTED_ACTION_ALLOWED_* */
int enable_debug_cmd; /* Enable DEBUG commands, see PROTECTED_ACTION_ALLOWED_* */
int enable_module_cmd; /* Enable MODULE commands, see PROTECTED_ACTION_ALLOWED_* */
int enable_debug_assert; /* Enable debug asserts */

/* RDB / AOF loading information */
volatile sig_atomic_t loading; /* We are loading data from disk if true */
Expand Down
2 changes: 2 additions & 0 deletions tests/assets/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ propagation-error-behavior panic

# Make sure shutdown doesn't fail if there's an initial AOFRW
shutdown-on-sigterm force

enable-debug-assert yes
1 change: 1 addition & 0 deletions valkey.conf
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ protected-mode yes
# enable-protected-configs no
# enable-debug-command no
# enable-module-command no
# enable-debug-assert no

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified the server will not listen on a TCP socket.
Expand Down

0 comments on commit 9dbad2f

Please sign in to comment.