Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichael-grunder <michael.grunder@gmail.com>2019-02-09 21:07:33 +0300
committermichael-grunder <michael.grunder@gmail.com>2019-02-09 21:07:33 +0300
commit2593df150f69f4e956f3c5a2566c3febce661085 (patch)
treee46473c6e0c24e8ac48c4600c2123a0457c80de8 /redis_cluster.c
parent9f0d7bc0a4d3bbf5a539b855a5d1c32abf9f2300 (diff)
parentfa130a4bd46200d799f0659b709c8062c87f692b (diff)
Merge exception fixes into cluster-slot-cache
Diffstat (limited to 'redis_cluster.c')
-rw-r--r--redis_cluster.c104
1 files changed, 32 insertions, 72 deletions
diff --git a/redis_cluster.c b/redis_cluster.c
index f7695f97..0c6b7cb8 100644
--- a/redis_cluster.c
+++ b/redis_cluster.c
@@ -41,10 +41,6 @@ zend_class_entry *redis_cluster_exception_ce;
/* Handlers for RedisCluster */
zend_object_handlers RedisCluster_handlers;
-/* Helper when throwing normal cluster exceptions */
-#define CLUSTER_THROW_EXCEPTION(msg) \
- zend_throw_exception(redis_cluster_exception_ce, msg, 0 TSRMLS_CC);
-
ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_ARG_ARRAY_INFO(0, seeds, 0)
@@ -432,36 +428,22 @@ static int cluster_cache_store(HashTable *ht_seeds, HashTable *nodes TSRMLS_DC)
static int
cluster_validate_args(double timeout, double read_timeout, HashTable *seeds) {
if (timeout < 0L || timeout > INT_MAX) {
- CLUSTER_THROW_EXCEPTION("Invalid timeout");
+ CLUSTER_THROW_EXCEPTION("Invalid timeout", 0);
return FAILURE;
}
if (read_timeout < 0L || read_timeout > INT_MAX) {
- CLUSTER_THROW_EXCEPTION("Invalid read timeout");
+ CLUSTER_THROW_EXCEPTION("Invalid read timeout", 0);
return FAILURE;
}
+ /* Make sure there are some seeds */
if (zend_hash_num_elements(seeds) == 0) {
- CLUSTER_THROW_EXCEPTION("Must pass seeds");
+ CLUSTER_THROW_EXCEPTION("Must pass seeds", 0);
return FAILURE;
}
return SUCCESS;
}
-static int cluster_init_from_seeds(redisCluster *c, HashTable *seeds TSRMLS_DC) {
- int rv1 = cluster_init_seeds(c, seeds);
- int rv2 = cluster_map_keyspace(c TSRMLS_CC);
- if (rv1 == SUCCESS && rv2 == SUCCESS) {
- return SUCCESS;
- } else {
- return FAILURE;
- }
-}
-
-//static int cluster_init_from_cache(redisCluster *c, redisCachedCluster *rcc TSRMLS_DC) {
-// cluster_init_cache(c, rcc);
-// return cluster_map_keyspace(c TSRMLS_CC);
-//}
-
/* Attempt to connect to a Redis cluster provided seeds and timeout options */
static void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
double read_timeout, int persistent, char *auth,
@@ -469,6 +451,7 @@ static void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double time
{
redisCachedCluster *cc;
+ /* TODO: Safe short circuit here */
cluster_validate_args(timeout, read_timeout, ht_seeds);
if (auth && auth_len > 0) {
@@ -486,11 +469,14 @@ static void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double time
/* Attempt to load from cache */
if ((cc = cluster_cache_load(ht_seeds TSRMLS_CC))) {
cluster_init_cache(c, cc);
- } else if (cluster_init_from_seeds(c, ht_seeds) == SUCCESS) {
+ } else if (cluster_init_seeds(c, ht_seeds) == SUCCESS &&
+ cluster_map_keyspace(c TSRMLS_CC) == SUCCESS)
+ {
cluster_cache_store(ht_seeds, c->nodes TSRMLS_CC);
}
}
+
/* Attempt to load a named cluster configured in php.ini */
void redis_cluster_load(redisCluster *c, char *name, int name_len TSRMLS_DC) {
zval z_seeds, z_timeout, z_read_timeout, z_persistent, z_auth, *z_value;
@@ -509,7 +495,7 @@ void redis_cluster_load(redisCluster *c, char *name, int name_len TSRMLS_DC) {
ht_seeds = Z_ARRVAL_P(z_value);
} else {
zval_dtor(&z_seeds);
- zend_throw_exception(redis_cluster_exception_ce, "Couldn't find seeds for cluster", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Couldn't find seeds for cluster", 0);
return;
}
@@ -603,9 +589,7 @@ PHP_METHOD(RedisCluster, __construct) {
// Require a name
if (name_len == 0 && ZEND_NUM_ARGS() < 2) {
- zend_throw_exception(redis_cluster_exception_ce,
- "You must specify a name or pass seeds!",
- 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("You must specify a name or pass seeds!", 0);
}
/* If we've been passed only one argument, the user is attempting to connect
@@ -713,8 +697,7 @@ static int get_key_val_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
kv->key = kv->kbuf;
break;
default:
- zend_throw_exception(redis_cluster_exception_ce,
- "Internal Zend HashTable error", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Internal Zend HashTable error", 0);
return -1;
}
@@ -724,8 +707,7 @@ static int get_key_val_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
// Now grab our value
if ((z_val = zend_hash_get_current_data_ex(ht, ptr)) == NULL) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Internal Zend HashTable error", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Internal Zend HashTable error", 0);
return -1;
}
@@ -744,8 +726,7 @@ static int get_key_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
if ((z_key = zend_hash_get_current_data_ex(ht, ptr)) == NULL) {
// Shouldn't happen, but check anyway
- zend_throw_exception(redis_cluster_exception_ce,
- "Internal Zend HashTable error", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Internal Zend HashTable error", 0);
return -1;
}
@@ -1950,8 +1931,7 @@ static void generic_unsub_cmd(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
if (cluster_send_slot(c, c->subscribed_slot, cmd, cmd_len, TYPE_MULTIBULK
TSRMLS_CC) == FAILURE)
{
- zend_throw_exception(redis_cluster_exception_ce,
- "Failed to UNSUBSCRIBE within our subscribe loop!", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Failed to UNSUBSCRIBE within our subscribe loop!", 0);
RETURN_FALSE;
}
@@ -2150,9 +2130,7 @@ PHP_METHOD(RedisCluster, watch) {
// Add this key to our distribution handler
if (cluster_dist_add_key(c, ht_dist, ZSTR_VAL(zstr), ZSTR_LEN(zstr), NULL) == FAILURE) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Can't issue WATCH command as the keyspace isn't fully mapped",
- 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Can't issue WATCH command as the keyspace isn't fully mapped", 0);
zend_string_release(zstr);
RETURN_FALSE;
}
@@ -2163,8 +2141,7 @@ PHP_METHOD(RedisCluster, watch) {
ZEND_HASH_FOREACH_PTR(ht_dist, dl) {
// Grab the clusterDistList pointer itself
if (dl == NULL) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Internal error in a PHP HashTable", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Internal error in a PHP HashTable", 0);
cluster_dist_free(ht_dist);
efree(z_args);
efree(cmd.c);
@@ -2240,10 +2217,7 @@ PHP_METHOD(RedisCluster, exec) {
if (SLOT_SOCK(c, fi->slot)->mode == MULTI) {
if ( cluster_send_exec(c, fi->slot TSRMLS_CC) < 0) {
cluster_abort_exec(c TSRMLS_CC);
-
- zend_throw_exception(redis_cluster_exception_ce,
- "Error processing EXEC across the cluster",
- 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Error processing EXEC across the cluster", 0);
// Free our queue, reset MULTI state
CLUSTER_FREE_QUEUE(c);
@@ -2361,8 +2335,7 @@ cluster_empty_node_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw,
// Kick off our command
if (cluster_send_slot(c, slot, cmd, cmd_len, reply_type TSRMLS_CC) < 0) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Unable to send command at a specific node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Unable to send command at a specific node", 0);
efree(cmd);
RETURN_FALSE;
}
@@ -2405,8 +2378,7 @@ cluster_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, REDIS_REPLY_TYPE reply
// Kick off our command
if (cluster_send_slot(c, slot, cmd, cmd_len, reply_type TSRMLS_CC) < 0) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Unable to send command at a specific node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Unable to send command at a specific node", 0);
efree(cmd);
RETURN_FALSE;
}
@@ -2470,8 +2442,7 @@ static void cluster_raw_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len)
/* Send it off */
if (cluster_send_slot(c, slot, cmd.c, cmd.len, TYPE_EOF TSRMLS_CC) < 0) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Couldn't send command to node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Couldn't send command to node", 0);
efree(cmd.c);
efree(z_args);
RETURN_FALSE;
@@ -2500,8 +2471,7 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
// Can't be in MULTI mode
if (!CLUSTER_IS_ATOMIC(c)) {
- zend_throw_exception(redis_cluster_exception_ce,
- "SCAN type commands can't be called in MULTI mode!", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("SCAN type commands can't be called in MULTI mode!", 0);
RETURN_FALSE;
}
@@ -2546,8 +2516,7 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
// Send it off
if (cluster_send_command(c, slot, cmd, cmd_len TSRMLS_CC) == FAILURE)
{
- zend_throw_exception(redis_cluster_exception_ce,
- "Couldn't send SCAN command", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Couldn't send SCAN command", 0);
if (key_free) efree(key);
efree(cmd);
RETURN_FALSE;
@@ -2557,8 +2526,7 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
if (cluster_scan_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, type,
&it) == FAILURE)
{
- zend_throw_exception(redis_cluster_exception_ce,
- "Couldn't read SCAN response", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Couldn't read SCAN response", 0);
if (key_free) efree(key);
efree(cmd);
RETURN_FALSE;
@@ -2595,8 +2563,7 @@ PHP_METHOD(RedisCluster, scan) {
/* Can't be in MULTI mode */
if (!CLUSTER_IS_ATOMIC(c)) {
- zend_throw_exception(redis_cluster_exception_ce,
- "SCAN type commands can't be called in MULTI mode", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("SCAN type commands can't be called in MULTI mode", 0);
RETURN_FALSE;
}
@@ -2637,8 +2604,7 @@ PHP_METHOD(RedisCluster, scan) {
// Send it to the node in question
if (cluster_send_command(c, slot, cmd, cmd_len TSRMLS_CC) < 0)
{
- zend_throw_exception(redis_cluster_exception_ce,
- "Couldn't send SCAN to node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Couldn't send SCAN to node", 0);
efree(cmd);
RETURN_FALSE;
}
@@ -2646,8 +2612,7 @@ PHP_METHOD(RedisCluster, scan) {
if (cluster_scan_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, TYPE_SCAN,
&it) == FAILURE || Z_TYPE_P(return_value)!=IS_ARRAY)
{
- zend_throw_exception(redis_cluster_exception_ce,
- "Couldn't process SCAN response from node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Couldn't process SCAN response from node", 0);
efree(cmd);
RETURN_FALSE;
}
@@ -2770,8 +2735,7 @@ PHP_METHOD(RedisCluster, info) {
rtype = CLUSTER_IS_ATOMIC(c) ? TYPE_BULK : TYPE_LINE;
if (cluster_send_slot(c, slot, cmd, cmd_len, rtype TSRMLS_CC) < 0) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Unable to send INFO command to specific node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Unable to send INFO command to specific node", 0);
efree(cmd);
RETURN_FALSE;
}
@@ -2844,8 +2808,7 @@ PHP_METHOD(RedisCluster, client) {
/* Attempt to write our command */
if (cluster_send_slot(c, slot, cmd, cmd_len, rtype TSRMLS_CC) < 0) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Unable to send CLIENT command to specific node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Unable to send CLIENT command to specific node", 0);
efree(cmd);
RETURN_FALSE;
}
@@ -2923,8 +2886,7 @@ PHP_METHOD(RedisCluster, script) {
/* Send it off */
if (cluster_send_slot(c, slot, cmd.c, cmd.len, TYPE_EOF TSRMLS_CC) < 0) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Couldn't send command to node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Couldn't send command to node", 0);
efree(cmd.c);
efree(z_args);
RETURN_FALSE;
@@ -3098,8 +3060,7 @@ PHP_METHOD(RedisCluster, echo) {
/* Send it off */
rtype = CLUSTER_IS_ATOMIC(c) ? TYPE_BULK : TYPE_LINE;
if (cluster_send_slot(c,slot,cmd,cmd_len,rtype TSRMLS_CC) < 0) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Unable to send commnad at the specificed node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Unable to send commnad at the specificed node", 0);
efree(cmd);
RETURN_FALSE;
}
@@ -3152,8 +3113,7 @@ PHP_METHOD(RedisCluster, rawcommand) {
/* Direct the command */
rtype = CLUSTER_IS_ATOMIC(c) ? TYPE_EOF : TYPE_LINE;
if (cluster_send_slot(c,slot,cmd,cmd_len,rtype TSRMLS_CC) < 0) {
- zend_throw_exception(redis_cluster_exception_ce,
- "Unable to send command to the specified node", 0 TSRMLS_CC);
+ CLUSTER_THROW_EXCEPTION("Unable to send command to the specified node", 0);
efree(cmd);
RETURN_FALSE;
}