debug log group for DNS blacklist lookup results
[lhc/web/wiklou.git] / includes / objectcache / SqlBagOStuff.php
index e504887..5ad7020 100644 (file)
@@ -87,25 +87,34 @@ class SqlBagOStuff extends BagOStuff {
         * @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;
@@ -113,6 +122,7 @@ class SqlBagOStuff extends BagOStuff {
 
        /**
         * Get the table name for a given key
+        * @param $key string
         * @return string
         */
        protected function getTableByKey( $key ) {
@@ -126,6 +136,7 @@ class SqlBagOStuff extends BagOStuff {
 
        /**
         * Get the table name for a given shard index
+        * @param $index int
         * @return string
         */
        protected function getTableByShard( $index ) {
@@ -138,11 +149,19 @@ class SqlBagOStuff extends BagOStuff {
                }
        }
 
+       /**
+        * @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)
 
@@ -199,6 +218,12 @@ class SqlBagOStuff extends BagOStuff {
                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 );
@@ -238,6 +263,11 @@ class SqlBagOStuff extends BagOStuff {
                return true;
        }
 
+       /**
+        * @param $key string
+        * @param $time int
+        * @return bool
+        */
        public function delete( $key, $time = 0 ) {
                $db = $this->getDB();
 
@@ -257,6 +287,11 @@ class SqlBagOStuff extends BagOStuff {
                return true;
        }
 
+       /**
+        * @param $key string
+        * @param $step int
+        * @return int|null
+        */
        public function incr( $key, $step = 1 ) {
                $db = $this->getDB();
                $tableName = $this->getTableByKey( $key );
@@ -307,6 +342,9 @@ class SqlBagOStuff extends BagOStuff {
                return $newValue;
        }
 
+       /**
+        * @return Array
+        */
        public function keys() {
                $db = $this->getDB();
                $result = array();
@@ -322,10 +360,17 @@ class SqlBagOStuff extends BagOStuff {
                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 );
@@ -357,6 +402,8 @@ class SqlBagOStuff extends BagOStuff {
 
        /**
         * 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 ) {