5555#include <sys/utsname.h>
5656#include <locale.h>
5757#include <sys/socket.h>
58+ #include <mcheck.h>
5859
5960/* Our shared "common" objects */
6061
@@ -1525,6 +1526,26 @@ void initServerConfig(void) {
15251526 server .watchdog_period = 0 ;
15261527}
15271528
1529+ void reloadServerCommands () {
1530+ /* release old dict */
1531+ dictRelease (server .commands );
1532+ dictRelease (server .orig_commands );
1533+
1534+ /* re-add command to table */
1535+ server .commands = dictCreate (& commandTableDictType ,NULL );
1536+ server .orig_commands = dictCreate (& commandTableDictType ,NULL );
1537+ populateCommandTable ();
1538+ server .delCommand = lookupCommandByCString ("del" );
1539+ server .multiCommand = lookupCommandByCString ("multi" );
1540+ server .lpushCommand = lookupCommandByCString ("lpush" );
1541+ server .lpopCommand = lookupCommandByCString ("lpop" );
1542+ server .rpopCommand = lookupCommandByCString ("rpop" );
1543+ server .sremCommand = lookupCommandByCString ("srem" );
1544+ server .execCommand = lookupCommandByCString ("exec" );
1545+ server .expireCommand = lookupCommandByCString ("expire" );
1546+ server .pexpireCommand = lookupCommandByCString ("pexpire" );
1547+ }
1548+
15281549extern char * * environ ;
15291550
15301551/* Restart the server, executing the same executable that started this
@@ -3975,6 +3996,7 @@ int serverRun(int argc, char **argv, struct wrapperContext *ctx) {
39753996 serverRestore (& ctx -> server , & ctx -> shared );
39763997 bioRestore (ctx -> bioThreads );
39773998 evictionPoolRestore (ctx -> evictionpool );
3999+ zmalloc_used_memory_restore (ctx -> usedmemory );
39784000 }
39794001
39804002#ifdef REDIS_TEST
@@ -4022,6 +4044,8 @@ int serverRun(int argc, char **argv, struct wrapperContext *ctx) {
40224044 for (j = 0 ; j < argc ; j ++ ) server .exec_argv [j ] = zstrdup (argv [j ]);
40234045 } else {
40244046 moduleReloadModulesSystem ();
4047+ /* command adress may be changed, so reload it */
4048+ reloadServerCommands ();
40254049 }
40264050
40274051
@@ -4041,7 +4065,7 @@ int serverRun(int argc, char **argv, struct wrapperContext *ctx) {
40414065 else if (strstr (argv [0 ],"redis-check-aof" ) != NULL )
40424066 redis_check_aof_main (argc ,argv );
40434067
4044- if (argc >= 2 ) {
4068+ if (! ctx -> reload && argc >= 2 ) {
40454069 j = 1 ; /* First option to parse in argv[] */
40464070 sds options = sdsempty ();
40474071 char * configfile = NULL ;
@@ -4125,15 +4149,14 @@ int serverRun(int argc, char **argv, struct wrapperContext *ctx) {
41254149
41264150 server .supervised = redisIsSupervised (server .supervised_mode );
41274151 int background = server .daemonize && !server .supervised ;
4128- if (background ) daemonize ();
4129-
41304152 if (!ctx -> reload ) {
4153+ if (background ) daemonize ();
41314154 initServer ();
4155+ redisSetProcTitle (argv [0 ]);
41324156 } else {
41334157 reloadServer ();
41344158 }
41354159 if (background || server .pidfile ) createPidFile ();
4136- redisSetProcTitle (argv [0 ]);
41374160 redisAsciiArt ();
41384161 checkTcpBacklogSettings ();
41394162
@@ -4144,7 +4167,7 @@ int serverRun(int argc, char **argv, struct wrapperContext *ctx) {
41444167 linuxMemoryWarnings ();
41454168 #endif
41464169 moduleLoadFromQueue ();
4147- if (ctx -> reload == 0 ) {
4170+ if (! ctx -> reload ) {
41484171 loadDataFromDisk ();
41494172 }
41504173 if (server .cluster_enabled ) {
@@ -4172,10 +4195,18 @@ int serverRun(int argc, char **argv, struct wrapperContext *ctx) {
41724195 aeSetAfterSleepProc (server .el ,afterSleep );
41734196 aeMain (server .el );
41744197
4198+ if (ctx -> reloadTimes == 0 ) {
4199+ mtrace ();
4200+ }
4201+ if (ctx -> reloadTimes == 200 ) {
4202+ muntrace ();
4203+ }
4204+
41754205 /* save server ctx to s */
41764206 serverSave (& ctx -> server , & ctx -> shared );
41774207 bioSave (ctx -> bioThreads );
41784208 evictionPoolSave (& ctx -> evictionpool );
4209+ zmalloc_used_memory_save (& ctx -> usedmemory );
41794210
41804211 return 0 ;
41814212}
0 commit comments