- back end: allow the specification of a read-only DB replica

(in config.xml) to include DB name, user, and password.
- back end: add read-only replica info to SCHED_CONFIG,
    so that C++ programs can use the replica
    (currently only PHP code can use it)
- db_dump: use the read-only DB replica if it exists.


svn path=/trunk/boinc/; revision=22958
This commit is contained in:
David Anderson 2011-01-28 22:03:46 +00:00
parent b72572be1b
commit 43a3036101
6 changed files with 401 additions and 352 deletions

View File

@ -343,3 +343,17 @@ Charlie 28 Jan 2011
boinc.xcodeproj/
project.pbxproj
David 28 Jan 2011
- back end: allow the specification of a read-only DB replica
(in config.xml) to include DB name, user, and password.
- back end: add read-only replica info to SCHED_CONFIG,
so that C++ programs can use the replica
(currently only PHP code can use it)
- db_dump: use the read-only DB replica if it exists.
html/inc/
boinc_db.inc
db.inc
sched/
sched_config.cpp,h
db_dump.cpp

View File

@ -40,6 +40,12 @@ class BoincDb extends DbConn {
}
$instance = new DbConn();
if ($readonly && $replica_host) {
$x = parse_config($config, '<replica_db_user>');
if ($x) $user = $x;
$x = parse_config($config, '<replica_db_passwd>');
if ($x) $passwd = $x;
$x = parse_config($config, '<replica_db_name>');
if ($x) $name = $x;
$retval = $instance->init_conn($user, $passwd, $replica_host, $name);
if ($retval) {
self::$instance = $instance;

View File

@ -26,9 +26,19 @@ function db_init_aux($try_replica=false) {
$config = get_config();
$user = parse_config($config, "<db_user>");
$pass = parse_config($config, "<db_passwd>");
$db_name = parse_config($config, "<db_name>");
$host = null;
if ($try_replica == true) {
$host = parse_config($config, "<replica_db_host>");
if ($try_replica) {
$x = parse_config($config, "<replica_db_host>");
if ($x) {
$host = $x;
$x = parse_config($config, "<replica_db_user>");
if ($x) $user = $x;
$x = parse_config($config, "<replica_db_passwd>");
if ($x) $pass = $x;
$x = parse_config($config, "<replica_db_name>");
if ($x) $db_name = $x;
}
}
if ($host == null) {
$host = parse_config($config, "<db_host>");
@ -40,7 +50,6 @@ function db_init_aux($try_replica=false) {
if (!$link) {
return 1;
}
$db_name = parse_config($config, "<db_name>");
if (!mysql_select_db($db_name, $link)) {
echo "selecting $db_name\n";
return 2;

View File

@ -838,10 +838,10 @@ int main(int argc, char** argv) {
exit(1);
}
retval = boinc_db.open(
config.db_name,
db_host?db_host:config.db_host,
config.db_user,
config.db_passwd
config.replica_db_name,
db_host?db_host:config.replica_db_host,
config.replica_db_user,
config.replica_db_passwd
);
if (retval) {
log_messages.printf(MSG_CRITICAL, "Can't open DB\n");

View File

@ -101,6 +101,18 @@ int SCHED_CONFIG::parse(FILE* f) {
char hostname[256];
gethostname(hostname, 256);
if (!strcmp(hostname, db_host)) strcpy(db_host, "localhost");
if (!strlen(replica_db_host)) {
strcpy(replica_db_host, db_host);
}
if (!strlen(replica_db_name)) {
strcpy(replica_db_name, db_name);
}
if (!strlen(replica_db_user)) {
strcpy(replica_db_user, db_user);
}
if (!strlen(replica_db_passwd)) {
strcpy(replica_db_passwd, db_passwd);
}
return 0;
}
if (xp.parse_str(tag, "master_url", master_url, sizeof(master_url))) continue;
@ -109,6 +121,10 @@ int SCHED_CONFIG::parse(FILE* f) {
if (xp.parse_str(tag, "db_user", db_user, sizeof(db_user))) continue;
if (xp.parse_str(tag, "db_passwd", db_passwd, sizeof(db_passwd))) continue;
if (xp.parse_str(tag, "db_host", db_host, sizeof(db_host))) continue;
if (xp.parse_str(tag, "replica_db_name", replica_db_name, sizeof(replica_db_name))) continue;
if (xp.parse_str(tag, "replica_db_user", replica_db_user, sizeof(replica_db_user))) continue;
if (xp.parse_str(tag, "replica_db_passwd", replica_db_passwd, sizeof(replica_db_passwd))) continue;
if (xp.parse_str(tag, "replica_db_host", replica_db_host, sizeof(replica_db_host))) continue;
if (xp.parse_str(tag, "project_dir", project_dir, sizeof(project_dir))) continue;
if (xp.parse_int(tag, "shmem_key", shmem_key)) continue;
if (xp.parse_str(tag, "key_dir", key_dir, sizeof(key_dir))) continue;

View File

@ -47,6 +47,10 @@ struct SCHED_CONFIG {
char db_user[256];
char db_passwd[256];
char db_host[256];
char replica_db_name[256];
char replica_db_user[256];
char replica_db_passwd[256];
char replica_db_host[256];
int shmem_key;
char project_dir[256];
char key_dir[256];