Class::DBI::Replicated::Pg::Slony1 - Pg replication using Slony1


Class-DBI-Replicated documentation Contained in the Class-DBI-Replicated distribution.

Index


Code Index:

NAME

Top

Class::DBI::Replicated::Pg::Slony1 - Pg replication using Slony1

SYNOPSIS

Top

  package My::DBI;
  use base 'Class::DBI::Replicated::Pg::Slony1';
  My::DBI->replication(...);

OPTIONS

Top

Additional options for replication.

slony1_schema

slony1_origin

HOOKS

Top

replication_args

replication_setup

See Class::DBI::Replicated. Allow and set up slony1 options.

METHODS

Top

repl_get_master

repl_get_slave

repl_compare

AUTHOR

Top

Hans Dieter Pearcey, <hdp@cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-class-dbi-replicated-pg-slony1@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-DBI-Replicated. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Class-DBI-Replicated documentation Contained in the Class-DBI-Replicated distribution.
package Class::DBI::Replicated::Pg::Slony1;

use warnings;
use strict;
use base qw(Class::DBI::Pg Class::DBI::Replicated);
use Params::Validate qw(:types);

sub replication_args {
  return (
    slony1_schema => { type => SCALAR },
    slony1_origin => { type => SCALAR },
  );
}

sub replication_setup {
  my ($class, $arg) = @_;
  $class->mk_class_accessors(
    '__slony1_schema',
    '__slony1_origin',
    '__slony1_slave_node'
  );
  $class->__slony1_schema($arg->{slony1_schema});
  $class->__slony1_origin($arg->{slony1_origin});
  my %origin;
  my @slaves = @{ $arg->{slaves} };
  while (my ($name, $slave_arg) = splice @slaves, 0, 2) {
    $origin{"Slave_$name"} = $slave_arg->{node};
  }
  $class->__slony1_slave_node(\%origin);
}

# add 1 because of how slony1 works; that is, we care about
# the next event generated, not the last one
__PACKAGE__->set_sql(master_status => <<'', 'Master_Repl');
SELECT st_last_event + 1
FROM %s.sl_status
WHERE st_origin = ?
LIMIT 1

__PACKAGE__->set_sql(slave_status  => <<'', 'Master_Repl');
SELECT st_last_received
FROM %s.sl_status
WHERE st_received = ?
LIMIT 1

sub repl_get_master {
  my ($class) = @_;
  $class->repl_pos(
    $class->sql_master_status(
      $class->__slony1_schema
    )->select_val(
      1
    ),
  );
}
  
sub repl_get_slave {
  my ($class) = @_;
  my $sth = $class->sql_slave_status(
    $class->__slony1_schema
  );
  return $sth->select_val(
    $class->__slony1_slave_node->{$class->__slave_db}
  );
}

sub repl_compare {
  my ($class, $test, $ref) = @_;
  return $test >= $ref;
}

1; # End of Class::DBI::Replicated::Pg::Slony1