Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
r2db
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Noblogs
r2db
Commits
cff39fc3
Commit
cff39fc3
authored
14 years ago
by
root
Committed by
lucha
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
a few fixes to the global wpdb_hash instance (moved into $wpdb)
parent
828c6515
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
db-backends.php
+1
-1
1 addition, 1 deletion
db-backends.php
db-hash.php
+3
-3
3 additions, 3 deletions
db-hash.php
tools/db-migrate-to-new-schema.php
+11
-8
11 additions, 8 deletions
tools/db-migrate-to-new-schema.php
with
15 additions
and
12 deletions
db-backends.php
+
1
−
1
View file @
cff39fc3
<?php
function
noblogs_load_backends
(
$db_config_file
,
&
$hashptr
)
{
function
noblogs_load_backends
(
$db_config_file
,
$hashptr
)
{
global
$wpdb
;
$backend_map
=
array
();
...
...
This diff is collapsed.
Click to expand it.
db-hash.php
+
3
−
3
View file @
cff39fc3
<?php
require_once
(
'
flexihash.php'
);
require_once
(
dirname
(
__FILE__
)
.
'/
flexihash.php'
);
$wpdb
_
hash
=
new
Flexihash
();
$wpdb
->
hash
_map
=
new
Flexihash
();
/* Hashing function to map blogs to databases.
*
* Implements a consistent hashing scheme using Flexihash.
*/
function
noblogs_db_callback
(
$query
,
$wpdb
)
{
global
$wpdb
_
hash
;
$wpdb_hash
=
$wpdb
->
hash
_map
;
if
(
preg_match
(
"/^
{
$wpdb
->
base_prefix
}
(\d+)_/"
,
$wpdb
->
table
,
$matches
))
{
$blog_id
=
$matches
[
1
];
return
$wpdb_hash
->
lookup
(
$blog_id
);
...
...
This diff is collapsed.
Click to expand it.
tools/db-migrate-to-new-schema.php
+
11
−
8
View file @
cff39fc3
...
...
@@ -5,7 +5,7 @@
define
(
'WP_CACHE'
,
false
);
/** Setup WordPress environment */
require_once
(
'wp-load.php'
);
require_once
(
'db-config
-new
.php'
);
require_once
(
'db-config.php'
);
function
old_hash
(
$dbid
)
{
...
...
@@ -24,11 +24,10 @@ function old_hash($dbid) {
}
}
function
new_hash
(
$dbid
)
{
global
$wpdb_hash
;
global
$wpdb_reverse_backend_map
;
$lookup
=
$wpdb_hash
->
lookup
(
$dbid
);
$backend
=
$wpdb_reverse_backend_map
[
$lookup
];
function
new_hash
(
$dbid
,
$reversemap
)
{
global
$wpdb
;
$lookup
=
$wpdb
->
hash_map
->
lookup
(
$dbid
);
$backend
=
$reversemap
[
$lookup
];
$result
=
array
();
if
(
preg_match
(
'/^(.*):([0-9]*)$/'
,
$backend
[
'host'
],
$matches
))
{
$result
[
'host'
]
=
$matches
[
1
];
...
...
@@ -54,11 +53,15 @@ 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 public = 1 AND deleted = 0 AND archived = '0' ORDER BY domain, path";
$sql
=
"SELECT blog_id, domain, path FROM
$wpdb->blogs
WHERE public = 0 ORDER BY domain, path"
;
$result
=
$wpdb
->
get_results
(
$sql
);
return
(
$result
);
}
$hashmap
=
new
Flexihash
();
$reverse_backend_map
=
noblogs_load_backends
(
NOBLOGS_BACKEND_CONFIG
,
$hashmap
);
$new_counts
=
array
();
$moved_count
=
0
;
$blogs
=
get_all_blogs
();
...
...
@@ -67,7 +70,7 @@ foreach ($blogs as $blog) {
$old_params
=
old_hash
(
$blog_id
);
$old_dburi
=
mysqlurl
(
$old_params
);
$new_params
=
new_hash
(
$blog_id
);
$new_params
=
new_hash
(
$blog_id
,
$reverse_backend_map
);
$new_dburi
=
mysqlurl
(
$new_params
);
if
(
$new_counts
[
$new_params
[
'host'
]])
{
...
...
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