Skip to content

Deadlock Detection #39

Closed
Closed
@CMCDragonkai

Description

@CMCDragonkai

Specification

With the usage of the LockBox, we should be able to do deadlock detection. Right now we have a map in each DBTransaction called locks. This records the locks that each transaction holds.

We can have a global map of pending locks, that is keys that transactions want to lock.

When a transaction tries to lock any set of keys, it checks this global map to see if any of the other transactions want a lock on any of the keys that itself owns. It can do this by iterating over all the keys it already owns. Doing this every single time we acquire any kind of lock does seem kind of inefficient. As the number of locks grow for a given transaction, the longer it takes to check the locks it already holds is currently desired by others. One way to get around this is to only trigger deadlock detection after certain time passes, because most of the time there should not be any deadlocks.

If a lock request has a timeout, then it is exempt from the pending locks. This is up for debate, basically if a lock request has a timeout, then it will eventually timeout, so technically it won't deadlock.

Additional context

Tasks

  1. Bring in the deadlock detection system from Monitor.ts in js-async-locks
  2. Integrate Monitor into DBTransaction, we can imagine that DBTransaction can extend the Monitor, or Monitor can be an encapsulated property. An encapsulated property is probably better.
  3. Better error handling, when the Monitor throws an error due to deadlock, we can provide extra information about the DBTransaction that is causing the error... it may require some level of tracking information in the pending locks, perhaps a backlink to the transaction object.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions