* @return DatabaseBase
*/
protected function getDB() {
+ global $wgDebugDBTransactions;
if ( !isset( $this->db ) ) {
# If server connection info was given, use that
if ( $this->serverInfo ) {
+ if ( $wgDebugDBTransactions ) {
+ wfDebug( sprintf( "Using provided serverInfo for SqlBagOStuff\n" ) );
+ }
$this->lb = new LoadBalancer( array(
'servers' => array( $this->serverInfo ) ) );
$this->db = $this->lb->getConnection( DB_MASTER );
$this->db->clearFlag( DBO_TRX );
} else {
- # We must keep a separate connection to MySQL in order to avoid deadlocks
- # However, SQLite has an opposite behaviour.
- # @todo Investigate behaviour for other databases
- if ( wfGetDB( DB_MASTER )->getType() == 'sqlite' ) {
- $this->db = wfGetDB( DB_MASTER );
- } else {
+ /*
+ * We must keep a separate connection to MySQL in order to avoid deadlocks
+ * However, SQLite has an opposite behaviour. And PostgreSQL needs to know
+ * if we are in transaction or no
+ */
+ if ( wfGetDB( DB_MASTER )->getType() == 'mysql' ) {
$this->lb = wfGetLBFactory()->newMainLB();
$this->db = $this->lb->getConnection( DB_MASTER );
$this->db->clearFlag( DBO_TRX );
+ } else {
+ $this->db = wfGetDB( DB_MASTER );
}
}
+ if ( $wgDebugDBTransactions ) {
+ wfDebug( sprintf( "Connection %s will be used for SqlBagOStuff\n", $this->db ) );
+ }
}
return $this->db;
/**
* Get the table name for a given key
+ * @param $key string
* @return string
*/
protected function getTableByKey( $key ) {
/**
* Get the table name for a given shard index
+ * @param $index int
* @return string
*/
protected function getTableByShard( $index ) {
}
}
+ /**
+ * @param $key string
+ * @return mixed
+ */
public function get( $key ) {
$values = $this->getMulti( array( $key ) );
return $values[$key];
}
+ /**
+ * @param $keys array
+ * @return Array
+ */
public function getMulti( array $keys ) {
$values = array(); // array of (key => value)
return $values;
}
+ /**
+ * @param $key string
+ * @param $value mixed
+ * @param $exptime int
+ * @return bool
+ */
public function set( $key, $value, $exptime = 0 ) {
$db = $this->getDB();
$exptime = intval( $exptime );
return true;
}
+ /**
+ * @param $key string
+ * @param $time int
+ * @return bool
+ */
public function delete( $key, $time = 0 ) {
$db = $this->getDB();
return true;
}
+ /**
+ * @param $key string
+ * @param $step int
+ * @return int|null
+ */
public function incr( $key, $step = 1 ) {
$db = $this->getDB();
$tableName = $this->getTableByKey( $key );
return $newValue;
}
+ /**
+ * @return Array
+ */
public function keys() {
$db = $this->getDB();
$result = array();
return $result;
}
+ /**
+ * @param $exptime string
+ * @return bool
+ */
protected function isExpired( $exptime ) {
return $exptime != $this->getMaxDateTime() && wfTimestamp( TS_UNIX, $exptime ) < time();
}
+ /**
+ * @return string
+ */
protected function getMaxDateTime() {
if ( time() > 0x7fffffff ) {
return $this->getDB()->timestamp( 1 << 62 );
/**
* Delete objects from the database which expire before a certain date.
+ * @param $timestamp string
+ * @param $progressCallback bool|callback
* @return bool
*/
public function deleteObjectsExpiringBefore( $timestamp, $progressCallback = false ) {