Skip to content

Commit

Permalink
bailout after engine fatals
Browse files Browse the repository at this point in the history
  • Loading branch information
krakjoe committed Sep 29, 2016
1 parent ac97f34 commit 62f559e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
50 changes: 42 additions & 8 deletions apc_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,16 +942,23 @@ PHP_APCU_API zend_bool apc_cache_insert(apc_cache_t* cache,
zend_bool exclusive)
{
zend_bool result = 0;

zend_bool bailout = 0;

APC_LOCK(cache->header);

zend_try {
result = apc_cache_insert_internal(
cache, key, value, ctxt, t, exclusive);
} zend_catch {
bailout = 1;
} zend_end_try();

APC_UNLOCK(cache->header);

if (bailout) {
zend_bailout();
}

return result;
}
/* }}} */
Expand Down Expand Up @@ -1059,7 +1066,7 @@ PHP_APCU_API zend_bool apc_cache_update(apc_cache_t* cache, zend_string *key, ap
apc_cache_slot_t** slot;
apc_cache_entry_t tmp_entry;

zend_bool retval = 0;
zend_bool retval = 0, bailout = 0;
zend_ulong h, s;

if(apc_cache_busy(cache))
Expand Down Expand Up @@ -1113,11 +1120,17 @@ PHP_APCU_API zend_bool apc_cache_update(apc_cache_t* cache, zend_string *key, ap
/* set next slot */
slot = &(*slot)->next;
}
} zend_catch {
bailout = 1;
} zend_end_try();

/* unlock header */
APC_UNLOCK(cache->header);

if (bailout) {
zend_bailout();
}

/* failed to find matching entry, create it */
ZVAL_LONG(&tmp_entry.val, 0);
updater(cache, &tmp_entry, data);
Expand Down Expand Up @@ -1713,6 +1726,7 @@ PHP_APCU_API zval apc_cache_info(apc_cache_t* cache, zend_bool limited)
zval slots;
apc_cache_slot_t* p;
zend_ulong i, j;
zend_bool bailout = 0;

if (!cache) {
ZVAL_NULL(&info);
Expand All @@ -1736,11 +1750,11 @@ PHP_APCU_API zval apc_cache_info(apc_cache_t* cache, zend_bool limited)
add_assoc_long(&info, "start_time", cache->header->stime);
add_assoc_double(&info, "mem_size", (double)cache->header->mem_size);

#if APC_MMAP
#if APC_MMAP
add_assoc_stringl(&info, "memory_type", "mmap", sizeof("mmap")-1);
#else
#else
add_assoc_stringl(&info, "memory_type", "IPC shared", sizeof("IPC shared")-1);
#endif
#endif

if (!limited) {
/* For each hashtable slot */
Expand Down Expand Up @@ -1773,11 +1787,17 @@ PHP_APCU_API zval apc_cache_info(apc_cache_t* cache, zend_bool limited)
add_assoc_zval(&info, "slot_distribution", &slots);
}

} zend_catch {
bailout = 1;
} zend_end_try();

/* unlock header */
APC_RUNLOCK(cache->header);

if (bailout) {
zend_bailout();
}

return info;
}
/* }}} */
Expand All @@ -1788,7 +1808,8 @@ PHP_APCU_API zval apc_cache_info(apc_cache_t* cache, zend_bool limited)
PHP_APCU_API zval* apc_cache_stat(apc_cache_t* cache, zend_string *key, zval *stat) {
apc_cache_slot_t** slot;
zend_ulong h, s;

zend_bool bailout = 0;

/* calculate hash and slot */
apc_cache_hash_slot(cache, key, &h, &s);

Expand Down Expand Up @@ -1819,10 +1840,16 @@ PHP_APCU_API zval* apc_cache_stat(apc_cache_t* cache, zend_string *key, zval *st
/* next */
slot = &(*slot)->next;
}
} zend_catch {
bailout = 1;
} zend_end_try();

APC_RUNLOCK(cache->header);


if (bailout) {
zend_bailout();
}

return stat;
}

Expand Down Expand Up @@ -1891,7 +1918,8 @@ PHP_APCU_API void apc_cache_serializer(apc_cache_t* cache, const char* name) {

PHP_APCU_API void apc_cache_entry(apc_cache_t *cache, zval *key, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_long ttl, zend_long now, zval *return_value) {
apc_cache_entry_t *entry = NULL;

zend_bool bailout = 0;

if(!cache || apc_cache_busy(cache)) {
return;
}
Expand Down Expand Up @@ -1930,6 +1958,8 @@ PHP_APCU_API void apc_cache_entry(apc_cache_t *cache, zval *key, zend_fcall_info
}
}
} else apc_cache_fetch_internal(cache, Z_STR_P(key), entry, now, &return_value);
} zend_catch {
bailout = 1;
} zend_end_try();

#ifndef APC_LOCK_RECURSIVE
Expand All @@ -1939,6 +1969,10 @@ PHP_APCU_API void apc_cache_entry(apc_cache_t *cache, zval *key, zend_fcall_info
#else
APC_UNLOCK(cache->header);
#endif

if (bailout) {
zend_bailout();
}
}

/*
Expand Down
21 changes: 21 additions & 0 deletions apc_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ static int apc_iterator_fetch_active(apc_iterator_t *iterator) {
apc_cache_slot_t **slot;
apc_iterator_item_t *item;
time_t t;
zend_bool bailout = 0;

t = apc_time();

Expand All @@ -223,11 +224,17 @@ static int apc_iterator_fetch_active(apc_iterator_t *iterator) {
}
iterator->slot_idx++;
}
} zend_catch {
bailout = 1;
} zend_end_try();

iterator->stack_idx = 0;
APC_RUNLOCK(apc_user_cache->header);

if (bailout) {
zend_bailout();
}

return count;
}
/* }}} */
Expand All @@ -237,6 +244,7 @@ static int apc_iterator_fetch_deleted(apc_iterator_t *iterator) {
int count=0;
apc_cache_slot_t **slot;
apc_iterator_item_t *item;
zend_bool bailout = 0;

APC_RLOCK(apc_user_cache->header);

Expand All @@ -257,12 +265,18 @@ static int apc_iterator_fetch_deleted(apc_iterator_t *iterator) {
}
slot = &(*slot)->next;
}
} zend_catch {
bailout = 1;
} zend_end_try();

iterator->slot_idx += count;
iterator->stack_idx = 0;
APC_RUNLOCK(apc_user_cache->header);

if (bailout) {
zend_bailout();
}

return count;
}
/* }}} */
Expand All @@ -271,6 +285,7 @@ static int apc_iterator_fetch_deleted(apc_iterator_t *iterator) {
static void apc_iterator_totals(apc_iterator_t *iterator) {
apc_cache_slot_t **slot;
int i;
zend_bool bailout = 0;

APC_RLOCK(apc_user_cache->header);

Expand All @@ -286,11 +301,17 @@ static void apc_iterator_totals(apc_iterator_t *iterator) {
slot = &(*slot)->next;
}
}
} zend_catch {
bailout = 1;
} zend_end_try();

APC_RUNLOCK(apc_user_cache->header);

iterator->totals_flag = 1;

if (bailout) {
zend_bailout();
}
}
/* }}} */

Expand Down

0 comments on commit 62f559e

Please sign in to comment.