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

Allow MEMORY MALLOC-STATS and MEMORY PURGE during loading phase #1317

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands.def
Original file line number Diff line number Diff line change
Expand Up @@ -7320,8 +7320,8 @@ struct COMMAND_ARG MEMORY_USAGE_Args[] = {
struct COMMAND_STRUCT MEMORY_Subcommands[] = {
{MAKE_CMD("doctor","Outputs a memory problems report.","O(1)","4.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,MEMORY_DOCTOR_History,0,MEMORY_DOCTOR_Tips,3,memoryCommand,2,0,0,MEMORY_DOCTOR_Keyspecs,0,NULL,0)},
{MAKE_CMD("help","Returns helpful text about the different subcommands.","O(1)","4.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,MEMORY_HELP_History,0,MEMORY_HELP_Tips,0,memoryCommand,2,CMD_LOADING|CMD_STALE,0,MEMORY_HELP_Keyspecs,0,NULL,0)},
{MAKE_CMD("malloc-stats","Returns the allocator statistics.","Depends on how much memory is allocated, could be slow","4.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,MEMORY_MALLOC_STATS_History,0,MEMORY_MALLOC_STATS_Tips,3,memoryCommand,2,0,0,MEMORY_MALLOC_STATS_Keyspecs,0,NULL,0)},
{MAKE_CMD("purge","Asks the allocator to release memory.","Depends on how much memory is allocated, could be slow","4.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,MEMORY_PURGE_History,0,MEMORY_PURGE_Tips,2,memoryCommand,2,0,0,MEMORY_PURGE_Keyspecs,0,NULL,0)},
{MAKE_CMD("malloc-stats","Returns the allocator statistics.","Depends on how much memory is allocated, could be slow","4.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,MEMORY_MALLOC_STATS_History,0,MEMORY_MALLOC_STATS_Tips,3,memoryCommand,2,CMD_LOADING,0,MEMORY_MALLOC_STATS_Keyspecs,0,NULL,0)},
{MAKE_CMD("purge","Asks the allocator to release memory.","Depends on how much memory is allocated, could be slow","4.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,MEMORY_PURGE_History,0,MEMORY_PURGE_Tips,2,memoryCommand,2,CMD_LOADING,0,MEMORY_PURGE_Keyspecs,0,NULL,0)},
{MAKE_CMD("stats","Returns details about memory usage.","O(1)","4.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,MEMORY_STATS_History,0,MEMORY_STATS_Tips,3,memoryCommand,2,0,0,MEMORY_STATS_Keyspecs,0,NULL,0)},
{MAKE_CMD("usage","Estimates the memory usage of a key.","O(N) where N is the number of samples.","4.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,MEMORY_USAGE_History,0,MEMORY_USAGE_Tips,0,memoryCommand,-3,CMD_READONLY,0,MEMORY_USAGE_Keyspecs,1,NULL,2),.args=MEMORY_USAGE_Args},
{0}
Expand Down
3 changes: 3 additions & 0 deletions src/commands/memory-malloc-stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"REQUEST_POLICY:ALL_SHARDS",
"RESPONSE_POLICY:SPECIAL"
],
"command_flags": [
"LOADING"
],
"reply_schema": {
"type": "string",
"description": "The memory allocator's internal statistics report."
Expand Down
3 changes: 3 additions & 0 deletions src/commands/memory-purge.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"REQUEST_POLICY:ALL_SHARDS",
"RESPONSE_POLICY:ALL_SUCCEEDED"
],
"command_flags": [
"LOADING"
],
"reply_schema": {
"const": "OK"
}
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/introspection.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,49 @@ test {config during loading} {
}
} {} {external:skip}

test {MEMORY commands during loading} {
start_server [list overrides [list key-load-delay 50 loading-process-events-interval-bytes 1024]] {
# Set up some initial data
r debug populate 100000 key 1000

# Save and restart
r save
restart_server 0 false false

# At this point, keys are loaded one at time, busy looping 50usec
# between each. Further, other events are processed every 1024 bytes
# of RDB. We're sending all our commands deferred, so they have a
# chance to be processed all at once between loading two keys.

set rd [valkey_deferring_client]

# Allowed during loading
$rd memory help
$rd memory malloc-stats
$rd memory purge

# Disallowed during loading (because directly dependent on the dataset)
$rd memory doctor
$rd memory stats
$rd memory usage key:1

# memory help
assert_match {{MEMORY <subcommand> *}} [$rd read]
# memory malloc-stats
assert_match {*alloc*} [$rd read]
# memory purge
assert_match OK [$rd read]
# memory doctor
assert_error {*LOADING*} {$rd read}
# memory stats
assert_error {*LOADING*} {$rd read}
# memory usage key:1
assert_error {*LOADING*} {$rd read}

$rd close
}
} {} {external:skip}

test {CONFIG REWRITE handles rename-command properly} {
start_server {tags {"introspection"} overrides {rename-command {flushdb badger}}} {
assert_error {ERR unknown command*} {r flushdb}
Expand Down
Loading