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

Trigger a save of the cluster configuration file before shutting down #822

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void clusterInitLast(void);
void clusterCron(void);
void clusterBeforeSleep(void);
int verifyClusterConfigWithData(void);
void clusterHandleServerShutdown(void);

int clusterSendModuleMessageToTarget(const char *target,
uint64_t module_id,
Expand Down Expand Up @@ -83,7 +84,6 @@ int getNodeDefaultClientPort(clusterNode *n);
clusterNode *getMyClusterNode(void);
int getClusterSize(void);
int getMyShardSlotCount(void);
int handleDebugClusterCommand(client *c);
enjoy-binbin marked this conversation as resolved.
Show resolved Hide resolved
int clusterNodePending(clusterNode *node);
int clusterNodeIsPrimary(clusterNode *n);
char **getClusterNodesList(size_t *numnodes);
Expand Down
14 changes: 14 additions & 0 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,20 @@ void clusterInitLast(void) {
}
}

/* Called when a cluster node calls SHUTDOWN. */
enjoy-binbin marked this conversation as resolved.
Show resolved Hide resolved
void clusterHandleServerShutdown(void) {
/* 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, see clusterLockConfig. */
if (server.cluster_config_file_lock_fd != -1) {
flock(server.cluster_config_file_lock_fd, LOCK_UN | LOCK_NB);
}
#endif /* __sun */
}
enjoy-binbin marked this conversation as resolved.
Show resolved Hide resolved

/* Reset a node performing a soft or hard reset:
*
* 1) All other nodes are forgotten.
Expand Down
11 changes: 3 additions & 8 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -4333,17 +4333,12 @@ int finishShutdown(void) {
* send them pending writes. */
flushReplicasOutputBuffers();

/* Handle cluster-related matters when shutdown. */
if (server.cluster_enabled) clusterHandleServerShutdown();

/* Close the listening sockets. Apparently this allows faster restarts. */
closeListeningSockets(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
Loading