Looking for 'dead' locks
Can anybody share a code looking for 'dead' locks?
It's not trivial to find such locks manually when there are many records in lock table.
Can anybody share a code looking for 'dead' locks?
It's not trivial to find such locks manually when there are many records in lock table.
What do you mean by dead locks ?
As I'm not sure what you mean by 'dead' locks, I'll just show simple code for looking all locks in current namespace
Thank you Dmitry for response.
I need to detect only all mutual dependence of locks and locks attempts of different processes.
Dead lock sample:
1 process: Lock +^Glb(1)
2 process: Lock +^Glb(2)
1 process: Lock +^Glb(2)
2 process: Lock +^Glb(1)
1 process waiting for unlocking of ^Glb(2). But it's impossible because 2 processes is waiting unlocking of 1 process node.
^$LOCK contain information only about successful locks. Do detect 'dead' locks we need information about lock attempts too (%SYS.LockQuery:WebList query result that SMP displays).
SMP 'View Lock' mode can display thousands of records. But I need to filter only mutual dependence of locks.
You can use the information from %SYS.LockQuery to graph the locks with their owners and waiters. Then do a depth-first traversal of each node, looking for a cycle.
Here's a sketch of building the graph:
The graph looks something like this:
I've generated IDs for the locks to avoid a SUBSCRIPT error for long references. You'll want to keep a list of the original lock names.
Here's a (minimally tested) traversal method that returns an error if it finds a cycle:
If you try it on the previous graph, it will return an error like the following:
Many thanks John for idea. It's more easier to use WaiterPID values.
One correction to your code:
WaiterPID values are separated by "," not by " "