]> granicus.if.org Git - postgresql/commitdiff
TransactionIdIsInProgress is here now and gives quality answer
authorVadim B. Mikheev <vadim4o@yahoo.com>
Wed, 27 Nov 1996 07:20:07 +0000 (07:20 +0000)
committerVadim B. Mikheev <vadim4o@yahoo.com>
Wed, 27 Nov 1996 07:20:07 +0000 (07:20 +0000)
by scanning PROC structures of all running backend.

src/backend/storage/ipc/shmem.c

index 4a3ad33e9b63480d559713c1d156ef0f300ca946..4badedd32fe48c79544908f5e69e2d9b025f6bbe 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.6 1996/11/10 03:02:27 momjian Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.7 1996/11/27 07:20:07 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -64,6 +64,7 @@
 #include "storage/ipc.h"
 #include "storage/shmem.h"
 #include "storage/spin.h"
+#include "storage/proc.h"
 #include "utils/dynahash.h"
 #include "utils/hsearch.h"
 
@@ -559,4 +560,43 @@ ShmemInitStruct(char *name, unsigned long size, bool *foundPtr)
 }
 
 
+/*
+ * TransactionIdIsInProgress -- is given transaction running by some backend
+ *
+ * Strange place for this func, but we have to lookup process data structures 
+ * for all running backends. - vadim 11/26/96
+ */
+bool
+TransactionIdIsInProgress (TransactionId xid)
+{
+    BindingEnt *result;
+    PROC *proc;
+        
+    Assert (BindingTable);
+    
+    SpinAcquire(BindingLock);
+
+    (void) hash_seq ((HTAB *)NULL);
+    while ( (result = (BindingEnt *) hash_seq (BindingTable)) != NULL )
+    {
+       if ( result == (BindingEnt *) TRUE )
+       {
+           SpinRelease(BindingLock);
+           return (false);
+       }
+       if ( result->location == INVALID_OFFSET ||
+               strncmp (result->key, "PID ", 4) != 0 )
+           continue;
+       proc = (PROC *) MAKE_PTR (result->location);
+       if ( proc->xid == xid )
+       {
+           SpinRelease(BindingLock);
+           return (true);
+       }
+    }
+       
+    SpinRelease(BindingLock);
+    elog (WARN,"TransactionIdIsInProgress: BindingTable corrupted");
+    return (false);
+}