Skip to content

Commit 6fb645a

Browse files
author
Mikko Koppanen
committed
Merge pull request #96 from poison/feature-storeretrycount
Feature storeretrycount
2 parents eaa92d4 + 0280bee commit 6fb645a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

memcached.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ memcached.serializer = "igbinary"
109109
; the default is Off
110110
memcached.use_sasl = Off
111111

112+
; The amount of retries for failed store commands.
113+
; This mechanism allows transparent fail-over to secondary servers when
114+
; set/increment/decrement/setMulti operations fail on the desired server in a multi-server
115+
; environment.
116+
; the default is 2
117+
memcached.store_retry_count = 2

php_memcached.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ typedef unsigned long int uint32_t;
111111
#define MEMC_OPT_PREFIX_KEY -1002
112112
#define MEMC_OPT_SERIALIZER -1003
113113
#define MEMC_OPT_COMPRESSION_TYPE -1004
114+
#define MEMC_OPT_STORE_RETRY_COUNT -1005
114115

115116
/****************************************
116117
Custom result codes
@@ -202,6 +203,7 @@ typedef struct {
202203
#if HAVE_MEMCACHED_SASL
203204
zend_bool has_sasl_data;
204205
#endif
206+
long store_retry_count;
205207
} *obj;
206208

207209
zend_bool is_persistent;
@@ -315,6 +317,7 @@ PHP_INI_BEGIN()
315317
#if HAVE_MEMCACHED_SASL
316318
STD_PHP_INI_ENTRY("memcached.use_sasl", "0", PHP_INI_SYSTEM, OnUpdateBool, use_sasl, zend_php_memcached_globals, php_memcached_globals)
317319
#endif
320+
STD_PHP_INI_ENTRY("memcached.store_retry_count", "2", PHP_INI_ALL, OnUpdateLong, store_retry_count, zend_php_memcached_globals, php_memcached_globals)
318321
PHP_INI_END()
319322
/* }}} */
320323

@@ -465,6 +468,7 @@ static PHP_METHOD(Memcached, __construct)
465468
m_obj->serializer = MEMC_G(serializer);
466469
m_obj->compression_type = MEMC_G(compression_type_real);
467470
m_obj->compression = 1;
471+
m_obj->store_retry_count = MEMC_G(store_retry_count);
468472

469473
i_obj->obj = m_obj;
470474
i_obj->is_pristine = 1;
@@ -1142,7 +1146,7 @@ PHP_METHOD(Memcached, setMultiByKey)
11421146
/* }}} */
11431147

11441148
#define PHP_MEMC_FAILOVER_RETRY \
1145-
if (!by_key && retry < 2) { \
1149+
if (!by_key && retry < m_obj->store_retry_count) { \
11461150
switch (i_obj->rescode) { \
11471151
case MEMCACHED_HOST_LOOKUP_FAILURE: \
11481152
case MEMCACHED_CONNECTION_FAILURE: \
@@ -2278,6 +2282,10 @@ static PHP_METHOD(Memcached, getOption)
22782282
RETURN_LONG((long)m_obj->serializer);
22792283
break;
22802284

2285+
case MEMC_OPT_STORE_RETRY_COUNT:
2286+
RETURN_LONG((long)m_obj->store_retry_count);
2287+
break;
2288+
22812289
case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
22822290
case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
22832291
if (memcached_server_count(m_obj->memc) == 0) {
@@ -2400,6 +2408,11 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML
24002408
break;
24012409
}
24022410

2411+
case MEMC_OPT_STORE_RETRY_COUNT:
2412+
convert_to_long(value);
2413+
m_obj->store_retry_count = Z_LVAL_P(value);
2414+
break;
2415+
24032416
default:
24042417
/*
24052418
* Assume that it's a libmemcached behavior option.
@@ -3189,6 +3202,7 @@ static void php_memc_init_globals(zend_php_memcached_globals *php_memcached_glob
31893202
#if HAVE_MEMCACHED_SASL
31903203
MEMC_G(use_sasl) = 0;
31913204
#endif
3205+
MEMC_G(store_retry_count) = 2;
31923206
}
31933207

31943208
static void php_memc_destroy_globals(zend_php_memcached_globals *php_memcached_globals_p TSRMLS_DC)
@@ -3797,6 +3811,7 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
37973811
REGISTER_MEMC_CLASS_CONST_LONG(OPT_COMPRESSION_TYPE, MEMC_OPT_COMPRESSION_TYPE);
37983812
REGISTER_MEMC_CLASS_CONST_LONG(OPT_PREFIX_KEY, MEMC_OPT_PREFIX_KEY);
37993813
REGISTER_MEMC_CLASS_CONST_LONG(OPT_SERIALIZER, MEMC_OPT_SERIALIZER);
3814+
REGISTER_MEMC_CLASS_CONST_LONG(OPT_STORE_RETRY_COUNT, MEMC_OPT_STORE_RETRY_COUNT);
38003815

38013816
/*
38023817
* Indicate whether igbinary serializer is available

php_memcached.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
9393
#if HAVE_MEMCACHED_SASL
9494
bool use_sasl;
9595
#endif
96+
long store_retry_count;
9697
ZEND_END_MODULE_GLOBALS(php_memcached)
9798

9899
PHP_MEMCACHED_API zend_class_entry *php_memc_get_ce(void);

0 commit comments

Comments
 (0)