$err_handler->($err) if $err !~ /DBD::Pg/;
## We only do special things for certain errors, so check for those.
- my ($sleeptime,$payload_detail) = (0,'');
+ my ($sleeptime, $fail_msg) = (0,'');
my @states = map { $sync->{db}{$_}{dbh}->state } @dbs_dbi;
if (first { $_ eq '40001' } @states) {
$sleeptime = $config{kid_serial_sleep};
else {
$self->glog('Could not serialize, will try again', LOG_NORMAL);
}
- $payload_detail = "Serialization failure. Sleep=$sleeptime";
+ $fail_msg = "Serialization failure";
}
elsif (first { $_ eq '40P01' } @states) {
$sleeptime = $config{kid_deadlock_sleep};
else {
$self->glog('Encountered a deadlock, will try again', LOG_NORMAL);
}
- $payload_detail = "Deadlock detected. Sleep=$sleeptime";
+ $fail_msg = "Deadlock detected";
## TODO: Get more information via gett_deadlock_details()
}
else {
$dbh->pg_cancel if $dbh->{pg_async_status} > 0;
$dbh->rollback;
}
- $maindbh->rollback;
+
+ # End the syncrun.
+ $self->end_syncrun($maindbh, 'bad', $syncname, "Failed : $fail_msg (KID $$)" );
+ $maindbh->commit;
## Tell listeners we are about to sleep
## TODO: Add some sweet payload information: sleep time, which dbs/tables failed, etc.
- $self->db_notify($maindbh, "syncsleep_${syncname}", 0, $payload_detail);
- $maindbh->commit;
+ $self->db_notify($maindbh, "syncsleep_${syncname}", 0, "$fail_msg. Sleep=$sleeptime");
## Sleep and try again.
sleep $sleeptime if $sleeptime;
END { $bct->stop_bucardo if $bct }
-my $dbh = $bct->connect_database('A');
+my $dbh = $bct->empty_cluster('A');
END { $dbh->disconnect if $dbh }
# Skip the tests if we can't mock the serialization failure.
if $dbh->{pg_server_version} < 80400;
# We are a go!
-plan tests => 27;
+plan tests => 45;
$dbh->disconnect;
$dbh = undef;
# Should have no rows.
$bct->check_for_row([], [qw(A B)], undef, 'test[12]$');
+# Make sure the sync was recorded.
+ok my $runs = $dbhX->selectall_arrayref(
+ 'SELECT * FROM syncrun ORDER BY started',
+ { Slice => {} },
+), 'Get list of syncruns';
+is @{ $runs }, 1, 'Should have one syncrun';
+ok $runs->[0]{ended}, 'It should have an "ended" value';
+ok $runs->[0]{lastempty}, 'It should be marked "last empty"';
+like $runs->[0]{status}, qr/^No delta rows found/,
+ 'Its status should be "No delta rows found"';
+
# Let's add some data into A.bucardo_test1.
+$dbhX->commit;
ok $dbhA->do(q{INSERT INTO bucardo_test1 (id, data1) VALUES (1, 'foo')}),
'Insert a row into test1';
$dbhA->commit;
'SELECT id, data1 FROM bucardo_test1'
), [[1, 'foo']], 'Should have the test1 row in B';
+# Should have two syncrun records now.
+ok $runs = $dbhX->selectall_arrayref(
+ 'SELECT * FROM syncrun ORDER BY started',
+ { Slice => {} },
+), 'Get list of syncruns';
+is @{ $runs }, 2, 'Should have two syncruns';
+ok $runs->[1]{ended}, 'New run should have an "ended" value';
+ok $runs->[1]{lastgood}, 'It should be marked "last good"';
+like $runs->[1]{status}, qr/^Complete/, 'Its status should be "Complete"';
+
# Excellent. Now let's insert into test2.
+$dbhX->commit;
ok $dbhA->do(q{INSERT INTO bucardo_test2 (id, data1) VALUES (2, 'foo')}),
'Insert a row into test2';
$dbhA->commit;
is_deeply $dbhB->selectall_arrayref(
'SELECT id, data1 FROM bucardo_test2'
), [[2, 'foo']], 'Should have the B test2 row despite serialization failure';
+
+# Should have four syncrun records now.
+ok $runs = $dbhX->selectall_arrayref(
+ 'SELECT * FROM syncrun ORDER BY started',
+ { Slice => {} },
+), 'Get list of syncruns';
+is @{ $runs }, 4, 'Should have four syncruns';
+ok $runs->[2]{ended}, 'Third run should have an "ended" value';
+ok $runs->[2]{lastbad}, 'Third run should be marked "last bad"';
+like $runs->[2]{status}, qr/^Failed/, 'Third run status should be "Bad"';
+
+ok $runs->[3]{ended}, 'Fourth run should have an "ended" value';
+ok $runs->[3]{lastgood}, 'Fourth run should be marked "last good"';
+like $runs->[3]{status}, qr/^Complete/, 'Fourth run status should be "Complete"';