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
796fccd7
Commit
796fccd7
authored
13 years ago
by
Joe
Committed by
agata
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Workaround for the demented hyperdb bug
parent
f1dc0c9a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
db-config.php
+16
-3
16 additions, 3 deletions
db-config.php
r2db/tools/noblogs-new-topology.php
+31
-23
31 additions, 23 deletions
r2db/tools/noblogs-new-topology.php
wp-nginx-map.NOT_YET
+0
-0
0 additions, 0 deletions
wp-nginx-map.NOT_YET
with
47 additions
and
26 deletions
db-config.php
+
16
−
3
View file @
796fccd7
...
...
@@ -12,19 +12,32 @@ include_once('r2db/db-backends.php');
// Add the global database (configured in wp-config.php), stores the global
// blogs and users tables.
$is_master
=
__gf_ai_is_master
();
// 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"
=>
0
,
"read"
=>
1
,
"timeout"
=>
2
"write"
=>
$is_master
,
"read"
=>
1
,
"timeout"
=>
2
));
// This is the write-only master.
$wpdb
->
add_database
(
noblogs_load_master
(
NOBLOGS_MASTER_CONFIG
));
if
(
!
$is_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
);
// Ai patch: allows to understand if the current database is the master server
function
__gf_ai_is_master
()
{
$master_dsn
=
trim
(
file_get_contents
(
'/etc/noblogs/master'
));
preg_match
(
'/@172.16.1.(\d+):/'
,
$master_dsn
,
$m
);
$master_id
=
$m
[
1
];
if
(
!
empty
(
$_SERVER
[
'SERVER_ADDR'
]))
return
(
int
)
(
'172.16.1.'
.
$master_id
==
$_SERVER
[
'SERVER_ADDR'
]);
//works on web
return
(
int
)
(
$master_id
==
$_SERVER
[
'SERVER_PUBLIC_ID'
]);
//works on cli
}
This diff is collapsed.
Click to expand it.
r2db/tools/noblogs-new-topology.php
+
31
−
23
View file @
796fccd7
#!/opt/noblogs/cron/php-noblogs
<?php
// Load wordpress api.
define
(
'WP_CACHE'
,
false
);
/** Setup WordPress environment */
require_once
(
'wp-load.php'
);
require_once
(
'db-config.php'
);
/*
Parse command line options
*/
$opts
=
getopt
(
''
,
array
(
'no-database'
,
'calc-size'
));
$opts
=
getopt
(
''
,
array
(
'no-database'
,
'calc-size'
,
'db-only'
));
if
(
array_key_exists
(
'calc-size'
,
$opts
))
{
$opts
[
'no-database'
]
=
true
;
$g_added_size
=
array
();
}
$new_topology
=
array_pop
(
$argv
);
$old_topology
=
array_pop
(
$argv
);
if
(
!
(
$new_topology
&&
$old_topology
))
{
usage
();
exit
(
-
1
);
}
// Get all blogs
define
(
'WP_CACHE'
,
false
);
require_once
(
'wp-load.php'
);
require_once
(
'db-config.php'
);
$blogs
=
get_all_blogs
();
$n_hashmap
=
new
Flexihash
();
$new_map
=
noblogs_load_backends
(
array_pop
(
$argv
)
,
$n_hashmap
);
$new_map
=
noblogs_load_backends
(
$new_topology
,
$n_hashmap
);
$o_hashmap
=
new
Flexihash
();
$old_map
=
noblogs_load_backends
(
array_pop
(
$argv
),
$o_hashmap
);
$old_map
=
noblogs_load_backends
(
$old_topology
,
$o_hashmap
);
$blogs
=
get_all_blogs
();
foreach
(
$blogs
as
$blog
)
{
$blog_id
=
$blog
->
blog_id
;
$old_params
=
fhash
(
$blog_id
,
$old_map
);
$old_params
=
fhash
(
$blog_id
,
$old_map
,
$o_hashmap
);
$old_dburi
=
mysqlurl
(
$old_params
);
$new_params
=
fhash
(
$blog_id
,
$new_map
);
$new_params
=
fhash
(
$blog_id
,
$new_map
,
$n_hashmap
);
$new_dburi
=
mysqlurl
(
$new_params
);
if
(
$new_counts
[
$new_params
[
'host'
]])
{
...
...
@@ -39,20 +45,22 @@ foreach ($blogs as $blog) {
if
(
$old_dburi
!=
$new_dburi
)
{
echo
"echo moving blog
$blog_id
from "
.
$old_params
[
'host'
]
.
" to "
.
$new_params
[
'host'
]
.
"
\n
"
;
if
(
array_key_exists
(
'no-database'
,
$opts
)
)
{
if
(
!
array_key_exists
(
'no-database'
,
$opts
)
)
{
echo
"tables=
\$
(mysql "
.
mysqlopts
(
$old_params
)
.
" "
.
$old_params
[
'db'
]
.
" -NBe
\"
show tables like 'wp
\\
_"
.
$blog_id
.
"
\\
_%'
\"
)
\n
"
;
echo
"mysqldump --opt "
.
mysqlopts
(
$old_params
)
.
" "
.
$old_params
[
'db'
]
.
"
\$
{
tables
}
\\\n
"
;
echo
" | mysql "
.
mysqlopts
(
$new_params
)
.
" "
.
$new_params
[
'db'
]
.
"
\n
"
;
}
if
(
!
array_key_exists
(
'db-only'
,
$opts
))
{
if
(
array_key_exists
(
'calc-size'
,
$opts
))
{
$cmd
=
escapeshellargs
(
sprintf
(
"ssh root@%s du -sk /opt/noblogs/www/wp-content/blogs.dir/%d"
,
$old_params
[
'host'
],
$blog_id
));
list
(
$size
,
$dummy
)
=
explode
(
"
\t
"
,
exec
(
$cmd
,
$ret
));
# $cmd = sprintf("ssh root@%s du -sk /opt/noblogs/www/wp-content/blogs.dir/%d", $old_params['host'], $blog_id);
$cmd
=
sprintf
(
"du -sk /opt/noblogs/www/wp-content/blogs.dir/%d"
,
$blog_id
);
list
(
$size
,
$dummy
)
=
explode
(
"
\t
"
,
exec
(
$cmd
,
$ret
));
$g_added_size
[
$new_params
[
'host'
]]
+=
$size
;
}
else
{
printf
(
"rsync -avz --delete
root@%s:
/opt/noblogs/www/wp-content/blogs.dir/%d root@%s:/opt/noblogs/www/wp-content/blogs.dir/
%d
\n
"
,
$old_params
[
'host'
],
$blog_id
,
$new_params
[
'host'
]
,
$blog_id
);
printf
(
"
ssh root@%s
rsync -avz --delete /opt/noblogs/www/wp-content/blogs.dir/%d root@%s:/opt/noblogs/www/wp-content/blogs.dir/
\n
"
,
$old_params
[
'host'
],
$blog_id
,
$new_params
[
'host'
]);
}
}
$moved_count
+=
1
;
}
else
{
echo
"echo blog
$blog_id
stays on "
.
$old_params
[
'host'
]
.
"
\n
"
;
}
...
...
@@ -68,9 +76,8 @@ if (array_key_exists('calc-size', $opts)) {
print_r
(
$g_added_size
);
}
function
fhash
(
$dbid
,
$reversemap
)
{
global
$wpdb
;
$lookup
=
$wpdb
->
hash_map
->
lookup
(
$dbid
);
function
fhash
(
$dbid
,
$reversemap
,
$hashptr
)
{
$lookup
=
$hashptr
->
lookup
(
$dbid
);
$backend
=
$reversemap
[
$lookup
];
$result
=
array
();
if
(
preg_match
(
'/^(.*):([0-9]*)$/'
,
$backend
[
'host'
],
$matches
))
{
...
...
@@ -96,7 +103,7 @@ function mysqlurl(&$attrs) {
function
get_all_blogs
()
{
global
$wpdb
;
$sql
=
"SELECT blog_id, domain, path FROM
$wpdb->blogs
WHERE
public = 1 AND
deleted = 0 AND archived = '0' ORDER BY domain, path"
;
$sql
=
"SELECT blog_id, domain, path FROM
$wpdb->blogs
WHERE deleted = 0 AND archived = '0' ORDER BY domain, path"
;
$result
=
$wpdb
->
get_results
(
$sql
);
return
(
$result
);
}
...
...
@@ -105,4 +112,5 @@ function usage() {
$str
=
<<<USAGE
noblogs-new-topology.php [--no-database|--calc-size] <OLD_MAP> <NEW_MAP>
USAGE;
}
\ No newline at end of file
echo
$str
;
}
This diff is collapsed.
Click to expand it.
wp-nginx-map.
php
→
wp-nginx-map.
NOT_YET
+
0
−
0
View file @
796fccd7
File moved
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