Commit 5a8c6c59 authored by ale's avatar ale Committed by agata

support split master/slave backends for the primary database

parent e35e07c9
......@@ -5,19 +5,26 @@ $wpdb->persistent = true;
$wpdb->max_connections = 30;
define("NOBLOGS_BACKEND_CONFIG", "/etc/noblogs/backends");
define("NOBLOGS_MASTER_CONFIG", "/etc/noblogs/master");
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.
// This is the read-only slave.
$wpdb->add_database(array(
"host" => DB_HOST,
"user" => DB_USER,
"password" => DB_PASSWORD,
"name" => DB_NAME,
"dataset" => "global",
"write" => 1, "read" => 1, "timeout" => 2
"write" => 0, "read" => 1, "timeout" => 2
));
// This is the write-only master.
$wpdb->add_database(noblogs_load_master(NOBLOGS_MASTER_CONFIG));
// Add all the sharded blog databases.
$wpdb_reverse_backend_map = noblogs_load_backends(NOBLOGS_BACKEND_CONFIG, $wpdb->hash_map);
......@@ -25,7 +25,7 @@ function noblogs_load_backends($db_config_file, $hashptr) {
"password" => $backend_url_data["pass"],
"name" => substr($backend_url_data["path"], 1),
"dataset" => $dataset,
"read" => 1, "write" => 1, "timeout" => 2
"read" => 1, "write" => 1, "timeout" => 10
);
$wpdb->add_database($backend);
$hashptr->addTarget($dataset);
......@@ -34,3 +34,17 @@ function noblogs_load_backends($db_config_file, $hashptr) {
fclose($fp);
return $backend_map;
}
function noblogs_load_master($master_file) {
$master_url = trim(file_get_contents($master_file));
$mdata = parse_url($master_url);
return array(
"host" => $mdata["host"] . ":" . $mdata["port"],
"user" => $mdata["user"],
"password" => $mdata["pass"],
"name" => substr($mdata["path"], 1),
"dataset" => "global",
"read" => 0, "write" => 1, "timeout" => 10
);
}
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