August 2, 2012 at 1:34 am
Hi,
We are setting up a POC of SQL replication between two indentical SQL server (including hardware).
The concurrent updates (same record updated in both the DB at same time) are failed and replication continued to fail until we fix it manually (see the details below).
It is in SQL 2008 R2 - peer to peer replication.
Is this the real nature of replication, if this is the case what is best practice to have a load balanced environment.
--- Error message --------------
Command attempted:
if @@trancount > 0 rollback tran
(Transaction sequence number: 0x0000002600000142000700000000, Command ID: 1)
Error messages:
•A conflict of type 'Update-Update' was detected at peer 1 between peer 2 (incoming), transaction id 0x0000000000000ab5 and peer 1 (on disk), transaction id 0x000000000000039e (Source: MSSQLServer, Error number: 22815)
Get help: http://help/22815
A conflict of type 'Update-Update' was detected at peer 1 between peer 2 (incoming), transaction id 0x0000000000000ab5 and peer 1 (on disk), transaction id 0x000000000000039e (Source: MSSQLServer, Error number: 22815)
Get help: http://help/22815
Thanks
Berch
August 2, 2012 at 3:10 am
Never used peer to peer replication before, but found this article, hope it helps.
August 3, 2012 at 6:18 am
It's the nature of the beast (2-way replication) regardless of the RDBMS. Collisions are going to happen. IMO if you can't come up with an algorithm to decide which client wins, the best way to minimize them is with application partitioning. That is, place all clients that are likely to update the same rows, on the same server. That way the locking mechanisms will prevent transactions from stepping on each other.
Another thing to consider is that 90% of DB activity is read-only (in most cases). You might consider writing your application to do all DML on a single server and replicate to other servers that are read-only. In this scenario, SELECT's can be load balanced across all servers, while DML goes to just one. In this scenario you could use any of several methods to synchronize the read-only servers. Either transactional replication, mirroring (with snapshots) or log shipping (in standby mode). With both of these methods however, the replica will always be a few minutes behind the primary db depending on how often the agent jobs run.
August 6, 2012 at 8:03 am
P2P is inherently a multi-master system. If you update the same row in multiple peers at the same time you will get an update conflict.
SQL 2008 R2 allows automatic update conflict resolution, by saying the server with the lowest name in the collation sequence wins. You can also get automatic logging of the data that has been lost, so you can decide what to do about it.
We are in the final stages of going live with a P2P environment running within AWS. For us the main benefit of P2P is fast and relatively simple failover.
We have decided to route all our updates to a single node, so that we never get update conflicts. For us this is easy, as all updates are done from our web applications and all web applications use a common connection string to identify the server that hosts the updates. We use a DNS vanity name to identify our 'master write server', so if we have to move updates to another node then all we have to change is the IP address referenced by the vanity name.
Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.
When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara
August 6, 2012 at 11:58 am
Use the Microsoft SYNC framework. Takes out the guesswork.
August 6, 2012 at 12:34 pm
tim.cloud (8/6/2012)
Use the Microsoft SYNC framework. Takes out the guesswork.
o you have a sample article or any information about putting this together? Since they have deprecated Transactional Replication with Updatable Subscriptions in 2012, this will be a possible route for me.
Jared
CE - Microsoft
August 6, 2012 at 12:37 pm
I used this tutorial from Microsoft:
http://msdn.microsoft.com/en-us/library/ff928700.aspx
It actually works very well, and the only object type that is not supported is FileStream.
August 6, 2012 at 12:45 pm
tim.cloud (8/6/2012)
I used this tutorial from Microsoft:http://msdn.microsoft.com/en-us/library/ff928700.aspx
It actually works very well, and the only object type that is not supported is FileStream.
Interesting. Though it seems to be a lot of extra work to add a simple "article." Am I understanding that correctly? I would have to go back and change the C# code every time I add a new article?
Jared
CE - Microsoft
August 6, 2012 at 12:48 pm
Yes, that is the only drawback I could find.
However, I can tell you first hand that it does work, and it's a pretty flexible solution other than having to maintain the C# code.
August 6, 2012 at 12:50 pm
tim.cloud (8/6/2012)
Yes, that is the only drawback I could find.However, I can tell you first hand that it does work, and it's a pretty flexible solution other than having to maintain the C# code.
Thanks for sharing!
Jared
CE - Microsoft
August 7, 2012 at 6:44 am
Even if you use Sync Framework to do P2P data propogation, this does not overcome having to deal with update conflicts.
Your design either needs to accept that conflicts will occurr and include a process for dealing with them, or eliminate the possibility of a conflict ocurring.
Imagine a P2P system dealing with your personal bank account. You make a deposit of 1000 in a bank while buying an event ticket for 50 on your mobe. The two transactions are processed by different peer systems and the updates conflict. Most conflict resolution processes end up deciding one of the updates will be lost. Do you want to loose your deposit, or loose the event ticket?
Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.
When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara
August 7, 2012 at 6:48 am
Neither. I want the transactions serialized. That's why I always favor eliminating the possibility of conflicts by application partitioning, DML segregation, or both.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply