Skip to content

5 short clusterables - #1782

Closed
mattsta wants to merge 4 commits into
redis:unstablefrom
mattsta:5-short-clusterables
Closed

mattsta wants to merge 4 commits into
redis:unstablefrom
mattsta:5-short-clusterables

Conversation

@mattsta

@mattsta mattsta commented May 28, 2014

Copy link
Copy Markdown
Contributor

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:

  • Use the local bind IP (if available) instead of reporting :0 for the myself IP
  • Provide a CLUSTER SLOTS command with Redis-formatted output of the relevant parts of CLUSTER NODES
  • Add COMMANDS so clients can discover key position information for each command, allowing better client-side key to slot mapping.
  • PUBLISH to __cluster__:state when 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.

@badboy

badboy commented May 29, 2014

Copy link
Copy Markdown
Contributor

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.

@nrk

nrk commented Jun 1, 2014

Copy link
Copy Markdown

+1000 on CLUSTER SLOTS, it would be great to have it because parsing the output of CLUSTER NODES ends up being clumsy and prone to errors.

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 COMMANDS instead of the server version returned by INFO to selectively mark tests as skipped when certain commands are not yet available on it (one example is HyperLogLog-related commands added in 2.8.9: currently TravisCI still runs an older version of 2.8).

@antirez

antirez commented Jun 9, 2014

Copy link
Copy Markdown
Contributor

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?

  • If we lack a connection with a valid node, we use the socket of the client asking for the list of nodes itself, in order to obtain our IP address.
  • Once we see the first connection with the first known node, we cache the value and use it, however:
  • We never save this into nodes.conf so that after a restart the node will re-obtain its address, making it working when we node the instance to a different machine.

Alternatives:

  • Set the node address at cluster creation time, and update it only when other nodes detect we changed address?
  • Or, use what I described above, but actually write it into nodes.conf, at restart, flag the node as CHECK_ADDR, and at the first connection with a new node, verify and re-set if needed the right address.

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.
Like:

  • COMMANDS INFO foo bar zap zip: Current output but for the specified commands. Returns NULL as array element when a command does not exist, so we can avoid a COMMAND EXISTS subcommand.
  • COMMANDS: Current output.

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. movablekeys or alike.

CLUSTER SLOTS

This sounds like a very good idea, however I would change the output.
The goal of the command is to provide a simple to use map between slots and addresses to contact. To output flags makes it more complex to handle for the client, for instance myself is often before master, which is instead what the user needs to know. Also to know that a master is down or noaddr, should not be a concern of clients.

This is a format that may serve better the purpose of the command:

1) 1) <start>
   2) <end>
   3) 1) <master-ip>
      2) <master-port>
   4) 1) <slave-0-ip>
      2) <slave-0-port>
   5) 1) <slave-1-ip>
      2) <slave-1-port>
   ...

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 FAIL state. Basically in the format I proposed, the "primary key" is the range of slots, not the instance serving it.

PUBLISH cluster state

Given 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?

@antirez

antirez commented Jun 9, 2014

Copy link
Copy Markdown
Contributor

Yet another proposal for the IP thing, which is a simpler and more obvious way modification of the previous proposals:

  • Cluster nodes start not knowing their address, as today.
  • We have a function that given a socket, extracts the local address and sets it. The function accept flags and can behave in two ways: modify myself->ip if the IP in the socket is different, or, modify myself->ip only if the current ip is set to 0. Let's call the two flags UPDATE_IF_NEEDED and UPDATE_IF_DIFFERENT.

Now, that's how the function is called:

  • If we receive a CLUSTER NODES command (or upcoming CLUSTER SLOTS proposed by Matt), we call this function with UPDATE_IF_UNSET. This means that the address is set only if we don't know our address, which as we'll see does not happen almost never.
  • In the context of the first packet we receive in every new connection, when we assign link->node to a known node (so, this is only about known nodes, not random connections), we also call the function with UPDATE_IF_DIFFERENT.

In the context of this proposal, we always store the address in nodes.conf if it changes, since we always try to update the address on new connections, so we are sure we are able to update our address if it changes.

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.

@mattsta

mattsta commented Jun 9, 2014

Copy link
Copy Markdown
Contributor Author

(just one quick feedback for now; lots of reading to do here!)

We have a function that given a socket, extracts the local address and sets it.

If the interface has multiple IP addresses we can't always pick the correct one automatically (if you use ifconfig or ip to define address aliases, the socket API doesn't know which alias to return).

We've also seen deployments where people set bind to an IP not on the machine (going through a VIP or load balancer). The default Redis behavior of using the Redis-discovered interface address breaks for these situations (see: https://github.com/antirez/redis/issues/1667).

As much as we like Redis to auto-decide things when it can, if a user specifies a bind address, they probably need exactly the address they wrote.

Now, the problem is when people don't specify a specific address and just use bind * instead. I think that's a great situation to use the automatic IP discovery. If the user isn't happy with automatic IP discovery results, they can specify an explicit bind IP (which should probably actually bind source IPs and not just use the bind address for listen :))

If any of the IP discovery is confused by Redis accepting up to 16 multiple listening addresses, we could always add a listen directive for multiple addresses while only allowing one core bind address.

The node marked as myself in nodes.conf can always overwrite its nodes.conf persisted IP on startup (if using bind address) or on first cluster connect for self-discovery.

@antirez

antirez commented Jun 9, 2014

Copy link
Copy Markdown
Contributor

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.

@antirez

antirez commented Jun 9, 2014

Copy link
Copy Markdown
Contributor

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 myself if contacted for error by an external node, that uses a different address.

@mattsta

mattsta commented Jun 9, 2014

Copy link
Copy Markdown
Contributor Author

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 bind 192.168.10.10 as the requested source address even though that address doesn't exist on their machine.

@mattsta

mattsta commented Jun 12, 2014

Copy link
Copy Markdown
Contributor Author

Update: Cluster Slots

The suggested output improvement to CLUSTER SLOTS is a great idea. I didn't take that approach originally because it requires 2x the code to generate based on how we store the node state internally. :)

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) 7007

The 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 fail state is not added to the output. That's the only state limitation. We still include nodes in fail?. Note: the IP/Port output is reporting the local IP/Port using the bind addr. If you don't configure a bind addr, the node you run CLUSTER SLOTS on will show up as the default empty IP with a port of 0. Improvements to local IP determination are being considered above too.

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 slot range -> list(). The master dict should only store one IP/Port pair for each slot key, but this isn't enforced. If more than one master IP/Port pair shows up, we only use the first one and any others are ignored (we recently saw a bug where multiple masters occurred). The replica dict stores IP/Port for every replica of each slot range.

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.

@mattsta

mattsta commented Jun 13, 2014

Copy link
Copy Markdown
Contributor Author

Update Again: Cluster Slots

Pushed 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: CLUSTER SLOTS now internally only generates one result dict and guarantees the master node is in the first position by putting a flag in the IP string (we strip it out for the final result). If a range of slots has no master, the first result after slots will be a null reply, but you can still see your replicas after. If, for any reason, you have more than one master for a slot range, additional masters are listed immediately following the first master, but they are just IP/Port pairs, so they will look like the regular replicas you expect.

CLUSTER SLOTS is only 16% slower than CLUSTER NODES. nodes benchmarks at 3200 requests per second (0.31ms per command) while slots benchmarks at 2700 requests per second (0.37ms per command) on my laptop.

@antirez

antirez commented Jun 16, 2014

Copy link
Copy Markdown
Contributor

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.

@mattsta

mattsta commented Jun 16, 2014

Copy link
Copy Markdown
Contributor Author

are you using the fact that master nodes have an array of references slave objects?

Oops, I never noticed that! I was using the pattern from nodes.conf output and just iterating over every top-level node (which required creating the secondary slot->node dict).

I'll update the command to use the data we already have instead of re-creating everything.

Thanks!

@antirez

antirez commented Jun 16, 2014

Copy link
Copy Markdown
Contributor

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.
@mattsta

mattsta commented Jun 16, 2014

Copy link
Copy Markdown
Contributor Author

Update Again Again: Cluster Slots

Now CLUSTER SLOTS uses the correct master->slave list and the implementation is down to 71 lines.

Also, CLUSTER SLOTS is now almost twice as fast as CLUSTER NODES. slots benchmarks at 6000 requests per second while nodes benchmarks around 3200 requests per second.

Update: Commands

Agree on the changes. Working on it.

Update: Cluster publish state changes

Imagine: 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.

mattsta added 3 commits June 16, 2014 23:31
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.
@mattsta

mattsta commented Jun 17, 2014

Copy link
Copy Markdown
Contributor Author

Update: Commands

Added COMMANDS INFO [cmd1 cmd2 ... cmdN] support. Also added movablekey to flags instead of returning an additional element.

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)

@antirez

antirez commented Jun 25, 2014

Copy link
Copy Markdown
Contributor

Hello Matt, thanks for the updates, we are near to merge at this point. Things that should be changed:

  1. I'm going to implement the myself ip/port disconvery thing as we agreed in this thread so that all our listings will almost always have the right info filled for the myself node. CLUSTER NODES at this point is a "plug-and-play" mechanism so it now seems especially odd that the client has to fill stuff manually.
  2. CLUSTER SLOTS should not skip master nodes that are failing, it's part of the map regardless of the state. We can contact a slave, all the masters are down, and yet we should get a correct map. What it should skip instead is slaves that are down since this are likely to just cause a latency issue if the client is interested in scaling reads.
  3. COMMANDS command, great thanks, still didn't read the code of this but the output looks ok. This will be backported into 2.8 as well.
  4. I still don't think the publish mechanism is worth it. The client using a 100 nodes cluster will get a failure only when a cluster topology change happened, so it requires a failover that is a relatively speaking rare event. What is the price to pay after this rare event? A round-trip to call CLUSTER NODES. And this is a reliable mechanism. Adding push messages for changes means to add an unreliable mechanism that adds complexity client side.

So basically, today I'm going to implement the address discovery for myself, and merge both CLUTER SLOTS (with the changes proposed as an additional commit), and COMMANDS command.

A final proposal about change of names for both the commands:

  • CLUSTER SLOTS is fine but I would be slightly more happy with CLUSTER MAP because it is an higher level name, and it is simpler to actually understand what it does. Btw it's your call, I'm fine with both.
  • COMMANDS command, I would strongly avoid the plural and call it COMMAND like the symmetric INFO command of Tcl.

antirez added a commit that referenced this pull request Jun 25, 2014
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.
@antirez

antirez commented Jun 25, 2014

Copy link
Copy Markdown
Contributor

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.

@antirez

antirez commented Jun 25, 2014

Copy link
Copy Markdown
Contributor

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 repliedRangeCount with num_masters.

@antirez

antirez commented Jun 25, 2014

Copy link
Copy Markdown
Contributor

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.

@mattsta

mattsta commented Jun 25, 2014

Copy link
Copy Markdown
Contributor Author

almost always have the right info filled for the myself node. ... "plug-and-play" mechanism so it now seems especially odd that the client has to fill stuff manually.

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?

CLUSTER SLOTS should not skip master nodes that are failing, it's part of the map regardless of the state. We can contact a slave,

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?

CLUSTER SLOTS is fine but I would be slightly more happy with CLUSTER MAP

Naming is completely arbitrary. Feel free to change anything to sound better :)

COMMANDS command, I would strongly avoid the plural and call it COMMAND

Yup, sounds great. I wrote all of these on a flight and didn't spend long thinking up names. :octocat:

I'm doing minor style changes just to conform with the Redis code base style.

Thanks! Sorry for the mix-up.

@antirez

antirez commented Jun 25, 2014

Copy link
Copy Markdown
Contributor

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?

10.10.10.10, but we may handle this case in a separated way. Consider that we can't fix it even with the bind address trick, the server does not know at all a 4.4.4.4 address exists at all. So we have to add something like a new option that will write the address in the nodes.conf configuration making it not updatable if not with a special CLUSTER subcommand.

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.

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?

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 -CLUSTERDOWN error.

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.

Naming is completely arbitrary. Feel free to change anything to sound better :)

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!

@mattsta

mattsta commented Jun 25, 2014

Copy link
Copy Markdown
Contributor Author

Consider that we can't fix it even with the bind address trick, the server does not know at all a 4.4.4.4 address exists at all.

Yup, you're right the server knows nothing about the public non-local IP, but the user does (somehow).

What happens: the user sets bind 4.4.4.4 10.10.10.10, then configures Linux to "bind to non-local IPs" so it can still start when the IP doesn't exist. Using the "if bind_addr[0]" trick, the 4.4.4.4 will be used for generating the node map. (See: https://github.com/antirez/redis/issues/1667 — people can also hack it with iptables dnat).

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.

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.

There are no working replicas with failed master

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).

@Plasma

Plasma commented Jun 26, 2014

Copy link
Copy Markdown

"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."

@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.

antirez added a commit that referenced this pull request Jun 26, 2014
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.
@antirez

antirez commented Jun 26, 2014

Copy link
Copy Markdown
Contributor

@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.

@antirez

antirez commented Jun 27, 2014

Copy link
Copy Markdown
Contributor

COMMAND merged as well! I modified a few things in later commits and added COMMAND COUNT subcommand. Thanks. We can probably close this pull request even if it triggered other things like:

  • Ability to configure the cluster to remain available for the served hash slots even if there is no full coverage.
  • Ability to configure a cluster node address explicitly.

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.

@antirez antirez closed this Jun 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants