From 33b7ff387cbc75b5d53d4c42ec6303c8dbd5f656 Mon Sep 17 00:00:00 2001 From: Qu Chen Date: Sun, 3 Jul 2022 23:38:19 -0700 Subject: Unlock cluster config file upon server shutdown. (#10912) Currently in cluster mode, Redis process locks the cluster config file when starting up and holds the lock for the entire lifetime of the process. When the server shuts down, it doesn't explicitly release the lock on the cluster config file. We noticed a problem with restart testing that if you shut down a very large redis-server process (i.e. with several hundred GB of data stored), it takes the OS a while to free the resources and unlock the cluster config file. So if we immediately try to restart the redis server process, it might fail to acquire the lock on the cluster config file and fail to come up. This fix explicitly releases the lock on the cluster config file upon a shutdown rather than relying on the OS to release the lock, which is a cleaner and safer approach to free up resources acquired. --- src/cluster.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/cluster.c') diff --git a/src/cluster.c b/src/cluster.c index 147668a2e..b434bcc02 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -460,8 +460,8 @@ void clusterSaveConfigOrDie(int do_fsync) { } } -/* Lock the cluster config using flock(), and leaks the file descriptor used to - * acquire the lock so that the file will be locked forever. +/* Lock the cluster config using flock(), and retain the file descriptor used to + * acquire the lock so that the file will be locked as long as the process is up. * * This works because we always update nodes.conf with a new version * in-place, reopening the file, and writing to it in place (later adjusting @@ -500,8 +500,8 @@ int clusterLockConfig(char *filename) { close(fd); return C_ERR; } - /* Lock acquired: leak the 'fd' by not closing it, so that we'll retain the - * lock to the file as long as the process exists. + /* Lock acquired: leak the 'fd' by not closing it until shutdown time, so that + * we'll retain the lock to the file as long as the process exists. * * After fork, the child process will get the fd opened by the parent process, * we need save `fd` to `cluster_config_file_lock_fd`, so that in redisFork(), -- cgit v1.2.1