Support » Plugin: NS Cloner - Site Copier » HyperDB support

  • Resolved Václav Greif

    (@vasikgreif)


    Hello,
    on my multisite install I’m using HyperDB to split sites to separate databases. My setup is pretty basic, each 100 sites have it’s own db.

    $wpdb->add_callback('prefix_multisite_tables');
    function prefix_multisite_tables($query, $wpdb) {
    	// Multisite blog tables are "{$base_prefix}{$blog_id}_*"
        if ( preg_match("/^{$wpdb->base_prefix}(\d+)_/i", $wpdb->table,$matches) ) {
            if (isset($matches[1])) {
                $db_id = intval($matches[1] / 100);
                if ($db_id) {
                    return 'prefix_' . $db_id;
                }
            }
        }
    }

    When I try to duplicate site, I get “Table not found…” error. What I have to do now is copy the site tables to the main db, and add a condition for the site I’m duplicating and the new site, like:

    if(isset($matches[1]) && $matches[1] != 123 && $matches[1] != 925)

    Any chance to support HyperDB natively?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Never Settle

    (@neversettle)

    Thank you for your question! We’ve seen a couple questions like this over the years, but to be honest there hasn’t been nearly enough demand to try to build and support sharding techniques in the Cloner. There are also several different schemes that people use. HyperDB, MultiDB and others. They all use different schemes and it would be really hard to build in such a way to support them consistently. Plus, the troubleshooting effort goes up exponentially trying to isolate issues when there are sharding schemes in place.

    So far, we’ve been of the opinion that if someone truly needs the performance gains that sharding offers (default WP Multisite schema can handle hundreds of sites without issues and without the need to shard the DBs) then it’s probably better that those environments are tailored by the ones who know them best and set them up.

    All that said – I really appreciate your suggestions, and we will at least do a code scrub. We’re using the wpdb object and standard wpdb methods for everything, so we’ll take a look and see if we missed anything that isn’t letting your prefix callback work properly. we do use the wp prefix, but maybe a small tweak would make it compatible with your setup. We’re working hard on V4 and perhaps we can sneak some basic hyperdb support into that. Can’t promise, but genuinely appreciate your feedback!!!

    Thanks for reply!

    I spent some time debugging this, and found out that the issue was indeed on my site. I use Slim Stat Analytics plugin, with its own DB for saving the stats, to save some bandwidth on the main dbs. The HyperDB was not aware of this though. I just added a condition for this

    if ( preg_match("/^{$wpdb->base_prefix}(\d+)_/i", $wpdb->table,$matches) && strpos($wpdb->table, '_slim_') === false ) {

    and duplicating works like a charm!

    Thanks for really great plugin and support!

    Plugin Author Never Settle

    (@neversettle)

    Ah! Very cool! Thank you for sharing those findings. Now that you mention it I remember that at least a while back Slim Stat had a non-standard WP database structure as far as it’s table names go. We had even built a micro-plugin to tell the Cloner to ignore Slim Stat tables entirely (also helpful so that all that analytics data for one site isn’t replicated per new site). Here it is in case others find this and it can help them. This is the entire plugin. Just put inside a folder in /wp-content/plugins and in a file called whatever you want and network activate (OR put in mu-plugins):

    <?php
    /*
     * Plugin Name: NS Cloner Exclude SlimStat
     * Plugin URI: http://neversettle.it
     * Description: Custom mini-plugin that prevents the slimstat tables from being copied as a work around for SQL errors they are causing
     * Author: Never Settle
     * Version: 1.0.0
     * Network: true
     * Author URI: http://neversettle.it
     * License: GPLv2 or later
     */
    
    add_filter( 'ns_cloner_site_tables', 'ns_cloner_exclude_slimstat', 10, 3 );
    function ns_cloner_exclude_slimstat( $tables, $db, $prefix ){
    	foreach( $tables as $index=>$table ){
    		if( strpos( $table, 'slim_' ) >= 0 ){
    			unset( $tables[$index] );
    		}
    	}
    	return $tables;
    }

    You might find the technique useful in other cases.

    Best,
    NS

    Thanks for sharing the code, makes sense! I added it to my install.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘HyperDB support’ is closed to new replies.