add lineage increment_step and _offset for multi-master DB clusters

This commit is contained in:
Doug Bell 2011-03-21 18:26:18 -05:00
parent 1e422f3e21
commit 5e6483e97f
4 changed files with 44 additions and 13 deletions

View file

@ -7,6 +7,7 @@
- added: Group Manager form control
- fixed #12050: Thing query caching #1
- added: Let CHI cache request $dbh via an "args" : [ "dbh" ] cache conf
- added: lineage increment_step and increment_offset for multi-master DB clusters
7.10.11
- fixed #12057: WebGUI::Search, assetIds search clause

View file

@ -154,6 +154,24 @@
# "password" : "password"
# },
# If you have a multi-master set up, you must define increment_step and increment_offset
# to prevent merge conflicts between the different masters. increment_step should be set
# to the number of masters, and offset should be unique to each master, starting at 0.
#
# So, a 2-master cluster would define:
# Master 1:
# increment_step: 2
# increment_offset: 0
# Master 2:
# increment_step: 2
# increment_offset: 1
#
# "db" : {
# "increment_step" : 1,
# "increment_offset" : 0
# },
# Set this value if you wish to override all outbound emails to a specific
# user for testing purposes.

View file

@ -763,19 +763,25 @@ Returns a 6 digit number with leading zeros of the next rank a child will get.
=cut
sub getNextChildRank {
my $self = shift;
my ($lineage) = $self->session->db->quickArray("select max(lineage) from asset where parentId=?",[$self->getId]);
my $rank;
if (defined $lineage) {
$rank = $self->getRank($lineage);
$self->session->errorHandler->fatal("Asset ".$self->getId." has too many children.") if ($rank >= 999998);
$rank++;
} else {
$rank = 1;
}
return $self->formatRank($rank);
}
my $self = shift;
# Increment by steps for servers in multi-master DB setups
my $inc_step = $self->session->config->get('db/increment_step') || 1;
my $inc_offset = $self->session->config->get('db/increment_offset') || 0;
my ($lineage) = $self->session->db->quickArray("select max(lineage) from asset where parentId=?",[$self->getId]);
my $rank;
if (defined $lineage) {
$rank = $self->getRank($lineage);
# Increase rank to next step then add offset
$rank += ( $inc_step - $rank % $inc_step ) + $inc_offset;
$self->session->errorHandler->fatal("Asset ".$self->getId." has too many children.") if ($rank >= 999999); # Each lineage area is only 6 digits
}
else {
$rank = 1;
}
return $self->formatRank($rank);
}
#-------------------------------------------------------------------

View file

@ -17,7 +17,7 @@ use WebGUI::Session;
use WebGUI::User;
use WebGUI::Asset;
use Test::More tests => 96; # increment this value for each test you create
use Test::More tests => 98; # increment this value for each test you create
use Test::Deep;
# Test the methods in WebGUI::AssetLineage
@ -234,6 +234,12 @@ is($root->getRank('100001'), '100001', "getRank: arbitrary lineage");
is($folder->getNextChildRank, '000008', "getNextChildRank: folder with 8 snippets");
is($folder2->getNextChildRank, '000002', "getNextChildRank: empty folder");
# Change the step and offset
$session->config->set( 'db', { increment_step => 5, increment_offset => 3 } );
is( $folder->getNextChildRank, '000013', "getNextChildRank: step 5, offset 3, folder with 8 snippets" );
is( $folder2->getNextChildRank, '000008', "getNextChildRank: step 5, offset 3, empty folder" );
$session->config->delete( 'db' );
####################################################
#
# swapRank