summaryrefslogtreecommitdiff
path: root/src/cluster.c
diff options
context:
space:
mode:
authorQu Chen <QuChen88@users.noreply.github.com>2022-07-03 23:38:19 -0700
committerGitHub <noreply@github.com>2022-07-04 09:38:19 +0300
commit33b7ff387cbc75b5d53d4c42ec6303c8dbd5f656 (patch)
treea0a29420e881464f097da98da00353f6b6f8b0e5 /src/cluster.c
parent0ab885a685101522017021ac2d2b46b42d268f26 (diff)
downloadredis-33b7ff387cbc75b5d53d4c42ec6303c8dbd5f656.tar.gz
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.
Diffstat (limited to 'src/cluster.c')
-rw-r--r--src/cluster.c8
1 files changed, 4 insertions, 4 deletions
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(),