[Bucardo-general] Conflict Handling: Newest Data Always Wins

Spencer Christensen email at spencerchristensen.com
Wed Oct 10 00:10:39 UTC 2007


Ben Allen wrote:
> I was wondering if there was an easy way to to make a conflict handler 
> that causes "new data" to always be copied. 
>
> In other words, lets say we have database ONE and TWO. To start with, 
> both databases have the same data. Database ONE has a row updated. Now 
> the two databases are in conflict. The newer data in database ONE 
> should be copied to database TWO. 
>
> Database TWO has a row updated, the databases are in conflict. The 
> newer data from database TWO is copied to database ONE. Essentially 
> the newest data always wins. 
>
> I figure one way to do this would be add a timestamp column to all my 
> tables, and compare the two timestamps. I would like to, however, 
> stray away from altering my schema as much as possible. 
>

Hi Ben,
   You should be able to do this with a custom conflict handler that 
compares the transaction timestamp recorded in the bucardo_delta tables 
on each database.  That way you don't need to touch your tables to find 
out which is newer.  Your custom handler might look something like this:

my ($arg) = @_;
my $source_time = $arg->{sourcerow}->{BUCARDO_TXNTIME};
my $target_time = $arg->{targetrow}->{BUCARDO_TXNTIME};

# Source is more recent, it wins
return 1 if ($source_time > $target_time);

# Else target wins
return 2;

   Greg, please correct me if I missed anything.


-spencer christensen
www.backcountry.com




More information about the Bucardo-general mailing list