Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
noblogs-wp
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
33
Issues
33
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
ai
noblogs-wp
Commits
cf68b44d
Commit
cf68b44d
authored
Oct 16, 2019
by
samba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use dbconf from ai3/docker/noblogs
parent
08ae3b7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
61 deletions
+14
-61
db-config.php
db-config.php
+2
-2
r2db/db-backends.php
r2db/db-backends.php
+12
-59
No files found.
db-config.php
View file @
cf68b44d
...
...
@@ -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
);
r2db/db-backends.php
View file @
cf68b44d
<?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
);
Write
Preview
Markdown
is supported
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