line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::DBI::Replicated::Pg::Slony1; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
90403
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
18
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
5
|
use base qw(Class::DBI::Pg Class::DBI::Replicated); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
134
|
|
6
|
1
|
|
|
1
|
|
7
|
use Params::Validate qw(:types); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
587
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Class::DBI::Replicated::Pg::Slony1 - Pg replication using Slony1 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package My::DBI; |
15
|
|
|
|
|
|
|
use base 'Class::DBI::Replicated::Pg::Slony1'; |
16
|
|
|
|
|
|
|
My::DBI->replication(...); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 OPTIONS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Additional options for C<< replication >>. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head3 C<< slony1_schema >> |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head3 C<< slony1_origin >> |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 HOOKS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 C<< replication_args >> |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 C<< replication_setup >> |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
See L. Allow and set up slony1 |
33
|
|
|
|
|
|
|
options. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub replication_args { |
38
|
|
|
|
|
|
|
return ( |
39
|
0
|
|
|
0
|
1
|
|
slony1_schema => { type => SCALAR }, |
40
|
|
|
|
|
|
|
slony1_origin => { type => SCALAR }, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub replication_setup { |
45
|
0
|
|
|
0
|
1
|
|
my ($class, $arg) = @_; |
46
|
0
|
|
|
|
|
|
$class->mk_class_accessors( |
47
|
|
|
|
|
|
|
'__slony1_schema', |
48
|
|
|
|
|
|
|
'__slony1_origin', |
49
|
|
|
|
|
|
|
'__slony1_slave_node' |
50
|
|
|
|
|
|
|
); |
51
|
0
|
|
|
|
|
|
$class->__slony1_schema($arg->{slony1_schema}); |
52
|
0
|
|
|
|
|
|
$class->__slony1_origin($arg->{slony1_origin}); |
53
|
0
|
|
|
|
|
|
my %origin; |
54
|
0
|
|
|
|
|
|
my @slaves = @{ $arg->{slaves} }; |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
while (my ($name, $slave_arg) = splice @slaves, 0, 2) { |
56
|
0
|
|
|
|
|
|
$origin{"Slave_$name"} = $slave_arg->{node}; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
$class->__slony1_slave_node(\%origin); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# add 1 because of how slony1 works; that is, we care about |
62
|
|
|
|
|
|
|
# the next event generated, not the last one |
63
|
|
|
|
|
|
|
__PACKAGE__->set_sql(master_status => <<'', 'Master_Repl'); |
64
|
|
|
|
|
|
|
SELECT st_last_event + 1 |
65
|
|
|
|
|
|
|
FROM %s.sl_status |
66
|
|
|
|
|
|
|
WHERE st_origin = ? |
67
|
|
|
|
|
|
|
LIMIT 1 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__PACKAGE__->set_sql(slave_status => <<'', 'Master_Repl'); |
70
|
|
|
|
|
|
|
SELECT st_last_received |
71
|
|
|
|
|
|
|
FROM %s.sl_status |
72
|
|
|
|
|
|
|
WHERE st_received = ? |
73
|
|
|
|
|
|
|
LIMIT 1 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 METHODS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 C<< repl_get_master >> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub repl_get_master { |
82
|
0
|
|
|
0
|
1
|
|
my ($class) = @_; |
83
|
0
|
|
|
|
|
|
$class->repl_pos( |
84
|
|
|
|
|
|
|
$class->sql_master_status( |
85
|
|
|
|
|
|
|
$class->__slony1_schema |
86
|
|
|
|
|
|
|
)->select_val( |
87
|
|
|
|
|
|
|
1 |
88
|
|
|
|
|
|
|
), |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 C<< repl_get_slave >> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub repl_get_slave { |
97
|
0
|
|
|
0
|
1
|
|
my ($class) = @_; |
98
|
0
|
|
|
|
|
|
my $sth = $class->sql_slave_status( |
99
|
|
|
|
|
|
|
$class->__slony1_schema |
100
|
|
|
|
|
|
|
); |
101
|
0
|
|
|
|
|
|
return $sth->select_val( |
102
|
|
|
|
|
|
|
$class->__slony1_slave_node->{$class->__slave_db} |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 C<< repl_compare >> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub repl_compare { |
111
|
0
|
|
|
0
|
1
|
|
my ($class, $test, $ref) = @_; |
112
|
0
|
|
|
|
|
|
return $test >= $ref; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Hans Dieter Pearcey, C<< >> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 BUGS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
122
|
|
|
|
|
|
|
C, or through the web interface at |
123
|
|
|
|
|
|
|
L. |
124
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
125
|
|
|
|
|
|
|
your bug as I make changes. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Copyright 2005 Hans Dieter Pearcey, all rights reserved. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
134
|
|
|
|
|
|
|
under the same terms as Perl itself. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; # End of Class::DBI::Replicated::Pg::Slony1 |