Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
noblogs-wp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai
noblogs-wp
Commits
f44bcc33
Commit
f44bcc33
authored
13 years ago
by
ale
Committed by
agata
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
support split master/slave backends for the primary database
parent
5de98e61
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
db-config.php
+8
-1
8 additions, 1 deletion
db-config.php
r2db/db-backends.php
+15
-1
15 additions, 1 deletion
r2db/db-backends.php
with
23 additions
and
2 deletions
db-config.php
+
8
−
1
View file @
f44bcc33
...
...
@@ -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
);
This diff is collapsed.
Click to expand it.
r2db/db-backends.php
+
15
−
1
View file @
f44bcc33
...
...
@@ -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
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment