Deletes with SQL Server change tracking in a multi sync infrastructure #935
-
Hi all! I will work with a multi synchronization databases. To do this, two synchronization consoles (NET Core 5 C#) are run in parallel, one on each client. I want to synchronize the StateHistoryOnline table only. All synchronizations have the same template with its corresponding scope, so they always work with the same procedures stored in the central database. Like this: When I added or updated new rows in 'StateHistoryOnline', the sync works fine. The 'problem' is with deletes. I will try explain this: EXECUTE 1. Sync -> Client 1 (PVEGFF) - Server EXECUTE 2. Sync -> Client 2 (EGYSO2) - Server EXECUTE 3. Sync -> Client 2 (EGYSO2) - Server EXECUTE 4. Sync -> Client 1 (PVEGFF) - Server Why are conflicts generated? The complete examples |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
To understand correctly, you need to know how changes are tracked. The main problem with Deletes (when you have filters) is that the only thing you have to retrieve the deletes rows is the rows in the tracking tables, identified by the primary keys (and sync_row_is_tombstone = 1) When rows are deleted, you just can't apply filters (as the rows are deleted :D) That means that you can't apply filters when you are retrieving the deleted rows, as the rows don't exist anymore in the tables themselves. That means a row deleted on Client 1 will be sent to all other clients as a delete operation. agent.RemoteOrchestrator.OnApplyChangesConflictOccured(async args =>
{
args.Resolution = ConflictResolution.ClientWins;
var conflict = await args.GetSyncConflictAsync();
Debug.WriteLine(conflict.Type);
}); You will probably have a conflict type In that particular case, DMS will just pass, and will do nothing locally (as the row is not existing) but will increment the conflicts count. Make sense ? |
Beta Was this translation helpful? Give feedback.
-
Yes Sebastien, I understand. |
Beta Was this translation helpful? Give feedback.
-
I think use a logical DELETE for these table, is my solution. |
Beta Was this translation helpful? Give feedback.
To understand correctly, you need to know how changes are tracked.
Basically, the tracking tables have a 1-1 relation with the main table, using the table Primary Keys.
SQL Server Change Tracking works the same (at least this is how we are using it in DMS)
Tracking the rows changed, and returning the primary keys.
The main problem with Deletes (when you have filters) is that the only thing you have to retrieve the deletes rows is the rows in the tracking tables, identified by the primary keys (and sync_row_is_tombstone = 1)
When rows are deleted, you just can't apply filters (as the rows are deleted :D)
That means that you can't apply filters when you are retrieving the deleted rows, as t…