Skip to content

SqlSyncChangeTrackingProvider and unfrequently changed tables #1361

@slawomirpiotrowski

Description

@slawomirpiotrowski

Hello,

I have an application that is constantly synchronising a table from server to a set of clients (connecting with each of the clients directly by TCP) using DotMim.Sync with SqlSyncChangeTrackingProvider.
Synchronisation with each of the clients works asynchronously to not delay all synchronisations if for example one of the clients is temporary unavailable.

The problem I have is that sometimes I get an exception like this:

2025-10-09 15:27:08.362 Dotmim.Sync.SyncException: Client database is out of date. Last client sync timestamp:2264845. Last server cleanup metadata:2264846 Try to make a Reinitialize sync.

So I do a reinitialisation and a while later again:

2025-10-09 15:51:19.367 Dotmim.Sync.SyncException: Client database is out of date. Last client sync timestamp:2264846. Last server cleanup metadata:2264862 Try to make a Reinitialize sync.

What is the problem? My retention period is set to a fairly long time (4 days exactly) so last server cleanup metadata shouldn't increase that fast. I have tracked the code executed by DotMim.Sync to:

                    DECLARE @maxVersion bigint;
                    SELECT @maxVersion = MAX(CHANGE_TRACKING_MIN_VALID_VERSION(T.object_id)) 
                    FROM sys.tables T 
                    WHERE CHANGE_TRACKING_MIN_VALID_VERSION(T.object_id) is not null;

Initially it works just fine, but after a while, if some of the table are not updated at all, problems arise.

What CHANGE_TRACKING_MIN_VALID_VERSION returns for a table that was not updated during retention period at all? It returns next change tracking timestamp to be used (in the future).

So if at least one of tracked tables didn't have any changes tracked, it causes havoc - any changes to any of the other tables cause a full reinitialisation. And after that any following change to any of the tables cause yet another reinitialisation.

Any ideas how to fix that (other than doing dummy writes to each of rarely updated tables)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions