Factored setTimeout() into setSessionOptions() and deprecated the former. In the...
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 23 Nov 2011 19:25:59 +0000 (19:25 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 23 Nov 2011 19:25:59 +0000 (19:25 +0000)
includes/db/Database.php
includes/db/DatabaseMysql.php

index 8dc2a9e..ac2f159 100644 (file)
@@ -2994,14 +2994,28 @@ abstract class DatabaseBase implements DatabaseType {
        }
 
        /**
-        * Override database's default connection timeout.  May be useful for very
-        * long batch queries such as full-wiki dumps, where a single query reads
-        * out over hours or days.  May or may not be necessary for non-MySQL
-        * databases.  For most purposes, leaving it as a no-op should be fine.
+        * Override database's default connection timeout
         *
         * @param $timeout Integer in seconds
+        * @return void
+        * @deprecated since 1.19; use setSessionOptions()
         */
-       public function setTimeout( $timeout ) {}
+       public function setTimeout( $timeout ) {
+               $this->setSessionOptions( array( 'connTimeout' => $timeout ) );
+       }
+
+       /**
+        * Override database's default behavior. $options include:
+        *     'connTimeout' : Set the connection timeout value in seconds.
+        *                     May be useful for very long batch queries such as
+        *                     full-wiki dumps, where a single query reads out over
+        *                     hours or days.
+        *     'lockTimeout' : Set the lock wait timeout value in seconds.
+        *
+        * @param $options Array
+        * @return void
+        */
+       public function setSessionOptions( array $options ) {}
 
        /**
         * Read and execute SQL commands from a file.
index 22810ab..3a93e0f 100644 (file)
@@ -602,9 +602,17 @@ class DatabaseMysql extends DatabaseBase {
                return false;
        }
 
-       public function setTimeout( $timeout ) {
-               $this->query( "SET net_read_timeout=$timeout" );
-               $this->query( "SET net_write_timeout=$timeout" );
+       public function setSessionOptions( array $options ) {
+               if ( isset( $options['connTimeout'] ) ) {
+                       $timeout = (int)$options['connTimeout'];
+                       $this->query( "SET net_read_timeout=$timeout" );
+                       $this->query( "SET net_write_timeout=$timeout" );
+               }
+               if ( isset( $options['lockTimeout'] ) ) {
+                       $timeout = (int)$options['lockTimeout'];
+                       $this->query( "SET table_lock_wait_timeout=$timeout" ); // table level
+                       $this->query( "SET innodb_lock_wait_timeout=$timeout" ); // row level
+               }
        }
 
        public function lock( $lockName, $method, $timeout = 5 ) {