Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc3991c

Browse files
committed
Add BackendXidGetPid().
1 parentf57e3f4 commitbc3991c

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

‎src/backend/storage/ipc/procarray.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
*
2525
* 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 $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -685,6 +685,44 @@ BackendPidGetProc(int pid)
685685
returnresult;
686686
}
687687

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(TransactionIdxid)
700+
{
701+
intresult=0;
702+
ProcArrayStruct*arrayP=procArray;
703+
intindex;
704+
705+
if (xid==InvalidTransactionId)/* never match invalid xid */
706+
return0;
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+
returnresult;
724+
}
725+
688726
/*
689727
* IsBackendPid -- is a given pid a running backend
690728
*/

‎src/include/storage/procarray.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -27,6 +27,7 @@ extern bool TransactionIdIsActive(TransactionId xid);
2727
externTransactionIdGetOldestXmin(boolallDbs);
2828

2929
externPGPROC*BackendPidGetProc(intpid);
30+
externintBackendXidGetPid(TransactionIdxid);
3031
externboolIsBackendPid(intpid);
3132
externboolDatabaseHasActiveBackends(OiddatabaseId,boolignoreMyself);
3233

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp