summaryrefslogtreecommitdiff
path: root/includes/objectcache
diff options
context:
space:
mode:
Diffstat (limited to 'includes/objectcache')
-rw-r--r--includes/objectcache/BagOStuff.php8
-rw-r--r--includes/objectcache/DBABagOStuff.php4
-rw-r--r--includes/objectcache/EmptyBagOStuff.php2
-rw-r--r--includes/objectcache/MemcachedClient.php20
-rw-r--r--includes/objectcache/MultiWriteBagOStuff.php4
-rw-r--r--includes/objectcache/ObjectCache.php10
-rw-r--r--includes/objectcache/SqlBagOStuff.php139
-rw-r--r--includes/objectcache/eAccelBagOStuff.php46
8 files changed, 122 insertions, 111 deletions
diff --git a/includes/objectcache/BagOStuff.php b/includes/objectcache/BagOStuff.php
index 97b6cb2c..81ad6621 100644
--- a/includes/objectcache/BagOStuff.php
+++ b/includes/objectcache/BagOStuff.php
@@ -92,11 +92,15 @@ abstract class BagOStuff {
}
/**
- * Delete all objects expiring before a certain date.
+ * Delete all objects expiring before a certain date.
+ * @param $date The reference date in MW format
+ * @param $progressCallback Optional, a function which will be called
+ * regularly during long-running operations with the percentage progress
+ * as the first parameter.
*
* @return true on success, false if unimplemented
*/
- public function deleteObjectsExpiringBefore( $date ) {
+ public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
// stub
return false;
}
diff --git a/includes/objectcache/DBABagOStuff.php b/includes/objectcache/DBABagOStuff.php
index a273a4f7..ade8c0a9 100644
--- a/includes/objectcache/DBABagOStuff.php
+++ b/includes/objectcache/DBABagOStuff.php
@@ -187,8 +187,10 @@ class DBABagOStuff extends BagOStuff {
$result[] = $k1;
- while ( $key = dba_nextkey( $reader ) ) {
+ $key = dba_nextkey( $reader );
+ while ( $key ) {
$result[] = $key;
+ $key = dba_nextkey( $reader );
}
return $result;
diff --git a/includes/objectcache/EmptyBagOStuff.php b/includes/objectcache/EmptyBagOStuff.php
index e956e2ee..2aee6b12 100644
--- a/includes/objectcache/EmptyBagOStuff.php
+++ b/includes/objectcache/EmptyBagOStuff.php
@@ -19,7 +19,7 @@ class EmptyBagOStuff extends BagOStuff {
}
}
-/**
+/**
* Backwards compatibility alias for EmptyBagOStuff
* @deprecated since 1.18
*/
diff --git a/includes/objectcache/MemcachedClient.php b/includes/objectcache/MemcachedClient.php
index dd4401a8..868ad69f 100644
--- a/includes/objectcache/MemcachedClient.php
+++ b/includes/objectcache/MemcachedClient.php
@@ -396,7 +396,7 @@ class MWMemcached {
/**
* Retrieves the value associated with the key from the memcache server
*
- * @param $key Mixed: key to retrieve
+ * @param $key array|string key to retrieve
*
* @return Mixed
*/
@@ -419,6 +419,7 @@ class MWMemcached {
return false;
}
+ $key = is_array( $key ) ? $key[1] : $key;
if ( isset( $this->stats['get'] ) ) {
$this->stats['get']++;
} else {
@@ -826,9 +827,9 @@ class MWMemcached {
/**
* Perform increment/decriment on $key
*
- * @param $cmd String: command to perform
- * @param $key String: key to perform it on
- * @param $amt Integer: amount to adjust
+ * @param $cmd String command to perform
+ * @param $key String|array key to perform it on
+ * @param $amt Integer amount to adjust
*
* @return Integer: new value of $key
* @access private
@@ -958,10 +959,13 @@ class MWMemcached {
} else {
$this->stats[$cmd] = 1;
}
-
- // Memcached doesn't seem to handle very high TTL values very well,
- // so clamp them at 30 days
- if ( $exp > 2592000 ) {
+
+ // TTLs higher than 30 days will be detected as absolute TTLs
+ // (UNIX timestamps), and will result in the cache entry being
+ // discarded immediately because the expiry is in the past.
+ // Clamp expiries >30d at 30d, unless they're >=1e9 in which
+ // case they are likely to really be absolute (1e9 = 2011-09-09)
+ if ( $exp > 2592000 && $exp < 1000000000 ) {
$exp = 2592000;
}
diff --git a/includes/objectcache/MultiWriteBagOStuff.php b/includes/objectcache/MultiWriteBagOStuff.php
index 2b88b427..0d95a846 100644
--- a/includes/objectcache/MultiWriteBagOStuff.php
+++ b/includes/objectcache/MultiWriteBagOStuff.php
@@ -101,10 +101,10 @@ class MultiWriteBagOStuff extends BagOStuff {
*
* Succeed if any of the child caches succeed.
*/
- public function deleteObjectsExpiringBefore( $date ) {
+ public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
$ret = false;
foreach ( $this->caches as $cache ) {
- if ( $cache->deleteObjectsExpiringBefore( $date ) ) {
+ if ( $cache->deleteObjectsExpiringBefore( $date, $progressCallback ) ) {
$ret = true;
}
}
diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php
index 99e38953..77ca8371 100644
--- a/includes/objectcache/ObjectCache.php
+++ b/includes/objectcache/ObjectCache.php
@@ -43,7 +43,7 @@ class ObjectCache {
global $wgObjectCaches;
if ( !isset( $wgObjectCaches[$id] ) ) {
- throw new MWException( "Invalid object cache type \"$id\" requested. " .
+ throw new MWException( "Invalid object cache type \"$id\" requested. " .
"It is not present in \$wgObjectCaches." );
}
@@ -89,9 +89,7 @@ class ObjectCache {
* @return ObjectCache
*/
static function newAccelerator( $params ) {
- if ( function_exists( 'eaccelerator_get' ) ) {
- $id = 'eaccelerator';
- } elseif ( function_exists( 'apc_fetch') ) {
+ if ( function_exists( 'apc_fetch') ) {
$id = 'apc';
} elseif( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
$id = 'xcache';
@@ -106,11 +104,11 @@ class ObjectCache {
/**
* Factory function that creates a memcached client object.
- * The idea of this is that it might eventually detect and automatically
+ * The idea of this is that it might eventually detect and automatically
* support the PECL extension, assuming someone can get it to compile.
*
* @param $params array
- *
+ *
* @return MemcachedPhpBagOStuff
*/
static function newMemcached( $params ) {
diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php
index 78817d0b..93d22f11 100644
--- a/includes/objectcache/SqlBagOStuff.php
+++ b/includes/objectcache/SqlBagOStuff.php
@@ -24,24 +24,24 @@ class SqlBagOStuff extends BagOStuff {
/**
* Constructor. Parameters are:
- * - server: A server info structure in the format required by each
+ * - server: A server info structure in the format required by each
* element in $wgDBServers.
*
- * - purgePeriod: The average number of object cache requests in between
- * garbage collection operations, where expired entries
- * are removed from the database. Or in other words, the
- * reciprocal of the probability of purging on any given
- * request. If this is set to zero, purging will never be
+ * - purgePeriod: The average number of object cache requests in between
+ * garbage collection operations, where expired entries
+ * are removed from the database. Or in other words, the
+ * reciprocal of the probability of purging on any given
+ * request. If this is set to zero, purging will never be
* done.
*
* - tableName: The table name to use, default is "objectcache".
*
- * - shards: The number of tables to use for data storage. If this is
- * more than 1, table names will be formed in the style
- * objectcacheNNN where NNN is the shard index, between 0 and
- * shards-1. The number of digits will be the minimum number
- * required to hold the largest shard index. Data will be
- * distributed across all tables by key hash. This is for
+ * - shards: The number of tables to use for data storage. If this is
+ * more than 1, table names will be formed in the style
+ * objectcacheNNN where NNN is the shard index, between 0 and
+ * shards-1. The number of digits will be the minimum number
+ * required to hold the largest shard index. Data will be
+ * distributed across all tables by key hash. This is for
* MySQL bugs 61735 and 61736.
*
* @param $params array
@@ -108,7 +108,7 @@ class SqlBagOStuff extends BagOStuff {
protected function getTableByShard( $index ) {
if ( $this->shards > 1 ) {
$decimals = strlen( $this->shards - 1 );
- return $this->tableName .
+ return $this->tableName .
sprintf( "%0{$decimals}d", $index );
} else {
return $this->tableName;
@@ -133,7 +133,7 @@ class SqlBagOStuff extends BagOStuff {
if ( $this->isExpired( $row->exptime ) ) {
$this->debug( "get: key has expired, deleting" );
try {
- $db->begin();
+ $db->begin( __METHOD__ );
# Put the expiry time in the WHERE condition to avoid deleting a
# newly-inserted value
$db->delete( $tableName,
@@ -141,7 +141,7 @@ class SqlBagOStuff extends BagOStuff {
'keyname' => $key,
'exptime' => $row->exptime
), __METHOD__ );
- $db->commit();
+ $db->commit( __METHOD__ );
} catch ( DBQueryError $e ) {
$this->handleWriteError( $e );
}
@@ -170,18 +170,18 @@ class SqlBagOStuff extends BagOStuff {
$encExpiry = $db->timestamp( $exptime );
}
try {
- $db->begin();
+ $db->begin( __METHOD__ );
// (bug 24425) use a replace if the db supports it instead of
// delete/insert to avoid clashes with conflicting keynames
- $db->replace(
- $this->getTableByKey( $key ),
+ $db->replace(
+ $this->getTableByKey( $key ),
array( 'keyname' ),
array(
'keyname' => $key,
'value' => $db->encodeBlob( $this->serialize( $value ) ),
'exptime' => $encExpiry
), __METHOD__ );
- $db->commit();
+ $db->commit( __METHOD__ );
} catch ( DBQueryError $e ) {
$this->handleWriteError( $e );
@@ -195,12 +195,12 @@ class SqlBagOStuff extends BagOStuff {
$db = $this->getDB();
try {
- $db->begin();
- $db->delete(
- $this->getTableByKey( $key ),
- array( 'keyname' => $key ),
+ $db->begin( __METHOD__ );
+ $db->delete(
+ $this->getTableByKey( $key ),
+ array( 'keyname' => $key ),
__METHOD__ );
- $db->commit();
+ $db->commit( __METHOD__ );
} catch ( DBQueryError $e ) {
$this->handleWriteError( $e );
@@ -216,23 +216,23 @@ class SqlBagOStuff extends BagOStuff {
$step = intval( $step );
try {
- $db->begin();
- $row = $db->selectRow(
- $tableName,
+ $db->begin( __METHOD__ );
+ $row = $db->selectRow(
+ $tableName,
array( 'value', 'exptime' ),
- array( 'keyname' => $key ),
- __METHOD__,
+ array( 'keyname' => $key ),
+ __METHOD__,
array( 'FOR UPDATE' ) );
if ( $row === false ) {
// Missing
- $db->commit();
+ $db->commit( __METHOD__ );
return null;
}
$db->delete( $tableName, array( 'keyname' => $key ), __METHOD__ );
if ( $this->isExpired( $row->exptime ) ) {
// Expired, do not reinsert
- $db->commit();
+ $db->commit( __METHOD__ );
return null;
}
@@ -245,12 +245,12 @@ class SqlBagOStuff extends BagOStuff {
'value' => $db->encodeBlob( $this->serialize( $newValue ) ),
'exptime' => $row->exptime
), __METHOD__, 'IGNORE' );
-
+
if ( $db->affectedRows() == 0 ) {
// Race condition. See bug 28611
$newValue = null;
}
- $db->commit();
+ $db->commit( __METHOD__ );
} catch ( DBQueryError $e ) {
$this->handleWriteError( $e );
@@ -265,7 +265,7 @@ class SqlBagOStuff extends BagOStuff {
$result = array();
for ( $i = 0; $i < $this->shards; $i++ ) {
- $res = $db->select( $this->getTableByShard( $i ),
+ $res = $db->select( $this->getTableByShard( $i ),
array( 'keyname' ), false, __METHOD__ );
foreach ( $res as $row ) {
$result[] = $row->keyname;
@@ -311,18 +311,67 @@ class SqlBagOStuff extends BagOStuff {
/**
* Delete objects from the database which expire before a certain date.
*/
- public function deleteObjectsExpiringBefore( $timestamp ) {
+ public function deleteObjectsExpiringBefore( $timestamp, $progressCallback = false ) {
$db = $this->getDB();
$dbTimestamp = $db->timestamp( $timestamp );
+ $totalSeconds = false;
+ $baseConds = array( 'exptime < ' . $db->addQuotes( $dbTimestamp ) );
try {
for ( $i = 0; $i < $this->shards; $i++ ) {
- $db->begin();
- $db->delete(
- $this->getTableByShard( $i ),
- array( 'exptime < ' . $db->addQuotes( $dbTimestamp ) ),
- __METHOD__ );
- $db->commit();
+ $maxExpTime = false;
+ while ( true ) {
+ $conds = $baseConds;
+ if ( $maxExpTime !== false ) {
+ $conds[] = 'exptime > ' . $db->addQuotes( $maxExpTime );
+ }
+ $rows = $db->select(
+ $this->getTableByShard( $i ),
+ array( 'keyname', 'exptime' ),
+ $conds,
+ __METHOD__,
+ array( 'LIMIT' => 100, 'ORDER BY' => 'exptime' ) );
+ if ( !$rows->numRows() ) {
+ break;
+ }
+ $keys = array();
+ $row = $rows->current();
+ $minExpTime = $row->exptime;
+ if ( $totalSeconds === false ) {
+ $totalSeconds = wfTimestamp( TS_UNIX, $timestamp )
+ - wfTimestamp( TS_UNIX, $minExpTime );
+ }
+ foreach ( $rows as $row ) {
+ $keys[] = $row->keyname;
+ $maxExpTime = $row->exptime;
+ }
+
+ $db->begin( __METHOD__ );
+ $db->delete(
+ $this->getTableByShard( $i ),
+ array(
+ 'exptime >= ' . $db->addQuotes( $minExpTime ),
+ 'exptime < ' . $db->addQuotes( $dbTimestamp ),
+ 'keyname' => $keys
+ ),
+ __METHOD__ );
+ $db->commit( __METHOD__ );
+
+ if ( $progressCallback ) {
+ if ( intval( $totalSeconds ) === 0 ) {
+ $percent = 0;
+ } else {
+ $remainingSeconds = wfTimestamp( TS_UNIX, $timestamp )
+ - wfTimestamp( TS_UNIX, $maxExpTime );
+ if ( $remainingSeconds > $totalSeconds ) {
+ $totalSeconds = $remainingSeconds;
+ }
+ $percent = ( $i + $remainingSeconds / $totalSeconds )
+ / $this->shards * 100;
+ }
+ call_user_func( $progressCallback, $percent );
+ }
+ }
}
} catch ( DBQueryError $e ) {
$this->handleWriteError( $e );
@@ -335,9 +384,9 @@ class SqlBagOStuff extends BagOStuff {
try {
for ( $i = 0; $i < $this->shards; $i++ ) {
- $db->begin();
+ $db->begin( __METHOD__ );
$db->delete( $this->getTableByShard( $i ), '*', __METHOD__ );
- $db->commit();
+ $db->commit( __METHOD__ );
}
} catch ( DBQueryError $e ) {
$this->handleWriteError( $e );
@@ -415,12 +464,12 @@ class SqlBagOStuff extends BagOStuff {
}
for ( $i = 0; $i < $this->shards; $i++ ) {
- $db->begin();
+ $db->begin( __METHOD__ );
$db->query(
'CREATE TABLE ' . $db->tableName( $this->getTableByShard( $i ) ) .
' LIKE ' . $db->tableName( 'objectcache' ),
__METHOD__ );
- $db->commit();
+ $db->commit( __METHOD__ );
}
}
}
diff --git a/includes/objectcache/eAccelBagOStuff.php b/includes/objectcache/eAccelBagOStuff.php
deleted file mode 100644
index 30d24e80..00000000
--- a/includes/objectcache/eAccelBagOStuff.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-
-/**
- * This is a wrapper for eAccelerator's shared memory functions.
- *
- * This is basically identical to the deceased Turck MMCache version,
- * mostly because eAccelerator is based on Turck MMCache.
- *
- * @ingroup Cache
- */
-class eAccelBagOStuff extends BagOStuff {
- public function get( $key ) {
- $val = eaccelerator_get( $key );
-
- if ( is_string( $val ) ) {
- $val = unserialize( $val );
- }
-
- return $val;
- }
-
- public function set( $key, $value, $exptime = 0 ) {
- eaccelerator_put( $key, serialize( $value ), $exptime );
-
- return true;
- }
-
- public function delete( $key, $time = 0 ) {
- eaccelerator_rm( $key );
-
- return true;
- }
-
- public function lock( $key, $waitTimeout = 0 ) {
- eaccelerator_lock( $key );
-
- return true;
- }
-
- public function unlock( $key ) {
- eaccelerator_unlock( $key );
-
- return true;
- }
-}
-