Skip to content

Commit

Permalink
Fix the shm handling and destructor and change the documentation to m…
Browse files Browse the repository at this point in the history
…atch the code
  • Loading branch information
jboone100 committed Sep 28, 2016
1 parent 639703c commit 4fb530e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 48 deletions.
8 changes: 4 additions & 4 deletions doc/aerospike_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ The following configuration options in php.ini
| aerospike.udf.lua_system_path | /opt/aerospike/lua |
| aerospike.udf.lua_user_path | /opt/aerospike/usr-lua |
| aerospike.shm.use | false |
| aerospike.shm.key | 0xA5000000 |
| aerospike.shm.max_nodes | 16 |
| aerospike.shm.max_namespaces | 8 |
| aerospike.shm.takeover_threshold_sec | 30 |
| aerospike.shm.shm_key | 0xA5000000 |
| aerospike.shm.shm_max_nodes | 16 |
| aerospike.shm.shm_max_namespaces | 8 |
| aerospike.shm.shm_takeover_threshold_sec | 30 |
| aerospike.use_batch_direct | 0 |
| aerospike.compression_threshold | 0 |
| aerospike.max_threads | 300 |
Expand Down
8 changes: 4 additions & 4 deletions src/aerospike/aerospike.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ static void shm_key_hashtable_dtor(
{
TSRMLS_FETCH();
DEBUG_PHP_EXT_DEBUG("In shared memory key pesrsittent list destruction function");
struct set_get_data *shm_key_ptr =
struct set_get_data *shm_key_ptr;
#if PHP_VERSION_ID < 70000
((zend_rsrc_list_entry *)
shm_key_ptr = ((zend_rsrc_list_entry *)hashtable_element)->ptr;
#else
Z_RES_P(
shm_key_ptr = (struct set_get_data *)hashtable_element->value.obj;
#endif
hashtable_element)->ptr;

if (shm_key_ptr) {
pefree(shm_key_ptr, 1);
}
Expand Down
44 changes: 24 additions & 20 deletions src/aerospike/aerospike_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ set_shm_key_from_alias_hash_or_generate(as_config* conf,
zend_rsrc_list_entry *le, new_shm_entry;
zval* rsrc_result = NULL;
#else
zend_resource *le, new_shm_entry;
zval *le, new_shm_entry;
zval rsrc_result;
#endif
as_status status = AEROSPIKE_OK;
Expand Down Expand Up @@ -301,17 +301,18 @@ set_shm_key_from_alias_hash_or_generate(as_config* conf,
shm_key_ptr->key = conf->shm_key;
#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID < 70000)
ZEND_REGISTER_RESOURCE(rsrc_result, shm_key_ptr, 1);
#else
ZVAL_RES(&rsrc_result, zend_register_resource(shm_key_ptr, 1));
#endif
new_shm_entry.ptr = shm_key_ptr;
new_shm_entry.type = 1;
#else
ZVAL_PTR(&new_shm_entry, shm_key_ptr);
#endif

#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID < 70000)
zend_hash_add(shm_key_list, alias_to_search, strlen(alias_to_search),
(void *) &new_shm_entry, sizeof(zend_rsrc_list_entry*), NULL);
(void *) &new_shm_entry, sizeof(zend_rsrc_list_entry*), NULL);
#else
zend_hash_add_new_ptr(shm_key_list, \
zend_string_init(alias_to_search, strlen(alias_to_search), 0), (void *) &new_shm_entry);
zend_hash_add(shm_key_list,
zend_string_init(alias_to_search, strlen(alias_to_search), 0), &new_shm_entry);
#endif
pthread_rwlock_unlock(&AEROSPIKE_G(aerospike_mutex));
goto exit;
Expand All @@ -320,13 +321,17 @@ set_shm_key_from_alias_hash_or_generate(as_config* conf,
#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID < 70000)
if (AEROSPIKE_ZEND_HASH_FIND(shm_key_list, alias_to_search,
strlen(alias_to_search), (void **) &le) == SUCCESS) {
#else
if (NULL != (le = (zend_resource *) AEROSPIKE_ZEND_HASH_FIND(shm_key_list,
alias_to_search, strlen(alias_to_search), (void **) &le))) {
#endif
if ((le->ptr) != NULL) {
conf->shm_key = ((shared_memory_key *)(le->ptr))->key;
}
#else
if (NULL != (le = AEROSPIKE_ZEND_HASH_FIND(shm_key_list,
alias_to_search, strlen(alias_to_search), (void **) &le))) {
if ((le->value.obj) != NULL) {
conf->shm_key = ((shared_memory_key *)(le->value.obj))->key;
}
#endif

} else {
if (!(is_unique_shm_key(conf->shm_key, shm_key_list TSRMLS_CC))) {
while (true) {
Expand All @@ -345,19 +350,16 @@ set_shm_key_from_alias_hash_or_generate(as_config* conf,

#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID < 70000)
ZEND_REGISTER_RESOURCE(rsrc_result, shm_key_ptr, 1);
#else
ZVAL_RES(&rsrc_result, zend_register_resource(shm_key_ptr, 1));
#endif

new_shm_entry.ptr = shm_key_ptr;
new_shm_entry.type = 1;
#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID < 70000)
zend_hash_add(shm_key_list, alias_to_search, strlen(alias_to_search),
(void *) &new_shm_entry, sizeof(zend_rsrc_list_entry*), NULL);
(void *) &new_shm_entry, sizeof(zend_rsrc_list_entry*), NULL);
#else
zend_hash_add_new_ptr(shm_key_list, \
zend_string_init(alias_to_search, strlen(alias_to_search), 0), (void *) &new_shm_entry);
ZVAL_PTR(&new_shm_entry, shm_key_ptr);
zend_hash_add(shm_key_list,
zend_string_init(alias_to_search, strlen(alias_to_search), 0), &new_shm_entry);
#endif

}
pthread_rwlock_unlock(&AEROSPIKE_G(aerospike_mutex));
if (alias_to_search) {
Expand Down Expand Up @@ -496,11 +498,13 @@ aerospike_helper_object_from_alias_hash(Aerospike_object* as_object_p,
#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID < 70000)
zend_hash_add(persistent_list, alias_to_hash,
strlen(alias_to_hash), (void *) &new_le, sizeof(zend_rsrc_list_entry), NULL);
((aerospike_ref *) new_le.ptr)->ref_hosts_entry++;
#else
zend_hash_add(persistent_list, zend_string_init(alias_to_hash, strlen(alias_to_hash), 0),
&new_le);
#endif
((aerospike_ref *) new_le.value.obj)->ref_hosts_entry++;
#endif

pthread_rwlock_unlock(&AEROSPIKE_G(aerospike_mutex));
efree(alias_to_hash);
alias_to_hash = NULL;
Expand Down
50 changes: 30 additions & 20 deletions src/aerospike/aerospike_transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -2755,18 +2755,19 @@ aerospike_transform_set_shm_in_config(HashTable* ht_shm, void* as_config_p TSRML
goto exit;
}
#else
ZEND_HASH_FOREACH_VAL(ht_shm, options_value) {
ZEND_HASH_FOREACH_KEY_VAL(ht_shm, options_index, options_key_z, options_value) {
ZEND_HASH_FOREACH_KEY_VAL(ht_shm, options_index, options_key_z, data) {
if (!options_key_z) {
status = AEROSPIKE_ERR_PARAM;
DEBUG_PHP_EXT_DEBUG("Unable to set shared memory parameters");
goto exit;
}
options_key = options_key_z->val;
} ZEND_HASH_FOREACH_END();
options_key = (int8_t *)options_key_z->val;
#endif
if (strcmp((const char *) options_key, PHP_AS_KEY_DEFINE_FOR_SHM_KEY) == 0) {
if (AEROSPIKE_ZEND_HASH_GET_CURRENT_DATA_EX(ht_shm, (void**) &data, &options_pointer) == SUCCESS) {
#if PHP_VERSION_ID < 70000
if (AEROSPIKE_ZEND_HASH_GET_CURRENT_DATA_EX(ht_shm, (void**) &data, &options_pointer) == SUCCESS)
#endif
{
if (AEROSPIKE_Z_TYPE_P(data) != IS_LONG) {
status = AEROSPIKE_ERR_PARAM;
DEBUG_PHP_EXT_DEBUG("Unable to set shared memory key");
Expand All @@ -2776,7 +2777,10 @@ aerospike_transform_set_shm_in_config(HashTable* ht_shm, void* as_config_p TSRML
AEROSPIKE_Z_LVAL_P(data);
}
} else if (strcmp((const char *) options_key, PHP_AS_KEY_DEFINE_FOR_SHM_MAX_NODES) == 0) {
if (AEROSPIKE_ZEND_HASH_GET_CURRENT_DATA_EX(ht_shm, (void**) &data, &options_pointer) == SUCCESS) {
#if PHP_VERSION_ID < 70000
if (AEROSPIKE_ZEND_HASH_GET_CURRENT_DATA_EX(ht_shm, (void**) &data, &options_pointer) == SUCCESS)
#endif
{
if (AEROSPIKE_Z_TYPE_P(data) != IS_LONG) {
status = AEROSPIKE_ERR_PARAM;
DEBUG_PHP_EXT_DEBUG("Unable to set shared memory max nodes");
Expand All @@ -2786,7 +2790,10 @@ aerospike_transform_set_shm_in_config(HashTable* ht_shm, void* as_config_p TSRML
AEROSPIKE_Z_LVAL_P(data);
}
} else if (strcmp((const char *) options_key, PHP_AS_KEY_DEFINE_FOR_SHM_MAX_NAMESPACES) == 0) {
if (AEROSPIKE_ZEND_HASH_GET_CURRENT_DATA_EX(ht_shm, (void**) &data, &options_pointer) == SUCCESS) {
#if PHP_VERSION_ID < 70000
if (AEROSPIKE_ZEND_HASH_GET_CURRENT_DATA_EX(ht_shm, (void**) &data, &options_pointer) == SUCCESS)
#endif
{
if (AEROSPIKE_Z_TYPE_P(data) != IS_LONG) {
status = AEROSPIKE_ERR_PARAM;
DEBUG_PHP_EXT_DEBUG("Unable to set shared memory max namespaces");
Expand All @@ -2796,7 +2803,10 @@ aerospike_transform_set_shm_in_config(HashTable* ht_shm, void* as_config_p TSRML
AEROSPIKE_Z_LVAL_P(data);
}
} else if (strcmp((const char *) options_key, PHP_AS_KEY_DEFINE_FOR_SHM_TAKEOVER_THRESHOLD_SEC) == 0) {
if (AEROSPIKE_ZEND_HASH_GET_CURRENT_DATA_EX(ht_shm, (void**) &data, &options_pointer) == SUCCESS) {
#if PHP_VERSION_ID < 70000
if (AEROSPIKE_ZEND_HASH_GET_CURRENT_DATA_EX(ht_shm, (void**) &data, &options_pointer) == SUCCESS)
#endif
{
if (AEROSPIKE_Z_TYPE_P(data) != IS_LONG) {
status = AEROSPIKE_ERR_PARAM;
DEBUG_PHP_EXT_DEBUG("Unable to set shared memory max namespaces");
Expand All @@ -2811,9 +2821,9 @@ aerospike_transform_set_shm_in_config(HashTable* ht_shm, void* as_config_p TSRML
goto exit;
}
}
#if PHP_VERSION_ID >= 70000
ZEND_HASH_FOREACH_END();
#endif
#if PHP_VERSION_ID >= 70000
ZEND_HASH_FOREACH_END();
#endif
}
exit:
return status;
Expand Down Expand Up @@ -3318,10 +3328,10 @@ as_status aerospike_transform_array_callback_php7(HashTable* ht_p,
#else
if (tmp == AEROSPIKE_ZEND_HASH_FIND((((config_transform_iter_map_t *) data_p)->transform_result).host_lookup_p,
ip_port, strlen(ip_port), (void**)&tmp)) {
zval* z_temp;
ZVAL_STRING(z_temp, ip_port);
zval z_temp;
ZVAL_STRING(&z_temp, ip_port);
if (!zend_hash_str_add_new((((config_transform_iter_map_t *) data_p)->transform_result).host_lookup_p,
ip_port, strlen(ip_port), z_temp)) {
ip_port, strlen(ip_port), &z_temp)) {
#endif
status = AEROSPIKE_ERR_CLIENT;
goto exit;
Expand Down Expand Up @@ -3402,19 +3412,19 @@ as_status aerospike_transform_array_callback(HashTable* ht_p,
goto exit;
}
if (!set_as_config) {
zval **tmp;
DECLARE_ZVAL_P(tmp);
#if PHP_VERSION_ID < 70000
if (FAILURE == AEROSPIKE_ZEND_HASH_FIND((((config_transform_iter_map_t *) data_p)->transform_result).host_lookup_p,
ip_port, strlen(ip_port), (void**)&tmp)) {
if (0 != zend_hash_add((((config_transform_iter_map_t *) data_p)->transform_result).host_lookup_p,
ip_port, strlen(ip_port), (void *) ip_port, strlen(ip_port), NULL)) {
#else
if (FAILURE == AEROSPIKE_ZEND_HASH_FIND((((config_transform_iter_map_t *) data_p)->transform_result).host_lookup_p,
if (NULL == AEROSPIKE_ZEND_HASH_FIND((((config_transform_iter_map_t *) data_p)->transform_result).host_lookup_p,
ip_port, strlen(ip_port), (void**)&tmp)) {
zval* z_temp;
ZVAL_STRING(z_temp, ip_port);
if (*tmp != zend_hash_str_add_new((((config_transform_iter_map_t *) data_p)->transform_result).host_lookup_p,
ip_port, strlen(ip_port), z_temp)) {
zval z_temp;
ZVAL_STRING(&z_temp, ip_port);
if (!zend_hash_str_add_new((((config_transform_iter_map_t *) data_p)->transform_result).host_lookup_p,
ip_port, strlen(ip_port), &z_temp)) {
#endif
status = AEROSPIKE_ERR_CLIENT;
goto exit;
Expand Down

0 comments on commit 4fb530e

Please sign in to comment.