Skip to content

Unlock cluster config file upon server shutdown - #10912

Merged
oranagra merged 1 commit into
redis:unstablefrom
QuChen88:unlock_config_file
Jul 4, 2022
Merged

oranagra merged 1 commit into
redis:unstablefrom
QuChen88:unlock_config_file

Conversation

@QuChen88

@QuChen88 QuChen88 commented Jul 1, 2022 •

Copy link
Copy Markdown
Contributor

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.

@enjoy-binbin enjoy-binbin added the state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten label Jul 1, 2022
@yangbodong22011

Copy link
Copy Markdown
Contributor

Your PR only works when Redis exits normally. But when kill -9 redis-server, finishShutdown will not be called, there is still a problem.

Regarding cluster_config_file_lock_fd, it is to prevent starting multiple redis-cluster-servers with the same nodes.conf, but this is a user misuse problem. I recommend removing cluster_config_file_lock_fd and its flock related code.

@redis/core-team Please share your opinion.

@madolson

madolson commented Jul 1, 2022

Copy link
Copy Markdown
Contributor

@yangbodong22011 to make sure I understand. You are suggesting we remove all of the locking code for nodes.conf?

@QuChen88

QuChen88 commented Jul 1, 2022 •

Copy link
Copy Markdown
Contributor Author

@yangbodong22011 I don't think we should remove cluster_config_file_lock_fd and the lock on nodes.conf file. It was intentionally put in place to prevent multiple redis processes from sharing/using the same cluster config file. This safety measure is still justified in normal operational scenarios. See db06108

Yes this CR only handles the graceful shutdown, which should happen in almost all of the cases (i.e. by sending a shutdown command to Redis, even terminating the process with SIGINT or SIGTERM is handled). Killing the process forcefully from the kernel via kill -9 which sends SIGKILL is not handled today in Redis in general and is not in scope of this change. The reason people do that is usually because redis engine is stuck and can't be shut down gracefully, and I think it is fine to rely on the OS to unlock the cluster config file upon process exit in this rare case.

@madolson

madolson commented Jul 1, 2022

Copy link
Copy Markdown
Contributor

I'm inclined to agree with qu that this is a reasonable improvement.

@madolson madolson added release-notes indication that this issue needs to be mentioned in the release notes 7.0-must-have and removed 7.0-must-have labels Jul 1, 2022

@oranagra oranagra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangbodong22011 if this feature was set in place to protect against misuse, why remove it now?
seems like a reasonable improvement (note that we also explicitly close the listen sockets for exactly the same reason.

@yangbodong22011

yangbodong22011 commented Jul 4, 2022 •

Copy link
Copy Markdown
Contributor

Here are my reasons for removing flock:

  1. does not completely solve the flock problem, such as the case of kill -9.
  2. We just flock nodes.conf and did not do the same for redis.conf.

After reading everyone's replies, I think protection is better than nothing, so I decided to approve this PR.

@oranagra
oranagra merged commit 33b7ff3 into redis:unstable Jul 4, 2022
@QuChen88
QuChen88 deleted the unlock_config_file branch July 4, 2022 18:28
@oranagra oranagra mentioned this pull request Jul 11, 2022
@steffen-moser

Copy link
Copy Markdown
Contributor

Unfortunately, the flock() breaks compilation of redis-7.x on Solaris 11.4 (SRU 49). Shouldn't using fcntl() instead of flock() make the code compatible with more Unix-like operating systems - or would it introduce other compatibility issues?

@oranagra

Copy link
Copy Markdown
Member

@steffen-moser can you submit a PR to fix that?

@steffen-moser

Copy link
Copy Markdown
Contributor

@oranagra - please see #11327

oranagra pushed a commit that referenced this pull request Sep 27, 2022
)

SunOS/Solaris and its relatives don't support the flock() function.
While "redis" has been excluding setting up the lock using flock() on the cluster
configuration file when compiling under Solaris, it was still using flock() in the
unlock call while shutting down. 

This pull request eliminates the flock() call also in the unlocking stage
for Oracle Solaris and its relatives.

Fix compilation regression from #10912
oranagra pushed a commit that referenced this pull request Dec 12, 2022
)

SunOS/Solaris and its relatives don't support the flock() function.
While "redis" has been excluding setting up the lock using flock() on the cluster
configuration file when compiling under Solaris, it was still using flock() in the
unlock call while shutting down.

This pull request eliminates the flock() call also in the unlocking stage
for Oracle Solaris and its relatives.

Fix compilation regression from #10912

(cherry picked from commit 6aab4cb)
madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
…is#11327)

SunOS/Solaris and its relatives don't support the flock() function.
While "redis" has been excluding setting up the lock using flock() on the cluster
configuration file when compiling under Solaris, it was still using flock() in the
unlock call while shutting down. 

This pull request eliminates the flock() call also in the unlocking stage
for Oracle Solaris and its relatives.

Fix compilation regression from redis#10912
enjoy-binbin pushed a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
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.
enjoy-binbin pushed a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
…is#11327)

SunOS/Solaris and its relatives don't support the flock() function.
While "redis" has been excluding setting up the lock using flock() on the cluster
configuration file when compiling under Solaris, it was still using flock() in the
unlock call while shutting down. 

This pull request eliminates the flock() call also in the unlocking stage
for Oracle Solaris and its relatives.

Fix compilation regression from redis#10912
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants