diff options
author | michael-grunder <michael.grunder@gmail.com> | 2014-12-02 08:06:31 +0300 |
---|---|---|
committer | michael-grunder <michael.grunder@gmail.com> | 2015-05-06 01:05:30 +0300 |
commit | 48e6e67a8286ac2aab95132763bc78af508b9e90 (patch) | |
tree | 31bd21f87dc95e80ad57666ae035eb5f05152d7c /cluster_library.h | |
parent | d804342a6f8258aa25147eeacbd4e3b22fa4faa6 (diff) |
Initial commit of formalized "redirection" timeout logic
When phpredis is communicating with a cluster, there are two
different kinds of timeout events.
The first, is your standard read or write timeout where the socket is
blocked either because of network issues, or because Redis is taking
longer than the timeout to complete the request.
The second is unique to cluster. Because Redis Cluster attempts to
automatically failover (in the case of replicas), phpredis cluster
will attempt to get data from a node where it thinks the key would
live, and upon a failure to connect, try a different node (at random).
This is because Redis could be resharding the connection and may point
the client to a new (now good node). However, if it's not yet detected
a failure, it will just bounce us back to the prior node (which could
be actually down or have just sputtered due to various issues).
So in this case, phpredis uses a second timeout mechanism where we keep
track (in milleseconds) when we entered the query/response loop. Once
we've been unsuccessful up to this timeout, phpredis will abort with
a different (catchable) exception.
TODO: It may be a good idea to implement some small delay, so we don't
hit the cluster with lots of requests over and over until the cluster
comes back.
Diffstat (limited to 'cluster_library.h')
-rw-r--r-- | cluster_library.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/cluster_library.h b/cluster_library.h index 98ee305c..162b0d30 100644 --- a/cluster_library.h +++ b/cluster_library.h @@ -178,10 +178,13 @@ typedef struct redisCluster { /* Object reference for Zend */ zend_object std; - /* Timeout and read timeout */ + /* Timeout and read timeout (for normal operations) */ double timeout; double read_timeout; + /* How long in milliseconds should we wait when being bounced around */ + long waitms; + /* Hash table of seed host/ports */ HashTable *seeds; @@ -214,9 +217,6 @@ typedef struct redisCluster { /* One RedisSock* struct for serialization and prefix information */ RedisSock *flags; - /* Cluster distribution mode (speed, vs. maintaining order of execution) */ - short dist_mode; - /* The first line of our last reply, not including our reply type byte * or the trailing \r\n */ char line_reply[1024]; @@ -330,6 +330,9 @@ void cluster_multi_fini(clusterMultiCmd *mc); unsigned short cluster_hash_key_zval(zval *key); unsigned short cluster_hash_key(const char *key, int len); +/* Get the current time in miliseconds */ +long long mstime(void); + PHPAPI short cluster_send_command(redisCluster *c, short slot, const char *cmd, int cmd_len TSRMLS_DC); |