Commit 0b7b389d authored by root's avatar root Committed by lechuck

a few fixes to the global wpdb_hash instance (moved into $wpdb)

parent b32dd9d8
<?php
// Common settings
$wpdb->save_queries = false;
$wpdb->persistent = false;
$wpdb->max_connections = 30;
define("NOBLOGS_BACKEND_CONFIG", "/etc/noblogs/backends");
require_once('r2db/db-hash.php');
require_once('r2db/db-backends.php');
include_once('r2db/db-hash.php');
include_once('r2db/db-backends.php');
// Add the global database (configured in wp-config.php), stores the global
// blogs and users tables.
......@@ -16,5 +21,5 @@ $wpdb->add_database(array(
"write" => 1, "read" => 1, "timeout" => 2
));
$wpdb_reverse_backend_map = noblogs_load_backends(NOBLOGS_BACKEND_CONFIG, $wpdb_hash);
$wpdb_reverse_backend_map = noblogs_load_backends(NOBLOGS_BACKEND_CONFIG, $wpdb->hash_map);
<?php
function noblogs_load_backends($db_config_file, &$hashptr) {
function noblogs_load_backends($db_config_file, $hashptr) {
global $wpdb;
$backend_map = array();
......
<?php
require_once('flexihash.php');
require_once(dirname(__FILE__) . '/flexihash.php');
$wpdb_hash = new Flexihash();
$wpdb->hash_map = new Flexihash();
/* Hashing function to map blogs to databases.
*
* Implements a consistent hashing scheme using Flexihash.
*/
function noblogs_db_callback($query, $wpdb) {
global $wpdb_hash;
$wpdb_hash = $wpdb->hash_map;
if (preg_match("/^{$wpdb->base_prefix}(\d+)_/", $wpdb->table, $matches)) {
$blog_id = $matches[1];
return $wpdb_hash->lookup($blog_id);
......
......@@ -5,7 +5,7 @@
define('WP_CACHE',false);
/** Setup WordPress environment */
require_once('wp-load.php');
require_once('db-config-new.php');
require_once('db-config.php');
function old_hash($dbid) {
......@@ -24,11 +24,10 @@ function old_hash($dbid) {
}
}
function new_hash($dbid) {
global $wpdb_hash;
global $wpdb_reverse_backend_map;
$lookup = $wpdb_hash->lookup($dbid);
$backend = $wpdb_reverse_backend_map[$lookup];
function new_hash($dbid, $reversemap) {
global $wpdb;
$lookup = $wpdb->hash_map->lookup($dbid);
$backend = $reversemap[$lookup];
$result = array();
if (preg_match('/^(.*):([0-9]*)$/', $backend['host'], $matches)) {
$result['host'] = $matches[1];
......@@ -54,11 +53,15 @@ function get_all_blogs()
{
global $wpdb;
$sql = "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE public = 1 AND deleted = 0 AND archived = '0' ORDER BY domain, path";
// $sql = "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE public = 1 AND deleted = 0 AND archived = '0' ORDER BY domain, path";
$sql = "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE public = 0 ORDER BY domain, path";
$result = $wpdb->get_results($sql);
return ($result);
}
$hashmap = new Flexihash();
$reverse_backend_map = noblogs_load_backends(NOBLOGS_BACKEND_CONFIG, $hashmap);
$new_counts = array();
$moved_count = 0;
$blogs = get_all_blogs();
......@@ -67,7 +70,7 @@ foreach ($blogs as $blog) {
$old_params = old_hash($blog_id);
$old_dburi = mysqlurl($old_params);
$new_params = new_hash($blog_id);
$new_params = new_hash($blog_id, $reverse_backend_map);
$new_dburi = mysqlurl($new_params);
if ($new_counts[$new_params['host']]) {
......
......@@ -40,6 +40,13 @@ define( 'HYPERDB_LAG_BEHIND', 2 );
define( 'HYPERDB_LAG_UNKNOWN', 3 );
class hyperdb extends wpdb {
/**
* A/I patch!
* store a FlexiHash() instance here.
*/
var $hash_map;
/**
* The last table that was queried
* @var string
......
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