Skip to content

Commit

Permalink
Memory inspection commands no longer return loading errors
Browse files Browse the repository at this point in the history
  • Loading branch information
knggk committed Nov 18, 2024
1 parent aa2dd3e commit 6b826d4
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/commands.def
Original file line number Diff line number Diff line change
Expand Up @@ -7289,11 +7289,11 @@ struct COMMAND_ARG MEMORY_USAGE_Args[] = {

/* MEMORY command table */
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("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,CMD_LOADING,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("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("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,CMD_LOADING,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-doctor.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": {
"description": "Memory problems report.",
"type": "string"
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
3 changes: 3 additions & 0 deletions src/commands/memory-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": {
"description": "Memory usage details.",
"type": "object",
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/loading.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
start_server [list overrides [list "key-load-delay" 50 loading-process-events-interval-bytes 1024]] {
test "Memory inspection commands no longer return loading errors" {
# 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]

# The ping at the end should still return LOADING error
$rd memory doctor
$rd memory malloc-stats
$rd memory stats
$rd memory help
# Memory usage on key while loading is not well defined -> keep error
$rd memory usage key:1
$rd memory purge
$rd ping

assert_match {Hi Sam, *} [$rd read]
assert_match {*} [$rd read]
assert_match {peak.allocated *} [$rd read]
assert_match {{MEMORY <subcommand> *}} [$rd read]
# Memory usage keeps getting rejected in loading because the dataset is not visible
assert_error {*LOADING*} {$rd read}
assert_match OK [$rd read]
assert_error {*LOADING*} {$rd read}

$rd close
}
}

0 comments on commit 6b826d4

Please sign in to comment.