Re: Fwd: [PECL-CVS] cvs: pecl /apc CHANGELOG apc_cache.c php_apc.c

[email protected] (Rasmus Lerdorf) Tue, 29 Jan 2008 20:11:17 -0800
Newsgroups php.apc.dev
Message-ID <[email protected]>
My fix was rather trivial.  Go ahead with your stuff.  I don't really
care how we avoid doing an expunge on an apc_add.  It is only called
from one place, so we can change it all we want.

-Rasmus

Brian Shire wrote:
> Hey Rasmus,
> 
> I just realized that you had already made a bug fix which I have just  
> also committed changes for.  I've added an expunge callback that will  
> expunge the cache from the sma code when it's attempting to alloc  
> space.  This gives me the ability to play with a least frequently  
> used algorithm in the future, ensures that we don't expunge due to  
> the exclusive failure in apc_add(), and that we insert the new entry  
> after we expunge so it's always successful.
> 
> Shout at me if you see problems with my thinking here, otherwise I  
> think I've created some duplicate code that I'll cleanup.
> 
> -shire
> 
> Begin forwarded message:
> 
>> From: "Rasmus Lerdorf" <[email protected]>
>> Date: January 24, 2008 11:10:48 PM PST
>> To: [email protected]
>> Subject: [PECL-CVS] cvs: pecl /apc CHANGELOG apc_cache.c php_apc.c
>>
>> rasmus		Fri Jan 25 07:10:48 2008 UTC
>>
>>   Modified files:
>>     /pecl/apc	CHANGELOG apc_cache.c php_apc.c
>>   Log:
>>   We don't want to expunge on an exclusive user cache insert that  
>> doesn't
>>   insert because of the exclusivity check.  So make the user cache  
>> insert
>>   return values match the opcode cache return values for  
>> consistency and
>>   check for them correctly.
>>
>>
>> http://cvs.php.net/viewvc.cgi/pecl/apc/CHANGELOG? 
>> r1=1.39&r2=1.40&diff_format=u
>> Index: pecl/apc/CHANGELOG
>> diff -u pecl/apc/CHANGELOG:1.39 pecl/apc/CHANGELOG:1.40
>> --- pecl/apc/CHANGELOG:1.39	Wed Dec 26 22:46:33 2007
>> +++ pecl/apc/CHANGELOG	Fri Jan 25 07:10:48 2008
>> @@ -1,3 +1,5 @@
>> +- Fix apc_add() cache expunge bug (Rasmus)
>> +
>>  3.0.16: 2007-12-26
>>  - Fix for longstanding cache-full crash (Christian Seiler)
>>    http://news.php.net/php.pecl.dev/4951 for the details
>> http://cvs.php.net/viewvc.cgi/pecl/apc/apc_cache.c? 
>> r1=3.148&r2=3.149&diff_format=u
>> Index: pecl/apc/apc_cache.c
>> diff -u pecl/apc/apc_cache.c:3.148 pecl/apc/apc_cache.c:3.149
>> --- pecl/apc/apc_cache.c:3.148	Wed Jan  9 10:33:05 2008
>> +++ pecl/apc/apc_cache.c	Fri Jan 25 07:10:48 2008
>> @@ -28,7 +28,7 @@
>>
>>   */
>>
>> -/* $Id: apc_cache.c,v 3.148 2008/01/09 10:33:05 gopalv Exp $ */
>> +/* $Id: apc_cache.c,v 3.149 2008/01/25 07:10:48 rasmus Exp $ */
>>
>>  #include "apc_cache.h"
>>  #include "apc_lock.h"
>> @@ -484,7 +484,7 @@
>>      size_t* mem_size_ptr = NULL;
>>
>>      if (!value) {
>> -        return 0;
>> +        return -1;
>>      }
>>
>>      LOCK(cache);
>> @@ -535,7 +535,7 @@
>>
>>      if ((*slot = make_slot(key, value, *slot, t)) == NULL) {
>>          UNLOCK(cache);
>> -        return 0;
>> +        return -1;
>>      }
>>      if (APCG(mem_size_ptr) != NULL) {
>>          value->mem_size = *APCG(mem_size_ptr);
>> http://cvs.php.net/viewvc.cgi/pecl/apc/php_apc.c? 
>> r1=3.158&r2=3.159&diff_format=u
>> Index: pecl/apc/php_apc.c
>> diff -u pecl/apc/php_apc.c:3.158 pecl/apc/php_apc.c:3.159
>> --- pecl/apc/php_apc.c:3.158	Tue Jan  8 21:42:32 2008
>> +++ pecl/apc/php_apc.c	Fri Jan 25 07:10:48 2008
>> @@ -26,7 +26,7 @@
>>
>>   */
>>
>> -/* $Id: php_apc.c,v 3.158 2008/01/08 21:42:32 gopalv Exp $ */
>> +/* $Id: php_apc.c,v 3.159 2008/01/25 07:10:48 rasmus Exp $ */
>>
>>  #include "apc_zend.h"
>>  #include "apc_cache.h"
>> @@ -222,7 +222,7 @@
>>  #else
>>      php_info_print_table_row(2, "Locking type", "File Locks");
>>  #endif
>> -    php_info_print_table_row(2, "Revision", "$Revision: 3.158 $");
>> +    php_info_print_table_row(2, "Revision", "$Revision: 3.159 $");
>>      php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__);
>>      php_info_print_table_end();
>>      DISPLAY_INI_ENTRIES();
>> @@ -539,6 +539,7 @@
>>      apc_cache_key_t key;
>>      time_t t;
>>      size_t mem_size = 0;
>> +    int ret;
>>
>>  #if PHP_API_VERSION < 20041225
>>  #if HAVE_APACHE && defined(APC_PHP4_STAT)
>> @@ -572,20 +573,22 @@
>>          return 0;
>>      }
>>
>> -    if (!apc_cache_user_insert(apc_user_cache, key, entry, t,  
>> exclusive TSRMLS_CC)) {
>> -        APCG(mem_size_ptr) = NULL;
>> +    if (ret = apc_cache_user_insert(apc_user_cache, key, entry, t,  
>> exclusive TSRMLS_CC)!=1) {
>>          apc_cache_free_entry(entry);
>> -        apc_cache_expunge(apc_cache,t);
>> -        apc_cache_expunge(apc_user_cache,t);
>> -        HANDLE_UNBLOCK_INTERRUPTIONS();
>> -        return 0;
>> +        if(ret==-1) {
>> +            APCG(mem_size_ptr) = NULL;
>> +            apc_cache_expunge(apc_cache,t);
>> +            apc_cache_expunge(apc_user_cache,t);
>> +            HANDLE_UNBLOCK_INTERRUPTIONS();
>> +            return 0;
>> +        }
>>      }
>>
>>      APCG(mem_size_ptr) = NULL;
>>
>>      HANDLE_UNBLOCK_INTERRUPTIONS();
>>
>> -    return 1;
>> +    return ret;
>>  }
>>  /* }}} */
>>
>>
>> -- 
>> PECL CVS Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>