Commit ffecab9e authored by joe's avatar joe Committed by lechuck

Added optional logging

parent 200f555f
......@@ -35,7 +35,7 @@ if ( defined('DB_CONFIG_FILE') && file_exists( DB_CONFIG_FILE ) ) {
}
/**
* Common definitions
* Common definitions
*/
define( 'HYPERDB_LAG_OK', 1 );
define( 'HYPERDB_LAG_BEHIND', 2 );
......@@ -44,7 +44,7 @@ define( 'HYPERDB_LAG_UNKNOWN', 3 );
class hyperdb extends wpdb {
/**
* A/I patch!
* A/I patch!
* store a FlexiHash() instance here.
*/
var $hash_map;
......@@ -244,7 +244,7 @@ class hyperdb extends wpdb {
/**
* Add a callback to a group of callbacks.
* The default group is 'dataset', used to examine
* The default group is 'dataset', used to examine
* queries and determine dataset.
*/
function add_callback( $callback, $group = 'dataset' ) {
......@@ -483,7 +483,7 @@ class hyperdb extends wpdb {
break;
}
if ( isset( $conn['queries'] ) )
if ( isset( $conn['queries'] ) )
++$conn['queries'];
else
$conn['queries'] = 1;
......@@ -507,13 +507,13 @@ class hyperdb extends wpdb {
foreach ( $this->hyper_servers[$dataset][$operation] as $group => $items ) {
$keys = array_keys($items);
shuffle($keys);
foreach ( $keys as $key )
foreach ( $keys as $key )
$servers[] = compact('group', 'key');
}
if ( !$tries_remaining = count( $servers ) )
if ( !$tries_remaining = count( $servers ) )
return $this->bail("No database servers were found to match the query. ($this->table, $dataset)");
if ( !isset( $unique_servers ) )
$unique_servers = $tries_remaining;
......@@ -525,8 +525,8 @@ class hyperdb extends wpdb {
$success = false;
foreach ( $servers as $group_key ) {
--$tries_remaining;
--$tries_remaining;
// If all servers are lagged, we need to start ignoring the lag and retry
if ( count( $unique_lagged_slaves ) == $unique_servers )
break;
......@@ -590,7 +590,7 @@ class hyperdb extends wpdb {
if ( $use_master || !$tries_remaining || !$this->check_tcp_responsiveness
|| true === $tcp = $this->check_tcp_responsiveness($host, $port, $timeout) )
{
$this->dbhs[$dbhname] = @ $connect_function( "$host:$port", $user, $password, true );
$this->dbhs[$dbhname] = @ $connect_function( "$host:$port", $user, $password, true );
} else {
$this->dbhs[$dbhname] = false;
}
......@@ -635,20 +635,23 @@ class hyperdb extends wpdb {
$success = false;
$this->last_connection = compact('dbhname', 'host', 'port', 'user', 'name', 'tcp', 'elapsed', 'success');
$this->db_connections[] = $this->last_connection;
$msg = date( "Y-m-d H:i:s" ) . " Can't select $dbhname - \n";
$msg .= "'referrer' => '{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}',\n";
$msg .= "'server' => {$server},\n";
$msg .= "'host' => {$host},\n";
$msg .= "'error' => " . mysql_error() . ",\n";
$msg .= "'errno' => " . mysql_errno() . ",\n";
$msg .= "'tcp_responsive' => " . ( $tcp === true ? 'true' : $tcp ) . ",\n";
$msg .= "'lagged_status' => " . ( isset( $lagged_status ) ? $lagged_status : HYPERDB_LAG_UNKNOWN );
$this->print_error( $msg );
/* Workaround to stop logging a/i */
if ( AI_LOG_HYPERDB == true ) {
$msg = date( "Y-m-d H:i:s" ) . " Can't select $dbhname - \n";
$msg .= "'referrer' => '{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}',\n";
$msg .= "'server' => {$server},\n";
$msg .= "'host' => {$host},\n";
$msg .= "'error' => " . mysql_error() . ",\n";
$msg .= "'errno' => " . mysql_errno() . ",\n";
$msg .= "'tcp_responsive' => " . ( $tcp === true ? 'true' : $tcp ) . ",\n";
$msg .= "'lagged_status' => " . ( isset( $lagged_status ) ? $lagged_status : HYPERDB_LAG_UNKNOWN );
$this->print_error( $msg );
}
}
if ( !$success || !isset($this->dbhs[$dbhname]) || !is_resource( $this->dbhs[$dbhname] ) ) {
if ( !isset( $ignore_slave_lag ) && count( $unique_lagged_slaves ) ) {
if ( !isset( $ignore_slave_lag ) && count( $unique_lagged_slaves ) ) {
// Lagged slaves were not used. Ignore the lag for this connection attempt and retry.
$ignore_slave_lag = true;
$tries_remaining = count( $servers );
......@@ -671,15 +674,15 @@ class hyperdb extends wpdb {
break;
} while ( true );
if ( !isset( $charset ) )
if ( !isset( $charset ) )
$charset = null;
if ( !isset( $collate ) )
$collate = null;
$this->set_charset($this->dbhs[$dbhname], $charset, $collate);
if ( !isset( $charset ) )
if ( !isset( $charset ) )
$charset = null;
if ( !isset( $collate ) )
......@@ -783,7 +786,7 @@ class hyperdb extends wpdb {
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/') !== false) {
$query .= ' /* NO CACHE */';
}
$this->timer_start();
$this->result = mysql_query($query, $this->dbh);
$elapsed = $this->timer_stop();
......@@ -1013,7 +1016,7 @@ class hyperdb extends wpdb {
}
// Helper functions for configuration
} // class hyperdb
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment