question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SqlSyncChangeTrackingProvider using on SQLServer 2019 cause table lock with _bulkdelete procedure

See original GitHub issue

Hi,

Recently, I test applying Change Tracking of SQL Server 2019 by using SqlSyncChangeTrackingProvider as the document. But _bulkdelete causes table locking and sometimes DMS throws exception ‘Invalid Object … _tracking table’. Here is my case in _bulkdelete procedure: `SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[TopssPartBoFollowUpSync_bulkdelete] @sync_min_timestamp bigint, @sync_scope_id uniqueidentifier, @changeTable [dbo].[TopssPartBoFollowUpSync_BulkType] READONLY AS BEGIN – use a temp table to store the list of PKs that successfully got deleted declare @dms_changed TABLE ([Id] [bigint], PRIMARY KEY ( [Id]));

DECLARE @var_sync_scope_id varbinary(128) = cast(@sync_scope_id as varbinary(128));

;WITH CHANGE_TRACKING_CONTEXT(@var_sync_scope_id), [TopssPartBoFollowUpSync_tracking] AS ( SELECT [p].[Id], CAST([CT].[SYS_CHANGE_CONTEXT] as uniqueidentifier) AS [update_scope_id], [CT].[SYS_CHANGE_VERSION] as [timestamp], CASE WHEN [CT].[SYS_CHANGE_OPERATION] = ‘D’ THEN 1 ELSE 0 END AS [sync_row_is_tombstone] FROM @changeTable AS [p] LEFT JOIN CHANGETABLE(CHANGES [TopssPartBoFollowUpSync], @sync_min_timestamp) AS [CT] ON [p].[Id] = [CT].[Id] ) DELETE [TopssPartBoFollowUpSync] OUTPUT DELETED.[Id] INTO @dms_changed FROM [TopssPartBoFollowUpSync] [base] JOIN [TopssPartBoFollowUpSync_tracking] [changes] ON [changes].[Id] = [base].[Id] WHERE [changes].[timestamp] <= @sync_min_timestamp OR [changes].[timestamp] IS NULL OR [changes].[update_scope_id] = @sync_scope_id;

–Select all ids not inserted / deleted / updated as conflict SELECT [Id] FROM @changeTable [t] WHERE NOT EXISTS ( SELECT [Id] FROM @dms_changed [i] WHERE [t].[Id] = [i].[Id] )

END GO`

and .NetCore code, I set SyncOptions as below: SyncOptions syncOption = new SyncOptions { ConflictResolutionPolicy = ConflictResolutionPolicy.ClientWins };

image

What is the solution to this issue? Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Mimetiscommented, Aug 3, 2021

I’m currently in vacation, but I guess, the next release will be released in early September

0reactions
tamdtvncommented, Jul 26, 2021

I already tested OK following your suggestion. When is version 0.8.1 release? I’m looking forward to applying this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve blocking problem caused by lock escalation - SQL ...
This article describes how to determine if lock escalation is causing blocking and how to resolve the problem.
Read more >
sql server - Can I avoid TABLOCKX on DELETE?
By default, a DELETE statement always acquires an exclusive (X) lock on the table it modifies, and holds that lock until the transaction ......
Read more >
Creating a SQL Server audit using SQL Server Change ...
SQL Server Change Tracking is considered a legacy SQL Server Audit solution, that can be used to track and audit the database table...
Read more >
13.3.6 LOCK TABLES and UNLOCK TABLES Statements
For view locking, LOCK TABLES adds all base tables used in the view to the set of tables to be locked and locks...
Read more >
SQL Server Change Tracking Performance Troubleshooting
Learn how to use SQL Server Change Tracking as well as ways performance troubleshooting and management.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found