microsoft / microsoft/Dynamics-365-FastTrack-Implementation-Assets

Table Locking caused by (DataLakeToSynapse_InsertIntoControlTableForCopy SPROC

Open
#246 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
494
Forks
296
Avg merge
1d 10h
Merged PRs (30d)
5

Description

The CDM Utils created SPROC (DataLakeToSynapse_InsertIntoControlTableForCopy) used to insert new table records in the control table, is causing a table (not row) lock when attempting to do the insert. It does this because it is using a WHERE NOT EXISTS clause in the WHERE clause of the Insert.

The table lock is resulting in excessive wait times and causes the new record inserts to fail. This is issue is compounded because the function app needs to loop through all tables- so essentially hundred of queries checking if a row exists and effectively locking the table.

The stored procedure that does the insert into the control table is created by the CDM Utils function app. If the stored procedure is dropped or altered the, function app will automatically recreate it. Even if the function app web service is stopped, and the SPROC is recreated/altered, the function app will drop and recreate it with the original code at some point. So currently there is no way to modify the SPROC code except by modifying the function app- which is something I would like to avoid. The SPROC is called by the function app directly, so recreating it with another name would have no benefit.

An alternative approach is needed to avoid table locking such as:

IF (SELECT COUNT([TableName]) FROM [dbo].[DataLakeToSynapse_ControlTableForCopy]
WHERE [TableName]=@TableName)=0**

BEGIN

INSERT INTO [dbo].[DataLakeToSynapse_ControlTableForCopy](TableName, DataLocation,FileFormat, CDCDataLocation, MetadataLocation)
SELECT * FROM
(SELECT @TableName, @DataLocation, @FileFormat, @CDCDataLocation, @MetadataLocation) as i (TableName, DataLocation, FileFormat, CDCDataLocation, MetadataLocation)

I am requesting assistance in the form of a change to the function app, or suggestions on how to avoid the issue.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the CDM Utils function app code that creates DataLakeToSynapse_InsertIntoControlTableForCopy and inspect how it inserts into DataLakeToSynapse_ControlTableForCopy. Reproduce concurrent inserts and compare locking and wait behavior; done means the generated stored procedure no longer causes table-level locking and new records insert successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.