1
0
Fork 0

MFT: fixed random 24H counters clear. it's a race cached condition. thanks to the report from Per Hansson

git-svn-id: svn://svn.lighttpd.net/xcache/branches/3.1@1484 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.1
Xuefer 2014-03-30 09:09:39 +00:00
parent ae93a37b95
commit 3a72a894d0
2 changed files with 12 additions and 9 deletions

View File

@ -3,6 +3,8 @@ ChangeLog
========
* cacher
* compatible with bcompiler
* admin
* fixed random 24H counters clear. it's a race cached condition. thanks to the report from Per Hansson
3.1.0 2013-10-10
ChangeLog

View File

@ -406,15 +406,15 @@ static inline zend_uint advance_wrapped(zend_uint val, zend_uint count) /* {{{ *
return val + 1;
}
/* }}} */
static inline void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t interval, zend_ulong *counters, zend_uint count TSRMLS_DC) /* {{{ */
static inline void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t interval, zend_ulong *counters, zend_uint ncounters TSRMLS_DC) /* {{{ */
{
time_t n = XG(request_time) / interval;
if (*curtime != n) {
zend_uint target_slot = ((zend_uint) n) % count;
if (*curtime < n) {
zend_uint target_slot = ((zend_uint) n) % ncounters;
zend_uint slot;
for (slot = advance_wrapped(*curslot, count);
for (slot = advance_wrapped(*curslot, ncounters);
slot != target_slot;
slot = advance_wrapped(slot, count)) {
slot = advance_wrapped(slot, ncounters)) {
counters[slot] = 0;
}
counters[target_slot] = 0;
@ -424,6 +424,7 @@ static inline void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t i
counters[*curslot] ++;
}
/* }}} */
#define xc_countof(array) (sizeof(array) / sizeof(array[0]))
static inline void xc_cached_hit_unlocked(xc_cached_t *cached TSRMLS_DC) /* {{{ */
{
cached->hits ++;
@ -431,13 +432,13 @@ static inline void xc_cached_hit_unlocked(xc_cached_t *cached TSRMLS_DC) /* {{{
xc_counters_inc(&cached->hits_by_hour_cur_time
, &cached->hits_by_hour_cur_slot, 60 * 60
, cached->hits_by_hour
, sizeof(cached->hits_by_hour) / sizeof(cached->hits_by_hour[0])
, xc_countof(cached->hits_by_hour)
TSRMLS_CC);
xc_counters_inc(&cached->hits_by_second_cur_time
, &cached->hits_by_second_cur_slot, 1
, cached->hits_by_second
, sizeof(cached->hits_by_second) / sizeof(cached->hits_by_second[0])
, xc_countof(cached->hits_by_second)
TSRMLS_CC);
}
/* }}} */
@ -624,14 +625,14 @@ static void xc_fillinfo_unlocked(int cachetype, xc_cache_t *cache, zval *return_
}
MAKE_STD_ZVAL(hits);
array_init(hits);
for (i = 0; i < sizeof(cached->hits_by_hour) / sizeof(cached->hits_by_hour[0]); i ++) {
for (i = 0; i < xc_countof(cached->hits_by_hour); i ++) {
add_next_index_long(hits, (long) cached->hits_by_hour[i]);
}
add_assoc_zval_ex(return_value, XCACHE_STRS("hits_by_hour"), hits);
MAKE_STD_ZVAL(hits);
array_init(hits);
for (i = 0; i < sizeof(cached->hits_by_second) / sizeof(cached->hits_by_second[0]); i ++) {
for (i = 0; i < xc_countof(cached->hits_by_second); i ++) {
add_next_index_long(hits, (long) cached->hits_by_second[i]);
}
add_assoc_zval_ex(return_value, XCACHE_STRS("hits_by_second"), hits);