Hi everyone,
Thanks for all the advice and recommendations on this post:
http://mu.wordpress.org/forums/topic.php?id=7998&page&replies=11
I downloaded and looked at HyperDb (and tracked down all the documentation I could), but I think it is aimed a step beyond where I am (and probably most others are) at the moment with separate Read and Write databases and replication in mind.
So... I took the Hyperdb class and have re-written the main server/database choosing function and the settings functions to enable the functionality I initially require. The remaining functions in the Hyperdb class are the same as the original that Automattic made available.
The new class has the following functionality:
* Multiple database servers - Servers can be grouped as sets of replicated servers, if the class can't connect to one of the servers in the group it will try each of the others in turn until it can connect to one.
* Multiple databases - can be spread between multiple servers / groups of servers. Again, if class can't connect to a particular database on one server/group of servers then it will attempt to connect on the next server/group of servers that it knows has that database.
* 16, 256 or 4096 databases - the default is splitting between 16 databases.
* Special case databases - I have my system set up so that I have a "Global" database in which I keep the main WPMU tables (site, user, blogs, meta, etc) and any tables that I think will be used across all blogs (in my case the IP2Nation geo-databases and some other large tables that I don't want to have copies of everywhere).
* VIP databases - these are really just like special case databases above, but instead of specifying which individual tables are kept in a certain database, you can assign a blog to a particular database so any new tables created (by plugins for example) are automatically created in the right place.
The Special case and VIP databases are in addition to the number of standard databases. So you can quite easily have 16 standard databases for your run-of-the-mill blogs, a global database for all your settings and configuration and 1 or more VIP databases for your special customers. Special case and VIP databases can be assigned to separate servers, so if you want a different database server just for your paying customers then you can.
* Default database - if the class can't decide where to put data then it will fall-back to a default database. I have mine set to the global database, then I can keep track of any problems and move things around as and when required.
- Basic setup example -
For an example of a basic setup using the class, I will describe the setup I currently have.
* 1 database server called 'local' - it is actually my main (and so far only) webserver/db box.
* 16 standard databases assigned to the 'local' server, (with same name prefix and numbered 1 to 16 - a blog is assigned to a database using an MD5 hash of the blogid).
* 1 Global database assigned to the 'local' server.
* Default database setup to be the Global database.
* 1 VIP database assigned to the 'local' server which holds 2 blogs.
* All standard WordPress MU tables assigned to the Global database.
- Intermediate setup example -
A slightly more advanced setup might include 3 database servers with the database spread amongst them.
1 server could hold the Global database and the first 4 of our 16 default databases.
The second server can hold the remaining 12 default databases and the final server will hold the VIP database.
This can easily be achieved by simply assigning each of the databases to a different server in the configuration file.
- Advanced setup example -
One or more groups of servers. Each group will consist of a Master database and a number of replicated slaves. All writes must go to the master, but reads can go to any of the servers.
This is, hopefully, the next bit of functionality I would like to re-introduce. I stripped out the read and write database code from the original Hyperdb class to enable the splitting of databases between servers. Once I get my head around the original read/write code, I will work on bringing it back in.
The new class is all of 1 day old (well about 8 hours really), I've got it up and running on my testing server (which will become my live server later this week...eek) and it seems to be functioning well at the moment (well, you wouldn't notice it is there, which is the plan I suppose), though there isn't a great deal of traffic (other than me).
If anyone would like a copy to test then let me know and I will send you through a copy and a sample settings file (for the Basic setup above). I won't make a download link available yet, until I (and possibly a few others) have hammered it to get rid of any left-over bugs and niggles.
Any recommendations for functionality would also be welcomed.
If you've made it this far then thanks for reading.
Barry