File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 23
23
*
24
24
*
25
25
* IDENTIFICATION
26
- * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.4 2005/07/31 17:19:18 tgl Exp $
26
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.5 2005/08/20 01:26:36 ishii Exp $
27
27
*
28
28
*-------------------------------------------------------------------------
29
29
*/
@@ -685,6 +685,44 @@ BackendPidGetProc(int pid)
685
685
return result ;
686
686
}
687
687
688
+ /*
689
+ * BackendXidGetPid -- get a backend's pid given its XID
690
+ *
691
+ * Returns 0 if not found or it's a prepared transaction. Note that
692
+ * it is up to the caller to be sure that the question remains
693
+ * meaningful for long enough for the answer to be used ...
694
+ *
695
+ * Only main transaction Ids are considered. This function is mainly
696
+ * useful for determining what backend owns a lock.
697
+ */
698
+ int
699
+ BackendXidGetPid (TransactionId xid )
700
+ {
701
+ int result = 0 ;
702
+ ProcArrayStruct * arrayP = procArray ;
703
+ int index ;
704
+
705
+ if (xid == InvalidTransactionId ) /* never match invalid xid */
706
+ return 0 ;
707
+
708
+ LWLockAcquire (ProcArrayLock , LW_SHARED );
709
+
710
+ for (index = 0 ; index < arrayP -> numProcs ; index ++ )
711
+ {
712
+ PGPROC * proc = arrayP -> procs [index ];
713
+
714
+ if (proc -> xid == xid )
715
+ {
716
+ result = proc -> pid ;
717
+ break ;
718
+ }
719
+ }
720
+
721
+ LWLockRelease (ProcArrayLock );
722
+
723
+ return result ;
724
+ }
725
+
688
726
/*
689
727
* IsBackendPid -- is a given pid a running backend
690
728
*/
Original file line number Diff line number Diff line change 7
7
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8
8
* Portions Copyright (c) 1994, Regents of the University of California
9
9
*
10
- * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.3 2005/07/31 17:19:22 tgl Exp $
10
+ * $PostgreSQL: pgsql/src/include/storage/procarray.h,v 1.4 2005/08/20 01:26:29 ishii Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -27,6 +27,7 @@ extern bool TransactionIdIsActive(TransactionId xid);
27
27
extern TransactionId GetOldestXmin (bool allDbs );
28
28
29
29
extern PGPROC * BackendPidGetProc (int pid );
30
+ extern int BackendXidGetPid (TransactionId xid );
30
31
extern bool IsBackendPid (int pid );
31
32
extern bool DatabaseHasActiveBackends (Oid databaseId , bool ignoreMyself );
32
33
You can’t perform that action at this time.
0 commit comments