Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb24a029

Browse files
committed
Attached is a patch that provides *VERY* limited support for multiple
slaveservers. I haven't tested it very well, so use at your own risk (and Irecommend against using it in production).Basically, I have a central database server that has 4 summary tablesinsideit replicated to a remote slave (these database tables are for my mailserverauthentication, so these are replicated to another server tuned for manyconnections, and so I don't have postgres connections opened straight tomyback-end database server).Unfortunately, I also wanted to implement a replication database serverforhot-backups. I realized, too late, that the replication process isprettygreedy and will try to replicate all tables marked as a"MasterAddTable".To make a long story, I made a patch to RServ.pm and Replicate thatallows youto specify, on the command line, a list of tables that you want toreplicate...it'll ignore all others.I haven't finished, since this has to be integrated with CleanLog forinstance, but this should (and does) suffice for the moment.I have yet to test it with two slaves, but at least my mail serverreplicationdatabase now works (it was failing every time it tried to replicate, foravariety of reasons).Anyone have any suggestions on how to improve on this? (or, if someonemorefamiliar with this code wants to take the ball and run with it, you'rewelcome to).--Michael A Nachbaur <mike@nachbaur.com>
1 parente1be2ee commitb24a029

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

‎contrib/rserv/RServ.pm

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ my %Stables = ();
1919

2020
subPrepareSnapshot
2121
{
22-
my ($conn,$outf,$server) =@_;# (@_[0], @_[1], @_[2]);
22+
my ($conn,$outf,$server,$onlytables) =@_;# (@_[0], @_[1], @_[2]);
2323

2424
my$result =$conn->exec("BEGIN");
2525
if ($result->resultStatusne PGRES_COMMAND_OK)
@@ -52,6 +52,10 @@ sub PrepareSnapshot
5252
while (@row =$result->fetchrow)
5353
{
5454
#printf "$row[0], $row[1], $row[2]\n";
55+
if (ref($onlytables)eq'HASH') {
56+
nextunless (exists$onlytables->{$row[1]});
57+
$onlytables->{$row[1]} =$row[0]unless ($onlytables->{$row[1]});
58+
}
5559
push @{$Mtables{$row[0]}},$row[1],$row[2];
5660
}
5761

@@ -232,7 +236,7 @@ sub GetSYNCID
232236

233237
subCleanLog
234238
{
235-
my ($conn,$howold) =@_;# (@_[0], @_[1]);
239+
my ($conn,$howold,$onlytables) =@_;# (@_[0], @_[1]);
236240

237241
my$result =$conn->exec("BEGIN");
238242
if ($result->resultStatusne PGRES_COMMAND_OK)
@@ -274,6 +278,11 @@ sub CleanLog
274278
my$alist =join(',',keys%active);
275279
my$sinfo ="logid <$maxid";
276280
$sinfo .=" and logid not in ($alist)"if$alistne'';
281+
#if (ref($onlytables) eq 'HASH') {
282+
#foreach my $onlytable (keys %{$onlytables}) {
283+
#$sinfo
284+
#}
285+
#}
277286

278287
$sql ="delete from _RSERV_LOG_ where" .
279288
"logtime < now() - '$howold second'::interval and$sinfo";
@@ -302,7 +311,7 @@ sub CleanLog
302311

303312
subApplySnapshot
304313
{
305-
my ($conn,$inpf) =@_;# (@_[0], @_[1]);
314+
my ($conn,$inpf,$onlytables) =@_;# (@_[0], @_[1]);
306315

307316
my$result =$conn->exec("BEGIN");
308317
if ($result->resultStatusne PGRES_COMMAND_OK)
@@ -336,6 +345,10 @@ sub ApplySnapshot
336345
while (@row =$result->fetchrow)
337346
{
338347
#printf "%s%s\n", $row[1], $row[0];
348+
if (ref($onlytables)eq'HASH') {
349+
nextunless (exists$onlytables->{$row[1]});
350+
$onlytables->{$row[1]} =$row[0]unless ($onlytables->{$row[1]});
351+
}
339352
push @{$Stables{$row[1]}},$row[0],$row[2],$row[3];
340353
}
341354

‎contrib/rserv/Replicate.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if (defined($opt_help) || (scalar(@ARGV) < 2)) {
3232

3333
my$master =$ARGV[0] ||"master";
3434
my$slave =$ARGV[1] ||"slave";
35+
my$tables =$#ARGV < 2 ?undef : {map {($_,undef)}@ARGV[2..$#ARGV] };
3536
my$server = 0;
3637

3738
my$minfo ="dbname=$master";
@@ -56,7 +57,7 @@ SyncSync($mconn, $sconn);
5657
my$outf = new IO::File;
5758
open$outf,">$snapshot";
5859
print"\n>>>>>>>>>>>>> Prepare Snapshot\n\n"if ($verbose);
59-
$res = PrepareSnapshot($mconn,$outf,$server);
60+
$res = PrepareSnapshot($mconn,$outf,$server,$tables);
6061
close$outf;
6162
die"\n>>>>>>>>>>>>> ERROR\n"if$res < 0;
6263
if ($res == 0)
@@ -68,7 +69,7 @@ if ($res == 0)
6869
my$inpf = new IO::File;
6970
open$inpf,"<$snapshot";
7071
print"\n>>>>>>>>>>>>> Apply Snapshot\n\n"if ($verbose);
71-
$res = ApplySnapshot($sconn,$inpf);
72+
$res = ApplySnapshot($sconn,$inpf,$tables);
7273
close$inpf;
7374
die"\n>>>>>>>>>>>>> ERROR\n"if$res < 0;
7475

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp