Skip to content

Commit

Permalink
Trigger a save of the cluster configuration file before shutting down
Browse files Browse the repository at this point in the history
The cluster configuration file is the metadata "database" for the
cluster. It is best to trigger a save when shutdown the server, to
avoid inconsistent content that is not refreshed.

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin committed Jul 24, 2024
1 parent f00c8f6 commit 5a9e2d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void clusterInit(void);
void clusterInitLast(void);
void clusterCron(void);
void clusterBeforeSleep(void);
int clusterSaveConfig(int do_fsync);
int verifyClusterConfigWithData(void);

int clusterSendModuleMessageToTarget(const char *target,
Expand Down
7 changes: 6 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -4336,14 +4336,19 @@ int finishShutdown(void) {
/* Close the listening sockets. Apparently this allows faster restarts. */
closeListeningSockets(1);

if (server.cluster_enabled) {
/* The error logs have been logged in the save function if the save fails. */
serverLog(LL_NOTICE, "Saving the cluster configuration file before exiting.");
clusterSaveConfig(1);
}

#if !defined(__sun)
/* Unlock the cluster config file before shutdown */
if (server.cluster_enabled && server.cluster_config_file_lock_fd != -1) {
flock(server.cluster_config_file_lock_fd, LOCK_UN | LOCK_NB);
}
#endif /* __sun */


serverLog(LL_WARNING, "%s is now ready to exit, bye bye...", server.sentinel_mode ? "Sentinel" : "Valkey");
return C_OK;

Expand Down

0 comments on commit 5a9e2d1

Please sign in to comment.