Commit cf68b44d authored by samba's avatar samba

use dbconf from ai3/docker/noblogs

parent 08ae3b7d
......@@ -12,7 +12,7 @@ include_once('r2db/db-hash.php');
include_once('r2db/db-backends.php');
// Set up global dataset with master databases
noblogs_load_global_dataset(NOBLOGS_MASTER_CONFIG, NOBLOGS_HOST_FILE);
noblogs_load_global_dataset();
// Add all the sharded blog databases.
$wpdb_reverse_backend_map = noblogs_load_backends(NOBLOGS_BACKEND_CONFIG, $wpdb->hash_map);
$wpdb_reverse_backend_map = noblogs_load_backends($wpdb->hash_map);
<?php
function noblogs_split_db($file) {
$db_url = trim(file_get_contents($file));
return parse_url($db_url);
}
// Common settings
$wpdb->persistent = true;
$wpdb->max_connections = 30;
function noblogs_load_backends($db_config_file, $hashptr) {
global $wpdb;
/* Disable responsiveness check, is not needed in our configuration and is causing
connection errors for the wrong implementation */
$wpdb->check_tcp_responsiveness = false;
$backend_map = array();
include_once('r2db/db-hash.php');
include_once('r2db/db-backends.php');
$fp = @fopen($db_config_file, "r");
if (!$fp) {
die("Database backends not configured!");
}
while (($line = fgets($fp, 1024)) !== false) {
$wline = rtrim($line);
if ($wline == "" || $wline[0] == '#') {
continue;
}
$line_parts = explode(" ", $wline);
$server_id = $line_parts[0];
$dataset = "backend_" . $server_id;
$backend_url = $line_parts[2];
$backend_url_data = parse_url($backend_url);
$backend = array(
"host" => $backend_url_data["host"] . ":" . $backend_url_data["port"],
"user" => $backend_url_data["user"],
"password" => $backend_url_data["pass"],
"name" => substr($backend_url_data["path"], 1),
"dataset" => $dataset,
"read" => 1, "write" => 1, "timeout" => 10
);
$wpdb->add_database($backend);
$hashptr->addTarget($dataset);
$backend_map[$dataset] = $backend;
}
fclose($fp);
return $backend_map;
}
// Set up global dataset with master databases
noblogs_load_global_dataset();
function noblogs_load_global_dataset($master_file, $ip_file) {
global $wpdb;
$mdata = noblogs_split_db($master_file);
$ldata = trim(file_get_contents($ip_file));
$globaldb = array(
"host" => $mdata["host"] . ":" . $mdata["port"],
"user" => $mdata["user"],
"password" => $mdata["pass"],
"name" => substr($mdata["path"], 1),
"dataset" => "global",
"read" => 1, "write" => 1, "timeout" => 2
);
if ($mdata['host'] == $ldata) {
$wpdb->add_database($globaldb);
} else {
$globaldb['read'] = 0;
$wpdb->add_database($globaldb);
$globaldb['host'] = $ldata . ":" . $mdata["port"];
$globaldb['read'] = 1;
$globaldb['write'] = 0;
$wpdb->add_database($globaldb);
}
}
// Add all the sharded blog databases.
$wpdb_reverse_backend_map = noblogs_load_backends($wpdb->hash_map);
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