Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ai
noblogs-wp
Commits
4436e861
Commit
4436e861
authored
Oct 08, 2011
by
ale
Committed by
agata
Oct 17, 2019
Browse files
support split master/slave backends for the primary database
parent
bd1bd157
Changes
2
Hide whitespace changes
Inline
Side-by-side
db-config.php
View file @
4436e861
...
...
@@ -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
);
r2db/db-backends.php
View file @
4436e861
...
...
@@ -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
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment