Ignore:
Timestamp:
2014-03-30T11:08:56+02:00 (9 months ago)
Author:
moo
Message:

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

Location:
branches/3.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2

    • Property svn:mergeinfo changed
      /trunkmerged: 1482
  • branches/3.2/mod_cacher/xc_cacher.c

    r1480 r1483  
    407407} 
    408408/* }}} */ 
    409 static inline void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t interval, zend_ulong *counters, zend_uint count TSRMLS_DC) /* {{{ */ 
     409static inline void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t interval, zend_ulong *counters, zend_uint ncounters TSRMLS_DC) /* {{{ */ 
    410410{ 
    411411    time_t n = XG(request_time) / interval; 
    412     if (*curtime != n) { 
    413         zend_uint target_slot = ((zend_uint) n) % count; 
     412    if (*curtime < n) { 
     413        zend_uint target_slot = ((zend_uint) n) % ncounters; 
    414414        zend_uint slot; 
    415         for (slot = advance_wrapped(*curslot, count); 
     415        for (slot = advance_wrapped(*curslot, ncounters); 
    416416                slot != target_slot; 
    417                 slot = advance_wrapped(slot, count)) { 
     417                slot = advance_wrapped(slot, ncounters)) { 
    418418            counters[slot] = 0; 
    419419        } 
     
    425425} 
    426426/* }}} */ 
     427#define xc_countof(array) (sizeof(array) / sizeof(array[0])) 
    427428static inline void xc_cached_hit_unlocked(xc_cached_t *cached TSRMLS_DC) /* {{{ */ 
    428429{ 
     
    432433            , &cached->hits_by_hour_cur_slot, 60 * 60 
    433434            , cached->hits_by_hour 
    434             , sizeof(cached->hits_by_hour) / sizeof(cached->hits_by_hour[0]) 
     435            , xc_countof(cached->hits_by_hour) 
    435436            TSRMLS_CC); 
    436437 
     
    438439            , &cached->hits_by_second_cur_slot, 1 
    439440            , cached->hits_by_second 
    440             , sizeof(cached->hits_by_second) / sizeof(cached->hits_by_second[0]) 
     441            , xc_countof(cached->hits_by_second) 
    441442            TSRMLS_CC); 
    442443} 
     
    625626    MAKE_STD_ZVAL(hits); 
    626627    array_init(hits); 
    627     for (i = 0; i < sizeof(cached->hits_by_hour) / sizeof(cached->hits_by_hour[0]); i ++) { 
     628    for (i = 0; i < xc_countof(cached->hits_by_hour); i ++) { 
    628629        add_next_index_long(hits, (long) cached->hits_by_hour[i]); 
    629630    } 
     
    632633    MAKE_STD_ZVAL(hits); 
    633634    array_init(hits); 
    634     for (i = 0; i < sizeof(cached->hits_by_second) / sizeof(cached->hits_by_second[0]); i ++) { 
     635    for (i = 0; i < xc_countof(cached->hits_by_second); i ++) { 
    635636        add_next_index_long(hits, (long) cached->hits_by_second[i]); 
    636637    } 
Note: See TracChangeset for help on using the changeset viewer.