* @ingroup Cache
*/
class SqlBagOStuff extends BagOStuff {
+ /** @var LoadBalancer */
+ protected $lb;
+
protected $serverInfos;
/** @var array */
$db = DatabaseBase::factory( $type, $info );
$db->clearFlag( DBO_TRX );
} else {
- // We must keep a separate connection to MySQL in order to avoid deadlocks
- // However, SQLite has an opposite behavior.
- // @todo get this trick to work on PostgreSQL too
+ /*
+ * We must keep a separate connection to MySQL in order to avoid deadlocks
+ * However, SQLite has an opposite behavior. And PostgreSQL needs to know
+ * if we are in transaction or no
+ */
if ( wfGetDB( DB_MASTER )->getType() == 'mysql' ) {
- $lb = wfGetLBFactory()->newMainLB();
- $db = $lb->getConnection( DB_MASTER );
+ $this->lb = wfGetLBFactory()->newMainLB();
+ $db = $this->lb->getConnection( DB_MASTER );
$db->clearFlag( DBO_TRX ); // auto-commit mode
} else {
$db = wfGetDB( DB_MASTER );
if ( $exptime == 0 ) {
$encExpiry = $this->getMaxDateTime( $db );
} else {
- if ( $exptime < 3.16e8 ) { # ~10 years
- $exptime += time();
- }
+ $exptime = $this->convertExpiry( $exptime );
$encExpiry = $db->timestamp( $exptime );
}
foreach ( $serverKeys as $tableName => $tableKeys ) {
if ( $exptime == 0 ) {
$encExpiry = $this->getMaxDateTime( $db );
} else {
- if ( $exptime < 3.16e8 ) { # ~10 years
- $exptime += time();
- }
-
+ $exptime = $this->convertExpiry( $exptime );
$encExpiry = $db->timestamp( $exptime );
}
// (bug 24425) use a replace if the db supports it instead of
if ( $exptime == 0 ) {
$encExpiry = $this->getMaxDateTime( $db );
} else {
- if ( $exptime < 3.16e8 ) { # ~10 years
- $exptime += time();
- }
+ $exptime = $this->convertExpiry( $exptime );
$encExpiry = $db->timestamp( $exptime );
}
// (bug 24425) use a replace if the db supports it instead of
}
/**
+ * @param DatabaseBase $db
* @param string $exptime
* @return bool
*/
if ( $remainingSeconds > $totalSeconds ) {
$totalSeconds = $remainingSeconds;
}
- $percent = ( $i + $remainingSeconds / $totalSeconds )
+ $processedSeconds = $totalSeconds - $remainingSeconds;
+ $percent = ( $i + $processedSeconds / $totalSeconds )
/ $this->shards * 100;
}
$percent = ( $percent / $this->numServers )
return true;
}
+ /**
+ * Delete content of shard tables in every server.
+ * Return true if the operation is successful, false otherwise.
+ * @return bool
+ */
public function deleteAll() {
for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
try {