You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pg_shardman--1.0.sql
+40-25Lines changed: 40 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -1996,34 +1996,49 @@ END;
1996
1996
$$ LANGUAGE plpgsql;
1997
1997
1998
1998
1999
-
-- Detect distributed deadlock and return set of process involed in deadlock. If there is no deadlock then this view ias empty.
2000
-
--
2001
-
-- This query is based on the algorithm described by Knuth for detecting a cycle in a linked list. In one column, keep track of the children,
2002
-
-- the children's children, the children's children's children, etc. In another column, keep track of the grandchildren, the grandchildren's grandchildren,
2003
-
-- the grandchildren's grandchildren's grandchildren, etc.
2004
-
--
2005
-
-- For the initial selection, the distance between Child and Grandchild columns is 1. Every selection from union all increases the depth of Child by 1, and that of Grandchild by 2.
2006
-
-- The distance between them increases by 1.
2007
-
--
2008
-
-- If there is any loop, since the distance only increases by 1 each time, at some point after Child is in the loop, the distance will be a multiple of the cycle length.
2009
-
-- When that happens, the Child and the Grandchild columns are the same. Use that as an additional condition to stop the recursion, and detect it in the rest of your code as an error.
2010
-
CREATEVIEWdeadlockAS
1999
+
-- Detect distributed deadlock and returns path in the lock graph forming deadlock loop
2000
+
CREATEFUNCTIONdetect_deadlock() RETURNS shardman.process[] AS $$
2011
2001
WITH RECURSIVE LinkTable AS (SELECT wait AS Parent, hold AS Child FROMshardman.deserialize_lock_graph(shardman.global_lock_graph())),
0 commit comments