On 2019-Jan-04, Peter Eisentraut wrote:
> Your reasoning seems correct to me.
>
> Maybe add a code comment along the lines of "once we have found the
> right ... we don't need to check the remaining ...".
>
> Or, you can make this even more clear by comparing the backendId
> directly with the proc entry:
I did both (the second idea was a non-obvious very nice cleanup --
thanks). Patch attached.
However, now I realize that this code is not covered at all, so I'll put
this patch to sleep until I write some test for it.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index faa46742bf..984ab7258a 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -2679,13 +2679,10 @@ CancelVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode)
{
int pgprocno = arrayP->pgprocnos[index];
PGPROC *proc = &allProcs[pgprocno];
- VirtualTransactionId procvxid;
- GET_VXID_FROM_PGPROC(procvxid, *proc);
-
- if (procvxid.backendId == vxid.backendId)
+ if (vxid.backendId == proc->backendId)
{
- if (procvxid.localTransactionId == vxid.localTransactionId)
+ if (vxid.localTransactionId == proc->lxid)
{
proc->recoveryConflictPending = true;
pid = proc->pid;
@@ -2695,9 +2692,14 @@ CancelVirtualTransaction(VirtualTransactionId vxid, ProcSignalReason sigmode)
* Kill the pid if it's still here. If not, that's what we
* wanted so ignore any errors.
*/
- (void) SendProcSignal(pid, sigmode, vxid.backendId);
+ (void) SendProcSignal(pid, sigmode, proc->backendId);
}
}
+
+ /*
+ * As soon as we find the right proc entry, we don't need to check
+ * the remaining ones.
+ */
break;
}
}