From 736820f8f2dc6bcf63d524612db90e7e9427aa98 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Thu, 16 Jan 2014 11:32:33 -0800 Subject: [PATCH] Remove DBABagOStuff Isn't useful outside of testing as the comments state, but it's barely even useful for that. People who are testing the cache code can use CACHE_DB if CACHE_MEMCACHED is too hard. Change-Id: Ief0aa148376957fdd844c8bb585a133b854a012c --- RELEASE-NOTES-1.23 | 1 + includes/AutoLoader.php | 1 - includes/DefaultSettings.php | 14 -- includes/Defines.php | 1 - includes/objectcache/DBABagOStuff.php | 305 -------------------------- 5 files changed, 1 insertion(+), 321 deletions(-) delete mode 100644 includes/objectcache/DBABagOStuff.php diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index b0d97aa809..ca8c91b796 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -28,6 +28,7 @@ production. should be updated if LBFactory_Simple or LBFactory_Multi is configured. * $wgPasswordSenderName has been deprecated. To set a custom mailer name, the system message 'emailsender' should be modified (default: "{{SITENAME}}"). +* $wgDBAhandler was removed as the only class using it was also removed === New features in 1.23 === * ResourceLoader can utilize the Web Storage API to cache modules client-side. diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 0ebca0e31e..e1f8a14b4d 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -768,7 +768,6 @@ $wgAutoloadLocalClasses = array( # includes/objectcache 'APCBagOStuff' => 'includes/objectcache/APCBagOStuff.php', 'BagOStuff' => 'includes/objectcache/BagOStuff.php', - 'DBABagOStuff' => 'includes/objectcache/DBABagOStuff.php', 'EmptyBagOStuff' => 'includes/objectcache/EmptyBagOStuff.php', 'FakeMemCachedClient' => 'includes/objectcache/EmptyBagOStuff.php', 'HashBagOStuff' => 'includes/objectcache/HashBagOStuff.php', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 92ceb6f81f..a8f51fe34e 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1945,9 +1945,6 @@ $wgCacheDirectory = false; * - CACHE_DB: Store cache objects in the DB * - CACHE_MEMCACHED: MemCached, must specify servers in $wgMemCachedServers * - CACHE_ACCEL: APC, XCache or WinCache - * - CACHE_DBA: Use PHP's DBA extension to store in a DBM-style - * database. This is slow, and is not recommended for - * anything other than debugging. * - (other): A string may be used which identifies a cache * configuration in $wgObjectCaches. * @@ -2000,15 +1997,10 @@ $wgLanguageConverterCacheType = CACHE_ANYTHING; * the value is an associative array of parameters. The "class" parameter is the * class name which will be used. Alternatively, a "factory" parameter may be * given, giving a callable function which will generate a suitable cache object. - * - * The other parameters are dependent on the class used. - * - CACHE_DBA uses $wgTmpDirectory by default. The 'dir' parameter let you - * overrides that. */ $wgObjectCaches = array( CACHE_NONE => array( 'class' => 'EmptyBagOStuff' ), CACHE_DB => array( 'class' => 'SqlBagOStuff', 'table' => 'objectcache' ), - CACHE_DBA => array( 'class' => 'DBABagOStuff' ), CACHE_ANYTHING => array( 'factory' => 'ObjectCache::newAnything' ), CACHE_ACCEL => array( 'factory' => 'ObjectCache::newAccelerator' ), @@ -2028,12 +2020,6 @@ $wgObjectCaches = array( */ $wgParserCacheExpireTime = 86400; -/** - * Select which DBA handler - * to use as CACHE_DBA backend. - */ -$wgDBAhandler = 'db3'; - /** * Deprecated alias for $wgSessionsInObjectCache. * diff --git a/includes/Defines.php b/includes/Defines.php index 7c71fe73d3..015ea9cc77 100644 --- a/includes/Defines.php +++ b/includes/Defines.php @@ -113,7 +113,6 @@ define( 'CACHE_NONE', 0 ); // Do not cache define( 'CACHE_DB', 1 ); // Store cache objects in the DB define( 'CACHE_MEMCACHED', 2 ); // MemCached, must specify servers in $wgMemCacheServers define( 'CACHE_ACCEL', 3 ); // APC, XCache or WinCache -define( 'CACHE_DBA', 4 ); // Use PHP's DBA extension to store in a DBM-style database /**@}*/ /**@{ diff --git a/includes/objectcache/DBABagOStuff.php b/includes/objectcache/DBABagOStuff.php deleted file mode 100644 index a81b5c5bc6..0000000000 --- a/includes/objectcache/DBABagOStuff.php +++ /dev/null @@ -1,305 +0,0 @@ - '/some/path' ); as a parameter - * to override the default DBA files directory (wfTempDir()). - * - * @ingroup Cache - */ -class DBABagOStuff extends BagOStuff { - var $mHandler, $mFile, $mReader, $mWriter, $mDisabled; - - /** - * @param $params array - */ - public function __construct( $params ) { - global $wgDBAhandler; - - if ( !isset( $params['dir'] ) ) { - $params['dir'] = wfTempDir(); - } - - $this->mFile = $params['dir'] . '/mw-cache-' . wfWikiID() . '.db'; - wfDebug( __CLASS__ . ": using cache file {$this->mFile}\n" ); - $this->mHandler = $wgDBAhandler; - } - - /** - * Encode value and expiry for storage - * @param $value - * @param $expiry - * - * @return string - */ - protected function encode( $value, $expiry ) { - # Convert to absolute time - $expiry = $this->convertExpiry( $expiry ); - - return sprintf( '%010u', intval( $expiry ) ) . ' ' . serialize( $value ); - } - - /** - * @param $blob string - * @return array list containing value first and expiry second - */ - protected function decode( $blob ) { - if ( !is_string( $blob ) ) { - return array( false, 0 ); - } else { - return array( - unserialize( substr( $blob, 11 ) ), - intval( substr( $blob, 0, 10 ) ) - ); - } - } - - /** - * @return resource - */ - protected function getReader() { - if ( file_exists( $this->mFile ) ) { - $handle = dba_open( $this->mFile, 'rl', $this->mHandler ); - } else { - $handle = $this->getWriter(); - } - - if ( !$handle ) { - wfDebug( "Unable to open DBA cache file {$this->mFile}\n" ); - } - - return $handle; - } - - /** - * @return resource - */ - protected function getWriter() { - $handle = dba_open( $this->mFile, 'cl', $this->mHandler ); - - if ( !$handle ) { - wfDebug( "Unable to open DBA cache file {$this->mFile}\n" ); - } - - return $handle; - } - - /** - * @param $key string - * @param $casToken[optional] mixed - * @return mixed - */ - public function get( $key, &$casToken = null ) { - wfProfileIn( __METHOD__ ); - wfDebug( __METHOD__ . "($key)\n" ); - - $handle = $this->getReader(); - if ( !$handle ) { - wfProfileOut( __METHOD__ ); - return false; - } - - $val = dba_fetch( $key, $handle ); - $casToken = $val; - list( $val, $expiry ) = $this->decode( $val ); - - # Must close ASAP because locks are held - dba_close( $handle ); - - if ( $val !== false && $expiry && $expiry < time() ) { - # Key is expired, delete it - $handle = $this->getWriter(); - dba_delete( $key, $handle ); - dba_close( $handle ); - wfDebug( __METHOD__ . ": $key expired\n" ); - $val = false; - } - - wfProfileOut( __METHOD__ ); - - return $val; - } - - /** - * @param $key string - * @param $value mixed - * @param $exptime int - * @return bool - */ - public function set( $key, $value, $exptime = 0 ) { - wfProfileIn( __METHOD__ ); - wfDebug( __METHOD__ . "($key)\n" ); - - $blob = $this->encode( $value, $exptime ); - - $handle = $this->getWriter(); - if ( !$handle ) { - wfProfileOut( __METHOD__ ); - return false; - } - - $ret = dba_replace( $key, $blob, $handle ); - dba_close( $handle ); - - wfProfileOut( __METHOD__ ); - return $ret; - } - - /** - * @param $casToken mixed - * @param $key string - * @param $value mixed - * @param $exptime int - * @return bool - */ - public function cas( $casToken, $key, $value, $exptime = 0 ) { - wfProfileIn( __METHOD__ ); - wfDebug( __METHOD__ . "($key)\n" ); - - $blob = $this->encode( $value, $exptime ); - - $handle = $this->getWriter(); - if ( !$handle ) { - wfProfileOut( __METHOD__ ); - return false; - } - - // DBA is locked to any other write connection, so we can safely - // compare the current & previous value before saving new value - $val = dba_fetch( $key, $handle ); - if ( $casToken !== $val ) { - dba_close( $handle ); - wfProfileOut( __METHOD__ ); - return false; - } - - $ret = dba_replace( $key, $blob, $handle ); - dba_close( $handle ); - - wfProfileOut( __METHOD__ ); - return $ret; - } - - /** - * @param $key string - * @param $time int - * @return bool - */ - public function delete( $key, $time = 0 ) { - wfProfileIn( __METHOD__ ); - wfDebug( __METHOD__ . "($key)\n" ); - - $handle = $this->getWriter(); - if ( !$handle ) { - wfProfileOut( __METHOD__ ); - return false; - } - - $ret = !dba_exists( $key, $handle ) || dba_delete( $key, $handle ); - dba_close( $handle ); - - wfProfileOut( __METHOD__ ); - return $ret; - } - - /** - * @param $key string - * @param $value mixed - * @param $exptime int - * @return bool - */ - public function add( $key, $value, $exptime = 0 ) { - wfProfileIn( __METHOD__ ); - - $blob = $this->encode( $value, $exptime ); - - $handle = $this->getWriter(); - - if ( !$handle ) { - wfProfileOut( __METHOD__ ); - return false; - } - - $ret = dba_insert( $key, $blob, $handle ); - - # Insert failed, check to see if it failed due to an expired key - if ( !$ret ) { - list( , $expiry ) = $this->decode( dba_fetch( $key, $handle ) ); - - if ( $expiry && $expiry < time() ) { - # Yes expired, delete and try again - dba_delete( $key, $handle ); - $ret = dba_insert( $key, $blob, $handle ); - # This time if it failed then it will be handled by the caller like any other race - } - } - - dba_close( $handle ); - - wfProfileOut( __METHOD__ ); - return $ret; - } - - /** - * @param $key string - * @param $step integer - * @return integer|bool - */ - public function incr( $key, $step = 1 ) { - wfProfileIn( __METHOD__ ); - - $handle = $this->getWriter(); - - if ( !$handle ) { - wfProfileOut( __METHOD__ ); - return false; - } - - list( $value, $expiry ) = $this->decode( dba_fetch( $key, $handle ) ); - if ( $value !== false ) { - if ( $expiry && $expiry < time() ) { - # Key is expired, delete it - dba_delete( $key, $handle ); - wfDebug( __METHOD__ . ": $key expired\n" ); - $value = false; - } else { - $value += $step; - $blob = $this->encode( $value, $expiry ); - - $ret = dba_replace( $key, $blob, $handle ); - $value = $ret ? $value : false; - } - } - - dba_close( $handle ); - - wfProfileOut( __METHOD__ ); - - return ( $value === false ) ? false : (int)$value; - } -} -- 2.20.1