Repository navigation
5 short clusterables - #1782
5 short clusterables#1782mattsta wants to merge 4 commits into
Conversation
|
I especially like the COMMANDS command. In try.redis I have some command-arguments-parsing to properly namespace things as needed (as redis-namespace doesn't handle everything, especially new commands). This could be easily used to get the correct answer when not in the code already. |
|
+1000 on I also like the idea of having the ability to inspect at runtime which commands are supported (and their signature) by a Redis instance. A practical use in my case: when I enable integration tests for Predis against a running Redis server, I could rely on the output of |
|
Hello Matt, this is a great list of additions! Thank you for your work. A few of this I already considered adoption in the past but never ended doing it for lack of time or inability to find a totally convincing design. Others are new. Feedbacks split into sections follow: Show IP in nodes list.In theory, this is a good idea, but in practice, I don't like that there are times when the behavior is as it is today, so basically, a client will sometimes not work, or will need to anyway implement the :0 case as today. So there is no neat improvement here. What we can do to fix that?
Alternatives:
The second alternative does not look bad at all too. COMMANDS command.This is great, but I think that a command subcommand style approach will work better for us.
The idea is that we can extend this command later with more subcommands. About the returl value, I think that it is a good idea to change the format you propose in a tiny way: when keys are not at predictable positions, just add a flag instead of adding an additional field. CLUSTER SLOTSThis sounds like a very good idea, however I would change the output. This is a format that may serve better the purpose of the command: So the output is guaranteed to start with the master ip/port, and continues with all the slaves available for the same range which are not in PUBLISH cluster stateGiven that clients are guaranteed to get an error when they have a wrong map, what's the gain of implementing clients with an open connection to the Pub/Sub channel? |
|
Yet another proposal for the IP thing, which is a simpler and more obvious way modification of the previous proposals:
Now, that's how the function is called:
In the context of this proposal, we always store the address in Note also that it is very unlikely that we need to set the address when the function is called with UPDATE_IF_UNSET, because after the cluster is created and joined, we set the address, and is unlikely that a client interacts with the node before the cluster is joined. However if this happens, we do what appears to be the sanest thing we can do. The only edge case is when a client asks for CLUSTER NODES in a cluster node which is yet not joined, and does this via UNIX sockets. In this case, we'll reply with an error. This is the first time in the context of this problem that I have a solution that sounds convincing to me. Feedbacks welcomed. |
|
(just one quick feedback for now; lots of reading to do here!)
If the interface has multiple IP addresses we can't always pick the correct one automatically (if you use We've also seen deployments where people set As much as we like Redis to auto-decide things when it can, if a user specifies a Now, the problem is when people don't specify a specific address and just use If any of the IP discovery is confused by Redis accepting up to 16 multiple listening addresses, we could always add a The node marked as |
|
Hey @mattsta, isn't this the opposit problem? If we create an outgoing connection, it is true that it may be bound to a different interface, but the other nodes will connect to use with the IP which is known across the cluster, so getsockname() should always report the right info here. |
|
I'm not sure if I was clear. I mean: Node A has 5 interfaces. However when the cluster is created, we used a single address. So node B, C, D, when connecting to A, will connect to this specific IP address. Since we extract the IP always from incoming connections, the IP should always be right, that is, the one we are "known" in the cluster to have. Note that the reason why we update the IP only when we receive the first packet is exactly to only update the address using sockets created by nodes that are known to us, or that presented to use with a MEET packet. So we don't risk putting a wrong address into |
|
Good point! If we have an inbound connection it should work for most cases. I was thinking of zero-connection discovery at startup just from the interface. But, this does assume the IP address on the interface is the IP address exposed throughout the cluster. If someone has eth0 with 10.10.10.10, but they are going through a load balancer or floating VIP that proxies 10.10.10.10<->192.168.10.10, Redis would be unable to discover the cluster should advertise on the load balancer address. In this case, they would explicitly |
Update: Cluster SlotsThe suggested output improvement to I've got a working implemention of the better format: 127.0.0.1:7001> cluster nodes
46c85d942a3cbaec3c82f0fbf925b3e70d08d07f 127.0.0.1:7006 slave 0e0189466595adcfb19388f9ec3864c5bbe1e1b1 0 1402546395015 7 connected
c23620122b9c9ad817de1ab67411475e3251d150 127.0.0.1:7004 slave 2f42e7b5427638850a413b9901a51164f952f91e 0 1402546391990 5 connected
0e0189466595adcfb19388f9ec3864c5bbe1e1b1 127.0.0.1:7002 master - 0 1402546394008 3 connected 8192-12287
dbef1a0642d251b5f1f37737f2d9a6877c2bd4f4 127.0.0.1:7007 slave 8d767fe2fe4ad881a9a75f5394719ccbc925e819 0 1402546390984 8 connected
1a1162458a66415fb801e121401bd6f923ba7e8b 127.0.0.1:7001 myself,master - 0 0 2 connected 4096-8191
b98c0d695a1222a59d8a4d4c2b37e949598b202d 127.0.0.1:7005 slave 1a1162458a66415fb801e121401bd6f923ba7e8b 0 1402546393000 6 connected
8d767fe2fe4ad881a9a75f5394719ccbc925e819 127.0.0.1:7003 master - 0 1402546388464 4 connected 12288-16383
2f42e7b5427638850a413b9901a51164f952f91e 127.0.0.1:7000 master - 0 1402546388967 1 connected 0-4095
127.0.0.1:7001>
127.0.0.1:7001>
127.0.0.1:7001> cluster slots
1) 1) (integer) 4096
2) (integer) 8191
3) 1) "127.0.0.1"
2) (integer) 7001
4) 1) "127.0.0.1"
2) (integer) 7005
2) 1) (integer) 8192
2) (integer) 12287
3) 1) "127.0.0.1"
2) (integer) 7002
4) 1) "127.0.0.1"
2) (integer) 7006
3) 1) (integer) 0
2) (integer) 4095
3) 1) "127.0.0.1"
2) (integer) 7000
4) 1) "127.0.0.1"
2) (integer) 7004
4) 1) (integer) 12288
2) (integer) 16383
3) 1) "127.0.0.1"
2) (integer) 7003
4) 1) "127.0.0.1"
2) (integer) 7007The first node returned under each slot pair (element 3 in each nested reply) is guaranteed to be a master. If there is no current master for a slot range, the entire slot doesn't show up in the output even if replicas are active for that slot. The no-master-no-slot scenario is currently a limitation of my approach to generating output; it would be nice if we could output a null master entry and still list replicas. Any node in In order to guarantee the first IP/Port pair is a master, I'm generating two slot to node mapping dicts when iterating over all the cluster nodes. Each dict stores If a slot has no range, the single slot number is listed for both start and end. The code is still a bit messy, so it's not posted yet. I'll clean it up and push it to this branch in a day or two. |
Update Again: Cluster SlotsPushed new implementation of CLUSTER SLOTS to this PR. The output format is the same as the example above. The original implementation was 76 lines. The new implementation is 169 lines. 😦 Changes from last update:
|
|
Hello @mattsta, sorry for the delay, I plan to review within 48h, however, long shot: are you using the fact that master nodes have an array of references slave objects? You should be able to just iterate skilling slaves, and when you find a master, output it and iterate over the slaves. So no dictionary creation should be needed. |
Oops, I never noticed that! I was using the pattern from I'll update the command to use the data we already have instead of re-creating everything. Thanks! |
|
Thanks Matt, I had the feeling you were not aware of the list of slaves since it is used only rarely in the cluster.c code (however it is very handy to have slaves as an array... especially for replicas migration and other cod paths, and now for CLUSTER SLOTS). |
Previously, the node you ran CLUSTER NODES on always reported itself as IP:Port = ":0" in the node output. The client requesting the current node map would have to parse "myself" from the flags and replcae the IP:Port with the IP:Port of the instance used to retrieve CLUSTER NODES. It seemed a bit convoluted. If the user sets a bind address in redis.conf, we can use that for the IP of this instance. If the user doesn't set a bind address, we fall back to the original ":0" behavior.
Update Again Again: Cluster SlotsNow Also, Update: CommandsAgree on the changes. Working on it. Update: Cluster publish state changesImagine: a cluster of 100 nodes. A client for this cluster will always have a map of slots->nodes so it can connect to correct nodes and run commands. The client doesn't stay connected to all 100 nodes, so if a node goes down (or changes slot responsibility) between slot->node map downloads, the client can only detect changes by encountering an actual failure. If the client can subscribe to a live-update stream about node state changes (nodes failing over, masters switching slot responsibility), the client can proactively update its local node map. Maybe the client stays connected to a random subset of nodes. Or, they could subscribe to one node and if the connection dies, force a node map refresh. The simplest case for live updates is just to send a blanket "SOMETHING CHANGED!" alert so the client can re-download the node map. |
Clients should be able to listen to any instance and get updates about the state of the cluster. At a minimum, the clients should be immediately notified when they need to refresh cluster state due to promotions/failovers. This commit implements that minimum. In the future it would be nice to PUBLISH more granular detail about: - ranges of slots changing ownership - new instances added/removed - instance state changes (fail?, fail, ...) Those additions would be a subset of the blunt hammer approach of "one notification for all state changes." Clients will probably have a common refreshClusterState() that is idempotent for nodes with no changes, so updating the entire state shouldn't be a huge burden (updating individual state like slot ownership would be more efficient, but also requires adding more special cases instead of just refreshing the world in the same manner you use during basic initialization anyway). For updates, you should SUBSCRIBE to _every_ node in your cluster. You will receive multiple updates for every event, but clearly you can't subscribe to just one instance. If that one instance goes down, you get no updates! Every event is tagged with the current cluster epoch, so keep a record of the last cluster epoch you acted on. When other nodes repeat the state change notification for the same epoch you can just ignore them.
CLUSTER SLOTS returns a Redis-formatted mapping from
slot ranges to IP/Port pairs serving that slot range.
The outer return elements group return values by slot ranges.
The first two entires in each result are the min and max slots for the range.
The third entry in each result is guaranteed to be either
an IP/Port of the master for that slot range - OR - null
if that slot range, for some reason, has no master
The 4th and higher entries in each result are replica instances
for the slot range.
Output comparison:
127.0.0.1:7001> cluster nodes
f853501ec8ae1618df0e0f0e86fd7abcfca36207 127.0.0.1:7001 myself,master - 0 0 2 connected 4096-8191
5a2caa782042187277647661ffc5da739b3e0805 127.0.0.1:7005 slave f853501ec8ae1618df0e0f0e86fd7abcfca36207 0 1402622415859 6 connected
6c70b49813e2ffc9dd4b8ec1e108276566fcf59f 127.0.0.1:7007 slave 26f4729ca0a5a992822667fc16b5220b13368f32 0 1402622415357 8 connected
2bd5a0e3bb7afb2b56a2120d3fef2f2e4333de1d 127.0.0.1:7006 slave 32adf4b8474fdc938189dba00dc8ed60ce635b0f 0 1402622419373 7 connected
5a9450e8279df36ff8e6bb1c139ce4d5268d1390 127.0.0.1:7000 master - 0 1402622418872 1 connected 0-4095
32adf4b8474fdc938189dba00dc8ed60ce635b0f 127.0.0.1:7002 master - 0 1402622419874 3 connected 8192-12287
5db7d05c245267afdfe48c83e7de899348d2bdb6 127.0.0.1:7004 slave 5a9450e8279df36ff8e6bb1c139ce4d5268d1390 0 1402622417867 5 connected
26f4729ca0a5a992822667fc16b5220b13368f32 127.0.0.1:7003 master - 0 1402622420877 4 connected 12288-16383
127.0.0.1:7001> cluster slots
1) 1) (integer) 0
2) (integer) 4095
3) 1) "127.0.0.1"
2) (integer) 7000
4) 1) "127.0.0.1"
2) (integer) 7004
2) 1) (integer) 12288
2) (integer) 16383
3) 1) "127.0.0.1"
2) (integer) 7003
4) 1) "127.0.0.1"
2) (integer) 7007
3) 1) (integer) 4096
2) (integer) 8191
3) 1) "127.0.0.1"
2) (integer) 7001
4) 1) "127.0.0.1"
2) (integer) 7005
4) 1) (integer) 8192
2) (integer) 12287
3) 1) "127.0.0.1"
2) (integer) 7002
4) 1) "127.0.0.1"
2) (integer) 7006
COMMANDS returns a nested multibulk reply for each
command in the command table. The reply for each
command contains:
- command name
- arity
- array of command flags
- start key position
- end key position
- key offset step
- optional: if the keys are not deterministic and
Redis uses an internal key evaluation function,
the 6th field appears and is defined as a status
reply of: REQUIRES ARGUMENT PARSING
Cluster clients need to know where the keys are in each
command to implement proper routing to cluster nodes.
Redis commands can have multiple keys, keys at offset steps, or other
issues where you can't always assume the first element after
the command name is the cluster routing key.
Using the information exposed by COMMANDS, client implementations
can have live, accurate key extraction details for all commands.
Also implements COMMANDS INFO [commands...] to return only a
specific set of commands instead of all 160+ commands live in Redis.
Update: CommandsAdded Sample output: 127.0.0.1:7001> commands info eval zinterstore echo howdy migrate telephoto
1) 1) "eval"
2) (integer) -3
3) 1) noscript
2) movablekeys
4) (integer) 0
5) (integer) 0
6) (integer) 0
2) 1) "zinterstore"
2) (integer) -4
3) 1) write
2) denyoom
3) movablekeys
4) (integer) 0
5) (integer) 0
6) (integer) 0
3) 1) "echo"
2) (integer) 2
3) 1) readonly
4) (integer) 0
5) (integer) 0
6) (integer) 0
4) (nil)
5) 1) "migrate"
2) (integer) -6
3) 1) write
2) admin
4) (integer) 0
5) (integer) 0
6) (integer) 0
6) (nil) |
|
Hello Matt, thanks for the updates, we are near to merge at this point. Things that should be changed:
So basically, today I'm going to implement the address discovery for A final proposal about change of names for both the commands:
|
Instead of having an hardcoded IP address in the node configuration, we autodiscover it via MEET messages for automatic update when the node is restarted with a different IP address. This mechanism was discussed in the context of PR #1782.
|
IP autodiscovery implemented. After thinking more about it, I discarded the idea to extract the address from the client if we have no address since it is ok to return an empty address if the cluster was yet not joined. Once a cluster is correctly created, there is no longer the possibility for a node to return a blank address for myself, which seems entirely acceptable. |
|
CLUSTER SLOTS merged, modifying it a bit as per the comments above. I'm doing minor style changes just to conform with the Redis code base style. Just a quick note about that, while we use cammelCase for function names, local var names are preferred to be lowercase, separated by underscores, and as minimal as possible as long they are understandable, so I'm for example replacing |
|
We got CLUSTER SLOTS! Just merged. Thanks, this really feels like a good idea, together the myself address stuff simplifies client implementations in an interesting way. Next is COMMANDS, reviewing this one. p.s. we need to document CLUSTER SLOT in order to close this issue, or we can open a new one to remember. |
The almost is where we run into user problems (the whole "we're running on EC2 with a VIP in front of the server" problem). If the server has IP 10.10.10.10 but the instance is only usable through public proxy IP 4.4.4.4, which IP will show up in CLUSTER NODES?
Good point, but if we aren't including flags with SLOTS/MAP, how do clients discover dead nodes? Just try, wait for a failure, then try a replica? Though, can we actually ever have a failed master with working replicas? Wouldn't a replica be promoted with a failed master almost immediately?
Naming is completely arbitrary. Feel free to change anything to sound better :)
Yup, sounds great. I wrote all of these on a flight and didn't spend long thinking up names.
Thanks! Sorry for the mix-up. |
10.10.10.10, but we may handle this case in a separated way. Consider that we can't fix it even with the At this point, when you create a cluster, you may want to use --sticky-ip-addresses or something like that as a sub-command of create. This will make Redis Cluster a lot less smart when you move a node to a different IP address, since this will require manual fixing, but at the same time will allow people to run cluster in such a setup. That sounds like a viable solution but we may want to think about it a bit more.
CLUSTER SLOTS as I see it was never intended to perform failure detection, it is just a quick way to map slots with instances. If a master is down, the cluster is down, so once the client obtained the map, as soon as it tries to reach any instance, it will get a There are no working replicas with failed master btw, as soon as the failure is propagated, replicas will get informed and eventually stop accepting reads (and other masters, writes). This is basically a courtesy of Redis Cluster, and is a very strong opinion (of mine) about how a distributed version of Redis should work. What I mean is that, in theory, 90% of the cluster may be up, but 10% of hash slots are not covered, and we stop accepting writes eventually for all the hash slots. I believe 99% of our users want this, but not all. I bet we'll end adding an option to keep the cluster up even when a subset of nodes are not covered.
Finally ended merging it as CLUSTER SLOTS since I was not entirely sure with MAP as well, so in doubt, I picked the original name. Thanks! |
Yup, you're right the server knows nothing about the public non-local IP, but the user does (somehow). What happens: the user sets
That could be a great fix too (and for Sentinel too). The basic problem is the 'bind' directive is actually 'listen' and we end up guessing where the source 'bind' address should actually be (which works fine for most users, but makes Sentinel/Cluster unusable for people doing strange things). [Or, have one 'server-ip' option and allow multiple 'listen' options. 3.0 would be a great time to make a big config change to fix how things work. Removing 'bind' option would also stop accidental breakage when upgrading.] I think the safest way is: If user information is provided, use it directly. Else, use automatic guessing if no user-specified IP is given.
Great point. If an instance is listed as a master, it will always be reachable or the entire cluster will be down. There's no intermediate step where a master is down and a replica isn't ready to be promoted yet (I just wasn't sure about the state transitions between pfail, fail, and promoting a replica). |
@antirez I'd (personally) prefer the cluster to remain online and just report errors for inaccessible slots, working in a degraded state. For example, if I have a "large" cluster and one of my ten primaries fails; this should only impact 1/10th of my customers, assuming I shard keys by Customer Id for example. Plus, as the cluster size increases the chance of overall failure increases. Cheers. |
Instead of having an hardcoded IP address in the node configuration, we autodiscover it via MEET messages for automatic update when the node is restarted with a different IP address. This mechanism was discussed in the context of PR #1782.
|
@Plasma yes this is a very reasonable idea... will be introduced for sure in the next weeks. It's also a trivial code change since it is to stop when some master is not available if an added condition not something inherent in Redis Cluster. |
|
I need some additional thinking on the above two so for now not acting, but I'm putting those two in the TODO for the next beta for re-evaluation. Thanks. |
Yesterday I wrote a quick note about adding cluster support to clients, but it raised some interesting issues.
Here's an attempt at fixing some cluster implementation difficulties.
Four new things:
:0for themyselfIPCLUSTER SLOTScommand with Redis-formatted output of the relevant parts ofCLUSTER NODESCOMMANDSso clients can discover key position information for each command, allowing better client-side key to slot mapping.PUBLISHto__cluster__:statewhen the cluster state changes so clients can automatically re-fetch their node map without waiting for timeouts or failures. Channel name was chosen arbitrarily. Open to suggestions for proper naming.For more details, see each individual commit message/essay.