Skip to content
Snippets Groups Projects
Commit ddf7ba23 authored by lechuck's avatar lechuck Committed by lechuck
Browse files

Revert "Upgrade hyperdb"

This reverts commit bb731cb7.
parent d5f1bfb6
No related branches found
No related tags found
No related merge requests found
...@@ -141,12 +141,6 @@ class hyperdb extends wpdb { ...@@ -141,12 +141,6 @@ class hyperdb extends wpdb {
*/ */
var $open_connections = array(); var $open_connections = array();
/**
* Lookup array (dbhname => host:port)
* @var array
*/
var $dbh2host = array();
/** /**
* The last server used and the database name selected * The last server used and the database name selected
* @var array * @var array
...@@ -267,11 +261,10 @@ class hyperdb extends wpdb { ...@@ -267,11 +261,10 @@ class hyperdb extends wpdb {
if ( preg_match('/^\s*SELECT.*?\s+FOUND_ROWS\(\)/is', $q) ) if ( preg_match('/^\s*SELECT.*?\s+FOUND_ROWS\(\)/is', $q) )
return $this->last_table; return $this->last_table;
// SHOW TABLE STATUS and SHOW TABLES // SHOW TABLE STATUS LIKE and SHOW TABLE STATUS WHERE Name =
if ( preg_match('/^\s*(?:' if ( preg_match('/^\s*'
. 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' . 'SHOW\s+TABLE\s+STATUS.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)'
. '|SHOW\s+(?:FULL\s+)?TABLES.+(?:LIKE\s+|WHERE\s+Name\s*=\s*)' . '\W(\w+)\W/is', $q, $maybe) )
. ')\W(\w+)\W/is', $q, $maybe) )
return $maybe[1]; return $maybe[1];
// Big pattern for the rest of the table-related queries in MySQL 5.0 // Big pattern for the rest of the table-related queries in MySQL 5.0
...@@ -320,7 +313,7 @@ class hyperdb extends wpdb { ...@@ -320,7 +313,7 @@ class hyperdb extends wpdb {
* of them returns something other than null. * of them returns something other than null.
*/ */
function run_callbacks( $group, $args = null) { function run_callbacks( $group, $args = null) {
if ( !isset( $this->hyper_callbacks[ $group ] ) || !is_array( $this->hyper_callbacks[ $group ] ) ) if ( !is_array( $this->hyper_callbacks[ $group ] ) )
return null; return null;
if ( !isset($args) ) { if ( !isset($args) ) {
...@@ -343,7 +336,7 @@ class hyperdb extends wpdb { ...@@ -343,7 +336,7 @@ class hyperdb extends wpdb {
* @param string query * @param string query
* @return resource mysql database connection * @return resource mysql database connection
*/ */
function db_connect( $query = '' ) { function &db_connect( $query = '' ) {
$connect_function = $this->persistent ? 'mysql_pconnect' : 'mysql_connect'; $connect_function = $this->persistent ? 'mysql_pconnect' : 'mysql_connect';
if ( empty( $this->hyper_servers ) ) { if ( empty( $this->hyper_servers ) ) {
if ( is_resource( $this->dbh ) ) if ( is_resource( $this->dbh ) )
...@@ -392,7 +385,7 @@ class hyperdb extends wpdb { ...@@ -392,7 +385,7 @@ class hyperdb extends wpdb {
$this->dataset = $dataset; $this->dataset = $dataset;
// Determine whether the query must be sent to the master (a writable server) // Determine whether the query must be sent to the master (a writable server)
if ( !empty( $use_master ) || $this->srtm === true || isset($this->srtm[$this->table]) ) { if ( $use_master || $this->srtm === true || isset($this->srtm[$this->table]) ) {
$use_master = true; $use_master = true;
} elseif ( $is_write = $this->is_write_query($query) ) { } elseif ( $is_write = $this->is_write_query($query) ) {
$use_master = true; $use_master = true;
...@@ -400,14 +393,11 @@ class hyperdb extends wpdb { ...@@ -400,14 +393,11 @@ class hyperdb extends wpdb {
$this->srtm[$this->table] = true; $this->srtm[$this->table] = true;
} elseif ( !isset($use_master) && is_array($this->srtm) && !empty($this->srtm) ) { } elseif ( !isset($use_master) && is_array($this->srtm) && !empty($this->srtm) ) {
// Detect queries that have a join in the srtm array. // Detect queries that have a join in the srtm array.
$use_master = false; $pattern = '/' . implode('|', array_keys($this->srtm)) . '/i';
$query_match = substr( $query, 0, 1000 ); if ( preg_match($pattern, substr($query, 0, 1000)) )
foreach ( $this->srtm as $key => $value ) {
if ( false !== stripos( $query_match, $key ) ) {
$use_master = true; $use_master = true;
break; else
} $use_master = false;
}
} else { } else {
$use_master = false; $use_master = false;
} }
...@@ -421,7 +411,7 @@ class hyperdb extends wpdb { ...@@ -421,7 +411,7 @@ class hyperdb extends wpdb {
} }
// Try to reuse an existing connection // Try to reuse an existing connection
while ( isset( $this->dbhs[$dbhname] ) && is_resource( $this->dbhs[$dbhname] ) ) { while ( is_resource($this->dbhs[$dbhname]) ) {
// Find the connection for incrementing counters // Find the connection for incrementing counters
foreach ( array_keys($this->db_connections) as $i ) foreach ( array_keys($this->db_connections) as $i )
if ( $this->db_connections[$i]['dbhname'] == $dbhname ) if ( $this->db_connections[$i]['dbhname'] == $dbhname )
...@@ -433,11 +423,7 @@ class hyperdb extends wpdb { ...@@ -433,11 +423,7 @@ class hyperdb extends wpdb {
if ( $name != $this->used_servers[$dbhname]['name'] ) { if ( $name != $this->used_servers[$dbhname]['name'] ) {
if ( !mysql_select_db($name, $this->dbhs[$dbhname]) ) { if ( !mysql_select_db($name, $this->dbhs[$dbhname]) ) {
// this can happen when the user varies and lacks permission on the $name database // this can happen when the user varies and lacks permission on the $name database
if ( isset( $conn['disconnect (select failed)'] ) )
++$conn['disconnect (select failed)']; ++$conn['disconnect (select failed)'];
else
$conn['disconnect (select failed)'] = 1;
$this->disconnect($dbhname); $this->disconnect($dbhname);
break; break;
} }
...@@ -459,24 +445,17 @@ class hyperdb extends wpdb { ...@@ -459,24 +445,17 @@ class hyperdb extends wpdb {
$this->last_connection = compact('dbhname', 'name'); $this->last_connection = compact('dbhname', 'name');
if ( !mysql_ping($this->dbhs[$dbhname]) ) { if ( !mysql_ping($this->dbhs[$dbhname]) ) {
if ( isset( $conn['disconnect (ping failed)'] ) )
++$conn['disconnect (ping failed)']; ++$conn['disconnect (ping failed)'];
else
$conn['disconnect (ping failed)'] = 1;
$this->disconnect($dbhname); $this->disconnect($dbhname);
break; break;
} }
if ( isset( $conn['queries'] ) )
++$conn['queries']; ++$conn['queries'];
else
$conn['queries'] = 1;
return $this->dbhs[$dbhname]; return $this->dbhs[$dbhname];
} }
if ( $use_master && defined( "MASTER_DB_DEAD" ) ) { if ( $this->write && defined( "MASTER_DB_DEAD" ) ) {
return $this->bail("We're updating the database, please try back in 5 minutes. If you are posting to your blog please hit the refresh button on your browser in a few minutes to post the data again. It will be posted as soon as the database is back online again."); return $this->bail("We're updating the database, please try back in 5 minutes. If you are posting to your blog please hit the refresh button on your browser in a few minutes to post the data again. It will be posted as soon as the database is back online again.");
} }
...@@ -521,7 +500,8 @@ class hyperdb extends wpdb { ...@@ -521,7 +500,8 @@ class hyperdb extends wpdb {
// $host, $user, $password, $name, $read, $write [, $lag_threshold, $connect_function, $timeout ] // $host, $user, $password, $name, $read, $write [, $lag_threshold, $connect_function, $timeout ]
extract($this->hyper_servers[$dataset][$operation][$group][$key], EXTR_OVERWRITE); extract($this->hyper_servers[$dataset][$operation][$group][$key], EXTR_OVERWRITE);
$port = null;
list($host, $port) = explode(':', $host);
// Split host:port into $host and $port // Split host:port into $host and $port
if ( strpos($host, ':') ) if ( strpos($host, ':') )
...@@ -563,7 +543,7 @@ class hyperdb extends wpdb { ...@@ -563,7 +543,7 @@ class hyperdb extends wpdb {
{ {
$this->lag_threshold = null; $this->lag_threshold = null;
} else { } else {
$unique_lagged_slaves["$host:$port"] = $this->lag; $unique_lagged_slaves["$host.$port"] = $this->lag;
continue; continue;
} }
} }
...@@ -610,7 +590,8 @@ class hyperdb extends wpdb { ...@@ -610,7 +590,8 @@ class hyperdb extends wpdb {
$this->dbh2host[$dbhname] = "$host:$port"; $this->dbh2host[$dbhname] = "$host:$port";
$queries = 1; $queries = 1;
$lag = isset( $this->lag ) ? $this->lag : 0; $lag = isset( $this->lag ) ? $this->lag : 0;
$this->last_connection = compact('dbhname', 'host', 'port', 'user', 'name', 'tcp', 'elapsed', 'success', 'queries', 'lag'); $this->last_connection = compact('dbhname', 'host', 'port', 'user', 'name', 'tcp', 'elapsed', 'success', 'querie
s', 'lag');
$this->db_connections[] = $this->last_connection; $this->db_connections[] = $this->last_connection;
$this->open_connections[] = $dbhname; $this->open_connections[] = $dbhname;
break; break;
...@@ -620,6 +601,7 @@ class hyperdb extends wpdb { ...@@ -620,6 +601,7 @@ class hyperdb extends wpdb {
$success = false; $success = false;
$this->last_connection = compact('dbhname', 'host', 'port', 'user', 'name', 'tcp', 'elapsed', 'success'); $this->last_connection = compact('dbhname', 'host', 'port', 'user', 'name', 'tcp', 'elapsed', 'success');
$this->db_connections[] = $this->last_connection; $this->db_connections[] = $this->last_connection;
$msg = date( "Y-m-d H:i:s" ) . " Can't select $dbhname - \n"; $msg = date( "Y-m-d H:i:s" ) . " Can't select $dbhname - \n";
$msg .= "'referrer' => '{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}',\n"; $msg .= "'referrer' => '{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}',\n";
$msg .= "'server' => {$server},\n"; $msg .= "'server' => {$server},\n";
...@@ -656,12 +638,6 @@ class hyperdb extends wpdb { ...@@ -656,12 +638,6 @@ class hyperdb extends wpdb {
break; break;
} while ( true ); } while ( true );
if ( !isset( $charset ) )
$charset = null;
if ( !isset( $collate ) )
$collate = null;
$this->set_charset($this->dbhs[$dbhname], $charset, $collate); $this->set_charset($this->dbhs[$dbhname], $charset, $collate);
$this->dbh = $this->dbhs[$dbhname]; // needed by $wpdb->_real_escape() $this->dbh = $this->dbhs[$dbhname]; // needed by $wpdb->_real_escape()
...@@ -926,38 +902,10 @@ class hyperdb extends wpdb { ...@@ -926,38 +902,10 @@ class hyperdb extends wpdb {
* @return (bool) true when $host:$post responds within $float_timeout seconds, else (bool) false * @return (bool) true when $host:$post responds within $float_timeout seconds, else (bool) false
*/ */
function check_tcp_responsiveness($host, $port, $float_timeout) { function check_tcp_responsiveness($host, $port, $float_timeout) {
if ( function_exists( 'apc_store' ) ) {
$use_apc = true;
$apc_key = "{$host}{$port}";
$apc_ttl = 10;
} else {
$use_apc = false;
}
if ( $use_apc ) {
$cached_value = apc_fetch( $apc_key );
switch ( $cached_value ) {
case 'up':
$this->tcp_responsive = 'true';
return true;
case 'down':
$this->tcp_responsive = 'false';
return false;
}
}
$socket = @ fsockopen($host, $port, $errno, $errstr, $float_timeout); $socket = @ fsockopen($host, $port, $errno, $errstr, $float_timeout);
if ( $socket === false ) { if ( $socket === false )
if ( $use_apc )
apc_store( $apc_key, 'down', $apc_ttl );
return "[ > $float_timeout ] ($errno) '$errstr'"; return "[ > $float_timeout ] ($errno) '$errstr'";
}
fclose($socket); fclose($socket);
if ( $use_apc )
apc_store( $apc_key, 'up', $apc_ttl );
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment