43 |
|
|
44 |
sub PrepareSnapshot |
sub PrepareSnapshot |
45 |
{ |
{ |
46 |
my ($mconn, $sconn, $outf, $server, $onlytables) = @_; |
my ($mconn, $sconn, $outf, $sserver, $onlytables) = @_; |
47 |
|
|
48 |
# first, we must know for wich tables the slave subscribed |
# first, we must know for wich tables the slave subscribed |
49 |
my $result = $sconn->exec("SELECT tname FROM _RSERV_SLAVE_TABLES_"); |
my $result = $sconn->exec("SELECT tname FROM _RSERV_SLAVE_TABLES_"); |
98 |
|
|
99 |
# Read last succeeded sync |
# Read last succeeded sync |
100 |
my $sql = "select syncid, synctime, minid, maxid, active from _RSERV_SYNC_" . |
my $sql = "select syncid, synctime, minid, maxid, active from _RSERV_SYNC_" . |
101 |
" where server = $server AND syncid = (select max(syncid) from" . |
" where server = $sserver AND syncid = (select max(syncid) from" . |
102 |
" _RSERV_SYNC_ where server = $server AND status > 0)"; |
" _RSERV_SYNC_ where server = $sserver AND status > 0)"; |
103 |
|
|
104 |
printf "$sql\n" if $debug; |
printf "$sql\n" if $debug; |
105 |
|
|
273 |
} |
} |
274 |
|
|
275 |
# Remember this snapshot info |
# Remember this snapshot info |
276 |
$result = $mconn->exec("select _rserv_sync_($server)"); |
$result = $mconn->exec("select _rserv_sync_($sserver)"); |
277 |
if ($result->resultStatus ne PGRES_TUPLES_OK) |
if ($result->resultStatus ne PGRES_TUPLES_OK) |
278 |
{ |
{ |
279 |
printf $outf "-- ERROR\n"; |
printf $outf "-- ERROR\n"; |
916 |
# |
# |
917 |
sub SyncSyncID |
sub SyncSyncID |
918 |
{ |
{ |
919 |
my ($mconn, $server, $syncid) = @_; # (@_[0], @_[1], @_[2]); |
my ($mconn, $sserver, $syncid) = @_; # (@_[0], @_[1], @_[2]); |
920 |
|
|
921 |
my $result = $mconn->exec("BEGIN"); |
my $result = $mconn->exec("BEGIN"); |
922 |
if ($result->resultStatus ne PGRES_COMMAND_OK) |
if ($result->resultStatus ne PGRES_COMMAND_OK) |
927 |
} |
} |
928 |
|
|
929 |
$result = $mconn->exec("select synctime, status from _RSERV_SYNC_" . |
$result = $mconn->exec("select synctime, status from _RSERV_SYNC_" . |
930 |
" where server = $server AND syncid = $syncid" . |
" where server = $sserver AND syncid = $syncid" . |
931 |
" for update"); |
" for update"); |
932 |
if ($result->resultStatus ne PGRES_TUPLES_OK) |
if ($result->resultStatus ne PGRES_TUPLES_OK) |
933 |
{ |
{ |
938 |
my @row = $result->fetchrow; |
my @row = $result->fetchrow; |
939 |
if (! defined $row[0]) |
if (! defined $row[0]) |
940 |
{ |
{ |
941 |
printf STDERR "No SyncID $syncid found for server $server\n" unless ($quiet); |
printf STDERR "No SyncID $syncid found for server $sserver\n" unless ($quiet); |
942 |
$mconn->exec("ROLLBACK"); |
$mconn->exec("ROLLBACK"); |
943 |
return(0); |
return(0); |
944 |
} |
} |
945 |
if ($row[1] > 0) |
if ($row[1] > 0) |
946 |
{ |
{ |
947 |
printf STDERR "SyncID $syncid for server ". |
printf STDERR "SyncID $syncid for server ". |
948 |
"$server already updated\n" unless ($quiet); |
"$sserver already updated\n" unless ($quiet); |
949 |
$mconn->exec("ROLLBACK"); |
$mconn->exec("ROLLBACK"); |
950 |
return(0); |
return(0); |
951 |
} |
} |
952 |
$result = $mconn->exec("update _RSERV_SYNC_" . |
$result = $mconn->exec("update _RSERV_SYNC_" . |
953 |
" set synctime = now(), status = 1" . |
" set synctime = now(), status = 1" . |
954 |
" where server = $server AND syncid = $syncid"); |
" where server = $sserver AND syncid = $syncid"); |
955 |
if ($result->resultStatus ne PGRES_COMMAND_OK) |
if ($result->resultStatus ne PGRES_COMMAND_OK) |
956 |
{ |
{ |
957 |
print STDERR $mconn->errorMessage unless ($quiet); |
print STDERR $mconn->errorMessage unless ($quiet); |
959 |
return(-1); |
return(-1); |
960 |
} |
} |
961 |
$result = $mconn->exec("delete from _RSERV_SYNC_" . |
$result = $mconn->exec("delete from _RSERV_SYNC_" . |
962 |
" where server = $server AND syncid < $syncid"); |
" where server = $sserver AND syncid < $syncid"); |
963 |
if ($result->resultStatus ne PGRES_COMMAND_OK) |
if ($result->resultStatus ne PGRES_COMMAND_OK) |
964 |
{ |
{ |
965 |
print STDERR $mconn->errorMessage unless ($quiet); |
print STDERR $mconn->errorMessage unless ($quiet); |