12
12
*
13
13
*
14
14
* IDENTIFICATION
15
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.47 2007/04/20 20:15:52 momjian Exp $
15
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.48 2007/06/19 20:13:21 tgl Exp $
16
16
*
17
17
* Interface:
18
18
*
25
25
*/
26
26
#include "postgres.h"
27
27
28
- #include "lib/stringinfo.h"
29
28
#include "miscadmin.h"
29
+ #include "storage/lmgr.h"
30
30
#include "storage/proc.h"
31
31
#include "utils/memutils.h"
32
32
@@ -117,8 +117,9 @@ static int nDeadlockDetails;
117
117
* allocation of working memory for DeadLockCheck. We do this per-backend
118
118
* since there's no percentage in making the kernel do copy-on-write
119
119
* inheritance of workspace from the postmaster. We want to allocate the
120
- * space at startup because the deadlock checker might be invoked when there's
121
- * no free memory left.
120
+ * space at startup because (a) the deadlock checker might be invoked when
121
+ * there's no free memory left, and (b) the checker is normally run inside a
122
+ * signal handler, which is a very dangerous place to invoke palloc from.
122
123
*/
123
124
void
124
125
InitDeadLockChecking (void )
@@ -184,17 +185,17 @@ InitDeadLockChecking(void)
184
185
*
185
186
* This code looks for deadlocks involving the given process. If any
186
187
* are found, it tries to rearrange lock wait queues to resolve the
187
- * deadlock. If resolution is impossible, return TRUE --- the caller
188
- * is then expected to abort the given proc's transaction.
188
+ * deadlock. If resolution is impossible, return DS_HARD_DEADLOCK ---
189
+ * the caller is then expected to abort the given proc's transaction.
189
190
*
190
- * Caller must already have locked all partitions of the lock tables,
191
- * so standard error logging/reporting code is handled by caller.
191
+ * Caller must already have locked all partitions of the lock tables.
192
192
*
193
193
* On failure, deadlock details are recorded in deadlockDetails[] for
194
194
* subsequent printing by DeadLockReport(). That activity is separate
195
- * because we don't want to do it while holding all those LWLocks.
195
+ * because (a) we don't want to do it while holding all those LWLocks,
196
+ * and (b) we are typically invoked inside a signal handler.
196
197
*/
197
- DeadlockState
198
+ DeadLockState
198
199
DeadLockCheck (PGPROC * proc )
199
200
{
200
201
int i ,
@@ -205,11 +206,6 @@ DeadLockCheck(PGPROC *proc)
205
206
nPossibleConstraints = 0 ;
206
207
nWaitOrders = 0 ;
207
208
208
- #ifdef LOCK_DEBUG
209
- if (Debug_deadlocks )
210
- DumpAllLocks ();
211
- #endif
212
-
213
209
/* Search for deadlocks and possible fixes */
214
210
if (DeadLockCheckRecurse (proc ))
215
211
{
@@ -256,10 +252,11 @@ DeadLockCheck(PGPROC *proc)
256
252
ProcLockWakeup (GetLocksMethodTable (lock ), lock );
257
253
}
258
254
255
+ /* Return code tells caller if we had to escape a deadlock or not */
259
256
if (nWaitOrders > 0 )
260
257
return DS_SOFT_DEADLOCK ;
261
258
else
262
- return DS_DEADLOCK_NOT_FOUND ;
259
+ return DS_NO_DEADLOCK ;
263
260
}
264
261
265
262
/*
@@ -833,82 +830,7 @@ PrintLockQueue(LOCK *lock, const char *info)
833
830
#endif
834
831
835
832
/*
836
- * Append a description of a lockable object to buf.
837
- *
838
- * XXX probably this should be exported from lmgr.c or some such place.
839
- * Ideally we would print names for the numeric values, but that requires
840
- * getting locks on system tables, which might cause problems.
841
- */
842
- static void
843
- DescribeLockTag (StringInfo buf , const LOCKTAG * lock )
844
- {
845
- switch (lock -> locktag_type )
846
- {
847
- case LOCKTAG_RELATION :
848
- appendStringInfo (buf ,
849
- _ ("relation %u of database %u" ),
850
- lock -> locktag_field2 ,
851
- lock -> locktag_field1 );
852
- break ;
853
- case LOCKTAG_RELATION_EXTEND :
854
- appendStringInfo (buf ,
855
- _ ("extension of relation %u of database %u" ),
856
- lock -> locktag_field2 ,
857
- lock -> locktag_field1 );
858
- break ;
859
- case LOCKTAG_PAGE :
860
- appendStringInfo (buf ,
861
- _ ("page %u of relation %u of database %u" ),
862
- lock -> locktag_field3 ,
863
- lock -> locktag_field2 ,
864
- lock -> locktag_field1 );
865
- break ;
866
- case LOCKTAG_TUPLE :
867
- appendStringInfo (buf ,
868
- _ ("tuple (%u,%u) of relation %u of database %u" ),
869
- lock -> locktag_field3 ,
870
- lock -> locktag_field4 ,
871
- lock -> locktag_field2 ,
872
- lock -> locktag_field1 );
873
- break ;
874
- case LOCKTAG_TRANSACTION :
875
- appendStringInfo (buf ,
876
- _ ("transaction %u" ),
877
- lock -> locktag_field1 );
878
- break ;
879
- case LOCKTAG_OBJECT :
880
- appendStringInfo (buf ,
881
- _ ("object %u of class %u of database %u" ),
882
- lock -> locktag_field3 ,
883
- lock -> locktag_field2 ,
884
- lock -> locktag_field1 );
885
- break ;
886
- case LOCKTAG_USERLOCK :
887
- /* reserved for old contrib code, now on pgfoundry */
888
- appendStringInfo (buf ,
889
- _ ("user lock [%u,%u,%u]" ),
890
- lock -> locktag_field1 ,
891
- lock -> locktag_field2 ,
892
- lock -> locktag_field3 );
893
- break ;
894
- case LOCKTAG_ADVISORY :
895
- appendStringInfo (buf ,
896
- _ ("advisory lock [%u,%u,%u,%u]" ),
897
- lock -> locktag_field1 ,
898
- lock -> locktag_field2 ,
899
- lock -> locktag_field3 ,
900
- lock -> locktag_field4 );
901
- break ;
902
- default :
903
- appendStringInfo (buf ,
904
- _ ("unrecognized locktag type %d" ),
905
- lock -> locktag_type );
906
- break ;
907
- }
908
- }
909
-
910
- /*
911
- * Report a detected DS_HARD_DEADLOCK, with available details.
833
+ * Report a detected deadlock, with available details.
912
834
*/
913
835
void
914
836
DeadLockReport (void )
0 commit comments