diff --git a/src/commands.def b/src/commands.def index 791b30d540..db0824fa00 100644 --- a/src/commands.def +++ b/src/commands.def @@ -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} }; diff --git a/src/commands/memory-doctor.json b/src/commands/memory-doctor.json index 7bc0e1e6e2..c0452e6daa 100644 --- a/src/commands/memory-doctor.json +++ b/src/commands/memory-doctor.json @@ -12,6 +12,9 @@ "REQUEST_POLICY:ALL_SHARDS", "RESPONSE_POLICY:SPECIAL" ], + "command_flags": [ + "LOADING" + ], "reply_schema": { "description": "Memory problems report.", "type": "string" diff --git a/src/commands/memory-malloc-stats.json b/src/commands/memory-malloc-stats.json index 5ef6a31c40..af5d439744 100644 --- a/src/commands/memory-malloc-stats.json +++ b/src/commands/memory-malloc-stats.json @@ -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." diff --git a/src/commands/memory-purge.json b/src/commands/memory-purge.json index 77ed61dc5b..aea3e2d24a 100644 --- a/src/commands/memory-purge.json +++ b/src/commands/memory-purge.json @@ -11,6 +11,9 @@ "REQUEST_POLICY:ALL_SHARDS", "RESPONSE_POLICY:ALL_SUCCEEDED" ], + "command_flags": [ + "LOADING" + ], "reply_schema": { "const": "OK" } diff --git a/src/commands/memory-stats.json b/src/commands/memory-stats.json index e32f5a291b..6ea6999079 100644 --- a/src/commands/memory-stats.json +++ b/src/commands/memory-stats.json @@ -12,6 +12,9 @@ "REQUEST_POLICY:ALL_SHARDS", "RESPONSE_POLICY:SPECIAL" ], + "command_flags": [ + "LOADING" + ], "reply_schema": { "description": "Memory usage details.", "type": "object", diff --git a/tests/unit/loading.tcl b/tests/unit/loading.tcl new file mode 100644 index 0000000000..9dc251cf71 --- /dev/null +++ b/tests/unit/loading.tcl @@ -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 *}} [$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 + } +}