ZF-6161: setDefaultMetadataCache throw exception after restart the memcached
Description
Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'Failed saving metadata to
metadataCache' in /var/www/ZENDIR/Zend/Db/Table/Abstract.php:635 Stack trace:
#0 /var/www/ZENDIR/Zend/Db/Table/Abstract.php(540): Zend_Db_Table_Abstract->_setupMetadata()
#1 /var/www/ZENDIR/Zend/Db/Table/Abstract.php(268): Zend_Db_Table_Abstract->_setup()
#2 /var/www/prcms/application/Initializer.php(155): Zend_Db_Table_Abstract->__construct()
#3 /var/www/prcms/application/Initializer.php(55): Initializer->initSite()
#4 /var/www/prcms/application/bootstrap.php(31): Initializer->__construct('testing')
#5 /var/www/prcms/public/index.php(2): require('/var/www/prcms/...')
#6 {main} thrown in /var/www/ZENDIR/Zend/Db/Table/Abstract.php on line 635
ENV: 1) Linux lamp 2.6.18-4-686 #1 SMP Mon Mar 26 17:17:36 UTC 2007 i686 GNU/Linux 2) apache-2.2.6 3) php-5.2.3 4) memcached-1.2.4 (should also affect latest stable version) 5) ZendFramework: 1.6.2 (after checked the latest trunk code, the problem hasnot fixed yet)
Our system use memcached as the cache storage, the connection is persistent. This bug hasnot occured under non-persistent Memcached circumstance
So the description below under persistent connection. (1) After restart the Memcached, function save frequently returns false;
Zend/Db/Table/Abstract.php
if (null !== $this->_metadataCache && !$this->_metadataCache->save($metadata, $cacheId)) {
/**
* @see Zend_Db_Table_Exception
*/
require_once 'Zend/Db/Table/Exception.php';
throw new Zend_Db_Table_Exception('Failed saving metadata to metadataCache');
}
So if $this->_metadataCache->save($metadata, $cacheId)) return false, then the exception threw
Comments
Posted by Ken Chou (kenchou77) on 2009-05-08T01:50:41.000+0000
Agree. This is not a crit error for Zend_Db_Table and need no exception to throw.
Posted by chocobn (chocobn69) on 2009-08-17T06:31:24.000+0000
same error if memached is not reachable, throw an exception
Posted by Ralph Schindler (ralph) on 2009-08-17T08:21:10.000+0000
Formatted error. Marked as trivial since a suggested fix is supplied. Marked as "should have" for "next mini release"
Posted by Ludwig Ruderstaller (rufinus) on 2009-08-21T05:06:09.000+0000
why isnt this fixed in current versions ?
at least seems this way in 1.9.0
restart memcached error -> reload -> working -> reload -> error
Posted by Ludwig Ruderstaller (rufinus) on 2009-08-21T05:07:41.000+0000
should take a look at the datestamps of the comments... nevermind.
Posted by Ralph Schindler (ralph) on 2009-08-25T13:12:14.000+0000
Digging into this, is an exception not what we want here? It seems like if you ask it to use a cache, and the cache fails at saving, shouldnt an exception be thrown? Is this perhaps a situation that should be taken care of before table metadataSetup(), like in the bootstrap? Perhaps the bootstrap should detect if memcached is not available?
-ralph
Posted by Valera Leontyev (feedbee) on 2009-09-10T00:33:41.000+0000
Is it possible situation when memcached server fails after connection setting up? Yes. In that case if exception will be thrown we'll get unwanted break up. I want to see my scripts still working fine even in the case memcached doesn't work properly.
Posted by Michael Rehbein (tech13) on 2009-11-24T11:29:13.000+0000
If we really need to know the cache failed, wouldn't a throw from Zend_Cache be a better place then a throw from Zend_Db?
Alternatively, couldn't it just be a trigger_error(...., Notice) rather then a throw?
Posted by Valera Leontyev (feedbee) on 2009-11-24T23:35:45.000+0000
Really, notice is the best way to keep a web-master informed about cache subsystem problems and not to interrupt normal code execution later on.
Posted by Ludwig Ruderstaller (rufinus) on 2009-12-18T06:29:04.000+0000
the really strange part of this is the error comes and goes.
Restart memcached -> access the page -> error -> reload -> working -> reload -> working or error
after a few minutes (dont know on what it depends) no errors are thrown.. until the next memcached restart.
What i have to try sometimes is what if you configure more than one memcached server will a error thrown wenn only one of them is restarted.
In general i would also suggest to trigger a notice, a cache failure is not allowed to stop a, besides this, working page.
Posted by Ralph Schindler (ralph) on 2009-12-21T12:31:54.000+0000
If the memcached server is not available, it seems like Zend_Cache should throw an exception, no?
Then, when inside Zend_Db_Table, it should treat Zend_Cache as a (effectively) /dev/null cache, thus, it will always have to do the lookup on the metadata.
Or am I missing something?
Posted by Ken Chou (kenchou77) on 2009-12-21T18:59:34.000+0000
That's right. Cache should be used to improve the performance of process, should not break the process. The current version, even if we caught the exception thrown within Zend_Db_Table, we can not return to run as no cache.
Posted by Michael Rehbein (tech13) on 2010-01-14T11:03:32.000+0000
Patch contains:
Changed throw to E_USER_NOTICE on metaCache save fail Updated test suite to match
Posted by Juraj Seffer (jurajseffer) on 2010-01-18T04:10:13.000+0000
I have not been able to find out what's causing the exception to be thrown, I initialise the cache in my bootstrap like this:
protected function _initDbTableCache() { $cache = Zend_Cache::factory('Core', 'File', array('automatic_serialization' => true), array('cache_dir' => APPLICATION_PATH . '/cache') ); Zend_Db_Table_Abstract::setDefaultMetadataCache($cache); }
but every now and then, it throws an exception.
Posted by Bryan (nynja) on 2010-03-01T16:40:19.000+0000
I have the same setup setup as Juraj. Since updating to 10.0.2, a notice is thrown instead of an exception. This is nice, but I don't know why its being thrown. I'm guessing that it throws whenever the cache is old, but I need to setup better logs to see if this is really the case.
Any ideas for pinpointing the problem?
Posted by Michael Kliewe (mkliewe) on 2010-05-17T07:37:42.000+0000
I have a similar problem with memcached as metadatacache. I use the Zend_Session_SaveHandler_DbTable, and from time to time I get an exception saying that saving metadata failed (because Zend_Db_Table is used to save session data). As a result session_start() does not work. See log below.
I will now try to use a "non-persistent" connection to memcached.
I also had the problem in the past with restarting memcached: Restart memcached -> access the page -> error -> reload -> working -> reload -> working or error Since it is not an exception anymore the problem is gone.
{quote}[12-May-2010 10:12:05] PHP Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Zend_Session::start() - /home/user/workspace/ZendFramework-1.10.3/library/Zend/Db/Table/Abstract.php(Line:826): Error #1024 Failed saving metadata to metadataCache Array' in /home/user/workspace/ZendFramework-1.10.3/library/Zend/Session.php:493 Stack trace:
0 /home/user/workspace/Project/application/Bootstrap.php(286): Zend_Session::start()
1 /home/user/workspace/ZendFramework-1.10.3/library/Zend/Application/Bootstrap/BootstrapAbstract.php(665): Bootstrap->_initSession()
2 /home/user/workspace/ZendFramework-1.10.3/library/Zend/Application/Bootstrap/BootstrapAbstract.php(618): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('session')
3 /home/user/workspace/ZendFramework-1.10.3/library/Zend/Application/Bootstrap/BootstrapAbstract.php(582): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL)
4 /home/user/workspace/Ze in /home/user/workspace/ZendFramework-1.10.3/library/Zend/Session.php on line 493{quote}