Skip to content

Commit

Permalink
Release 0.2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiz committed Jan 13, 2012
1 parent d2ee9d1 commit 6c59e82
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 75 deletions.
4 changes: 2 additions & 2 deletions config.m4
Expand Up @@ -58,7 +58,7 @@ if test "$PHP_ZOOKEEPER" != "no"; then

if test "$PHP_ZOOKEEPER_SESSION" != "no"; then
AC_MSG_RESULT([enabled])

AC_MSG_CHECKING([for session includes])
session_inc_path=""

Expand Down Expand Up @@ -87,7 +87,7 @@ if test "$PHP_ZOOKEEPER" != "no"; then
[
PHP_ADD_EXTENSION_DEP(zookeeper, session)
])

AC_DEFINE(HAVE_ZOOKEEPER_SESSION,1,[Whether zookeeper session handler is enabled])
SESSION_EXTRA_FILES="php_zookeeper_session.c"
else
Expand Down
23 changes: 19 additions & 4 deletions package.xml
Expand Up @@ -15,18 +15,22 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>andrei@php.net</email>
<active>yes</active>
</lead>
<date>2009-10-15</date>
<date>2012-01-12</date>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
<release>0.2.0</release>
<api>0.2.0</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP</license>
<notes>
- Initial PECL release
- Added session handler support
- Added connect() and delete methods
- Bug fixes
</notes>

</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -55,6 +59,17 @@ http://pear.php.net/dtd/package-2.0.xsd">
<providesextension>zookeeper</providesextension>
<extsrcrelease/>
<changelog>
<release>
<stability><release>beta</release><api>beta</api></stability>
<version><release>0.2.0</release><api>0.2.0</api></version>
<date>2012-01-12</date>
<notes>
- Added session handler support
- Added connect() and delete methods
- Bug fixes
</notes>
</release>

<release>
<stability><release>beta</release><api>beta</api></stability>
<version><release>0.1.0</release><api>0.1.0</api></version>
Expand Down
4 changes: 2 additions & 2 deletions php_zookeeper.h
Expand Up @@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/

/* $ Id: $ */
/* $ Id: $ */

#ifndef PHP_ZOOKEEPER_H
#define PHP_ZOOKEEPER_H
Expand Down Expand Up @@ -66,7 +66,7 @@ extern ps_module ps_mod_zookeeper;

PS_FUNCS(zookeeper);

#endif /* HAVE_ZOOKEEPER_SESSION */
#endif /* HAVE_ZOOKEEPER_SESSION */

#endif /* PHP_ZOOKEEPER_H */

Expand Down
44 changes: 22 additions & 22 deletions php_zookeeper_session.c
Expand Up @@ -40,26 +40,26 @@ ps_module ps_mod_zookeeper = {
static php_zookeeper_session *php_zookeeper_session_init(char *save_path TSRMLS_DC)
{
struct Stat stat;

int status, recv_timeout = ZK_G(recv_timeout);
php_zookeeper_session *session;

session = pecalloc(1, sizeof(php_zookeeper_session), 1);
session->zk = zookeeper_init(save_path, NULL, recv_timeout, 0, NULL, 0);

if (!session->zk) {
efree(session);
return NULL;
}

/* Create parent node if it does not exist */
if (zoo_exists(session->zk, PHP_ZK_PARENT_NODE, 1, &stat) == ZNONODE) {
int retry_count = 3;
do {
status = zoo_create(session->zk, PHP_ZK_PARENT_NODE, 0, 0, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
retry_count++;
} while (status == ZCONNECTIONLOSS && retry_count--);

if (status != ZOK) {
zookeeper_close(session->zk);
efree(session);
Expand Down Expand Up @@ -90,27 +90,27 @@ static php_zookeeper_session *php_zookeeper_session_get(char *save_path TSRMLS_D
return (php_zookeeper_session *) le_p->ptr;
}
}

session = php_zookeeper_session_init(save_path TSRMLS_CC);
le.type = php_zookeeper_get_connection_le();
le.ptr = session;

if (zend_hash_update(&EG(persistent_list), (char *)plist_key, plist_key_len, (void *)&le, sizeof(le), NULL) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not register persistent entry for the zk handle");
}

efree(plist_key);
session->is_locked = 0;
return session;
}
/* }}} */

/* {{{ PS_OPEN_FUNC(zookeeper)
/* {{{ PS_OPEN_FUNC(zookeeper)
*/
PS_OPEN_FUNC(zookeeper)
{
php_zookeeper_session *session = php_zookeeper_session_get(PS(save_path) TSRMLS_CC);

if (!session) {
PS_SET_MOD_DATA(NULL);
return FAILURE;
Expand Down Expand Up @@ -138,7 +138,7 @@ static zend_bool php_zookeeper_sess_lock(php_zookeeper_session *session, const c
efree(lock_path);
return 0;
}

/* set max timeout for session_start = max_execution_time. (c) Andrei Darashenka, Richter & Poweleit GmbH */
lock_maxwait = zend_ini_long(ZEND_STRS("max_execution_time"), 0);
if (lock_maxwait <= 0) {
Expand Down Expand Up @@ -181,7 +181,7 @@ PS_READ_FUNC(zookeeper)
}

path_len = snprintf(session->path, 512, "%s/%s", PHP_ZK_PARENT_NODE, key);

retry_count = 3;
do {
status = zoo_exists(session->zk, session->path, 1, &stat);
Expand All @@ -208,10 +208,10 @@ PS_READ_FUNC(zookeeper)
*vallen = 0;
return FAILURE;
}

*val = emalloc(stat.dataLength);
*vallen = stat.dataLength;

retry_count = 3;
do {
status = zoo_get(session->zk, session->path, 0, *val, vallen, &stat);
Expand Down Expand Up @@ -241,9 +241,9 @@ PS_WRITE_FUNC(zookeeper)
status = zoo_exists(session->zk, session->path, 1, &stat);
retry_count++;
} while (status == ZCONNECTIONLOSS && retry_count--);
retry_count = 3;
do {

retry_count = 3;
do {
if (status != ZOK) {
status = zoo_create(session->zk, session->path, val, vallen, &ZOO_OPEN_ACL_UNSAFE, 0, 0, 0);
} else {
Expand Down Expand Up @@ -277,7 +277,7 @@ PS_GC_FUNC(zookeeper)
int i, status;
int64_t expiration_time;
ZK_SESS_DATA;

expiration_time = (int64_t) (SG(global_request_time) - PS(gc_maxlifetime)) * 1000;
status = zoo_get_children(session->zk, PHP_ZK_PARENT_NODE, 0, &nodes);

Expand All @@ -287,7 +287,7 @@ PS_GC_FUNC(zookeeper)
int path_len;

path_len = snprintf(path, 512, "%s/%s", PHP_ZK_PARENT_NODE, nodes.data[i]);

if (zoo_exists(session->zk, path, 1, &stat) == ZOK) {
/* TODO: should lock here? */
if (stat.mtime < expiration_time) {
Expand All @@ -304,15 +304,15 @@ static void php_zk_sync_completion(int rc, const char *value, const void *data)
PS_CLOSE_FUNC(zookeeper)
{
ZK_SESS_DATA;
if (session->is_locked) {

if (session->is_locked) {
(void) zkr_lock_unlock(&(session->lock));
efree(session->lock.path);

zkr_lock_destroy(&(session->lock));
session->is_locked = 0;
}

/* TODO: is this needed? */
// zoo_async(session->zk, session->path, php_zk_sync_completion, (const void *) session);
PS_SET_MOD_DATA(NULL);
Expand Down
6 changes: 3 additions & 3 deletions php_zookeeper_session.h
Expand Up @@ -27,13 +27,13 @@
typedef struct _php_zookeeper_session {
/* Connection to zookeeper */
zhandle_t *zk;

/* Lock for the session */
zkr_lock_mutex_t lock;

/* Whether the session is locked */
zend_bool is_locked;

/* Current session path */
char path[512];
} php_zookeeper_session;
Expand Down

0 comments on commit 6c59e82

Please sign in to comment.