mongodb-quartz-net icon indicating copy to clipboard operation
mongodb-quartz-net copied to clipboard

Exception on creating the schedule - Unable to add lock instance for lock TriggerAccess on NON_CLUSTERED

Open prajasek-netapp opened this issue 1 year ago • 2 comments

"Quartz.JobPersistenceException: Unable to add lock instance for lock TriggerAccess on NON_CLUSTERED\n ---> System.Exception: Unable to add lock instance for lock TriggerAccess on NON_CLUSTERED\n at Quartz.Spi.MongoDbJobStore.LockManager.AddLock(LockInstance lockInstance).

This exception is not consistent.

prajasek-netapp avatar Sep 20 '24 04:09 prajasek-netapp

Hi, thanks for reporting, do you have more details? Current behaviour vs the expected one?

Thanks!

glucaci avatar Oct 04 '24 16:10 glucaci

Hi, Thanks for the reply, had figured out the issue and fixed.

Current Implementation: The AcquireLock method is designed to return a LockInstance object upon successful lock acquisition. If the attempt fails, the method retries every second. During this process, an entry with a 30-second TTL is created in the lock repository (MongoDB/CosmosDB), and a corresponding entry is added to a concurrent dictionary, keyed by Access Type and Instance ID. The lock is intended to be released upon disposal of the LockInstance object, removing entries from both the lock repository and the concurrent dictionary.

RCA (Root Cause Analysis): If an operation exceeds the 30-second threshold due to network latency or high load, the TTL mechanism will remove the database entry. This allows another instance—or potentially the same instance—to proceed with the pending operation (e.g., Schedule CRUD or Job Trigger). This new operation might successfully create a database record but fail to update the concurrent dictionary if an entry with the same key already exists, leading to operation failure.

Please let me know, so i can send the PR for review.

Thanks, Raj.

prajasek-netapp avatar Oct 07 '24 06:10 prajasek-netapp