Skip to content

Feature storeretrycount #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions memcached.ini
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ memcached.serializer = "igbinary"
; the default is Off
memcached.use_sasl = Off

; The amount of retries for failed store commands.
; This mechanism allows transparent fail-over to secondary servers when
; set/increment/decrement/setMulti operations fail on the desired server in a multi-server
; environment.
; the default is 2
memcached.store_retry_count = 2
17 changes: 16 additions & 1 deletion php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ typedef unsigned long int uint32_t;
#define MEMC_OPT_PREFIX_KEY -1002
#define MEMC_OPT_SERIALIZER -1003
#define MEMC_OPT_COMPRESSION_TYPE -1004
#define MEMC_OPT_STORE_RETRY_COUNT -1005

/****************************************
Custom result codes
Expand Down Expand Up @@ -202,6 +203,7 @@ typedef struct {
#if HAVE_MEMCACHED_SASL
zend_bool has_sasl_data;
#endif
long store_retry_count;
} *obj;

zend_bool is_persistent;
Expand Down Expand Up @@ -315,6 +317,7 @@ PHP_INI_BEGIN()
#if HAVE_MEMCACHED_SASL
STD_PHP_INI_ENTRY("memcached.use_sasl", "0", PHP_INI_SYSTEM, OnUpdateBool, use_sasl, zend_php_memcached_globals, php_memcached_globals)
#endif
STD_PHP_INI_ENTRY("memcached.store_retry_count", "2", PHP_INI_ALL, OnUpdateLong, store_retry_count, zend_php_memcached_globals, php_memcached_globals)
PHP_INI_END()
/* }}} */

Expand Down Expand Up @@ -465,6 +468,7 @@ static PHP_METHOD(Memcached, __construct)
m_obj->serializer = MEMC_G(serializer);
m_obj->compression_type = MEMC_G(compression_type_real);
m_obj->compression = 1;
m_obj->store_retry_count = MEMC_G(store_retry_count);

i_obj->obj = m_obj;
i_obj->is_pristine = 1;
Expand Down Expand Up @@ -1142,7 +1146,7 @@ PHP_METHOD(Memcached, setMultiByKey)
/* }}} */

#define PHP_MEMC_FAILOVER_RETRY \
if (!by_key && retry < 2) { \
if (!by_key && retry < m_obj->store_retry_count) { \
switch (i_obj->rescode) { \
case MEMCACHED_HOST_LOOKUP_FAILURE: \
case MEMCACHED_CONNECTION_FAILURE: \
Expand Down Expand Up @@ -2278,6 +2282,10 @@ static PHP_METHOD(Memcached, getOption)
RETURN_LONG((long)m_obj->serializer);
break;

case MEMC_OPT_STORE_RETRY_COUNT:
RETURN_LONG((long)m_obj->store_retry_count);
break;

case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
if (memcached_server_count(m_obj->memc) == 0) {
Expand Down Expand Up @@ -2400,6 +2408,11 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML
break;
}

case MEMC_OPT_STORE_RETRY_COUNT:
convert_to_long(value);
m_obj->store_retry_count = Z_LVAL_P(value);
break;

default:
/*
* Assume that it's a libmemcached behavior option.
Expand Down Expand Up @@ -3189,6 +3202,7 @@ static void php_memc_init_globals(zend_php_memcached_globals *php_memcached_glob
#if HAVE_MEMCACHED_SASL
MEMC_G(use_sasl) = 0;
#endif
MEMC_G(store_retry_count) = 2;
}

static void php_memc_destroy_globals(zend_php_memcached_globals *php_memcached_globals_p TSRMLS_DC)
Expand Down Expand Up @@ -3797,6 +3811,7 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
REGISTER_MEMC_CLASS_CONST_LONG(OPT_COMPRESSION_TYPE, MEMC_OPT_COMPRESSION_TYPE);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_PREFIX_KEY, MEMC_OPT_PREFIX_KEY);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_SERIALIZER, MEMC_OPT_SERIALIZER);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_STORE_RETRY_COUNT, MEMC_OPT_STORE_RETRY_COUNT);

/*
* Indicate whether igbinary serializer is available
Expand Down
1 change: 1 addition & 0 deletions php_memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
#if HAVE_MEMCACHED_SASL
bool use_sasl;
#endif
long store_retry_count;
ZEND_END_MODULE_GLOBALS(php_memcached)

PHP_MEMCACHED_API zend_class_entry *php_memc_get_ce(void);
Expand Down