Repository navigation
Conversation
|
Ha. Of course I meant "config set." Ignore unintentional dumbs. Looks like we don't allow reading or setting of cluster-config-file: 127.0.0.1:37446> config get cluster-config-file
(empty list or set)
127.0.0.1:37446> config set cluster-config-file poo.conf
(error) ERR Unsupported CONFIG parameter: cluster-config-file |
Prevent multiple Redis Cluster processes from using the same
node configuration file, since if that happens, your entire
cluster becomes unusable (and it confuses people who are
just getting started by giving them no feedback as to the failure).
This commit changes the functionality of reading and saving
cluster configs. Now we keep the cluster config file open
as long as the redis-server process is alive. If we close
the config file, we invite a race condition where another
node could start without our lock in place.
Instead of closing the configuration file after reading it, we
retain the FILE* globally. Also, we don't close the file after
writing anymore.
Updates:
- Retain FILE* in server struct
- Centralized file opening and file closing for cluster-config-file so
we can open the file without parsing it.
- Improved(?)/added specific error messages
- Started using REDIS_OK/REDIS_ERR in more places.
Example output on failure to obtain lock:
matt@ununoctium:~/repos/redis/src% ./redis-server --cluster-enabled yes --port 3333
[67969] 27 Mar 12:26:46.153 # Unable to start Redis Cluster. Your cluster-config-file "nodes.conf" is being used by another instance. Please provide a unique cluster-config-file.
|
[Refactored this and rebased it against current unstable to resolve a few merge conflicts.] |
|
Thanks matt, looks like to use About where the lock is obtained, more or less it is probably the same thing, the interesting stuff here is that no two instances can run with the same file, as long as there is no race condition possible. nodes.conf will hardly be something we can reconfigure at runtime, but, if we'll change idea, we'll just have to handle the logic by creating a new file in the dest path, lock it, unlock the old one, switch config. No need currently. |
|
Question: why are you retaining the file descriptor? It looks like there is a simpler way to obtain the same effect, that is just open the file, lock it, and leak the file descriptor (never close it again, ever). This way we'll always take our lock to the file, whatever we do in the next calls, and we are free to open/close the file an infinite number of times. |
|
p.s. I'm not sure what I suggested work after we rewrite the file, but it should in theory since the way we rewrite it we don't actually unlink / create it again, but merely truncate to zero length. Btw I'm investigating using fcntl() locks instead that have a less surprising semantics across operating systems apparently... |
|
Ok, that's the idea, and works great -> https://gist.github.com/antirez/11255064 if you run the test you'll notice that if you delete the file with rm /tmp/foo.txt, two processes will be able to lock the file at the same time, which is expected since they are two different files even if they have the same path (the first file will exist as long as one process still has a file descriptor about it). Sounds like very acceptable with Redis, since we never unlink(2) the nodes.conf file but we just rewrite it in place. I'm implementing the above give that's just a handful lines of code. |
|
Great change! The approach of "leak a file descriptor, but in a good way" didn't enter my mind :) Most of my version was dealing with saving the same FILE* throughout the server's lifetime. Your way is much easier. This will hopefully stop our weekly bug report of "cluster doesn't work -> oh, it's a nodes.conf conflict." |
|
Hello Matt, I implemented this approach here -> db06108 Thanks, |
|
The use of flock causes portability problems on solaris. |
|
Two different possibilities to incorporate the use of fnctl: https://gist.github.com/badboy/e24ffe49c77d833f1996 |
Neat! Though, isn't the main advantage of using We could just name it |
|
That's what I got from that article as well, but I didn't test it (yet). I can do so and would implement the redis_flock method then. |
|
After writing a small sample application and then porting it into a If you re-read perkin's post:
Redis frequently opens and closes the provided Our best shot: Keep the |
you're quite right! Just removing our flock calls for Solaris should be good enough. |
This is a first attempt at fixing the ongoing problem of people
launching multiple Redis Cluster instances in the same directory
with default options (which makes all instances use the same
"nodes.conf" which breaks their cluster).
This commit uses a
flockapproach to the problem. Anothervalid solution would be to use an external lock file. Another
valid pattern would be to obtain the lock in
clusterInitinstead of where we read/create the config in
clusterLoadConfig.Do we allow runtime moving of cluster-config-file? If so,
this commit doesn't handle that case yet. Actually, I just
checked, and the 'set' command doesn't work at all in
a cluster because: