Re: Re: [PATCHES] Patch to support transactions with BLOBs for current CVS - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Re: [PATCHES] Patch to support transactions with BLOBs for current CVS
Date
Msg-id 200101210358.WAA03449@candle.pha.pa.us
Whole thread Raw
In response to Re: Re: [PATCHES] Patch to support transactions with BLOBs for current CVS  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: Re: [PATCHES] Patch to support transactions with BLOBs for current CVS
List pgsql-hackers
Sorry, here is a clean version of the patch.

> > http://www.postgresql.org/mhonarc/pgsql-patches/2000-11/msg00013.html
>
> Can people comment on the following patch that Dennis says is needed?
> It prevents BLOB operations outside transactions.  Dennis, can you
> explain why BLOB operations have to be done inside transactions?
>
> ---------------------------------------------------------------------------
> Hello,
>
> here is the patch attached which do check in each BLOB operation, if we are
> in transaction, and raise an error otherwise. This will prevent such
> mistakes.
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: inv_api.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v
retrieving revision 1.80
diff -u -r1.80 inv_api.c
--- inv_api.c    2000/11/02 23:52:06    1.80
+++ inv_api.c    2000/11/03 16:57:57
@@ -64,6 +64,9 @@
     Oid            file_oid;
     LargeObjectDesc *retval;

+    if (!IsTransactionBlock())
+        elog(ERROR, "inv_create: Not in transaction. BLOBs should be used inside transaction.");
+
     /*
      * Allocate an OID to be the LO's identifier.
      */
@@ -117,6 +120,9 @@
 {
     LargeObjectDesc *retval;

+    if (!IsTransactionBlock())
+        elog(ERROR, "inv_open: Not in transaction. BLOBs should be used inside transaction.");
+
     if (! LargeObjectExists(lobjId))
         elog(ERROR, "inv_open: large object %u not found", lobjId);

@@ -145,6 +151,9 @@
 void
 inv_close(LargeObjectDesc *obj_desc)
 {
+    if (!IsTransactionBlock())
+        elog(ERROR, "inv_close: Not in transaction. BLOBs should be used inside transaction.");
+
     Assert(PointerIsValid(obj_desc));

     if (obj_desc->flags & IFS_WRLOCK)
@@ -164,6 +173,9 @@
 int
 inv_drop(Oid lobjId)
 {
+    if (!IsTransactionBlock())
+        elog(ERROR, "inv_drop: Not in transaction. BLOBs should be used inside transaction.");
+
     LargeObjectDrop(lobjId);

     /*
@@ -248,6 +260,9 @@
 int
 inv_seek(LargeObjectDesc *obj_desc, int offset, int whence)
 {
+    if (!IsTransactionBlock())
+        elog(ERROR, "inv_seek: Not in transaction. BLOBs should be used inside transaction.");
+
     Assert(PointerIsValid(obj_desc));

     switch (whence)
@@ -280,6 +295,9 @@
 int
 inv_tell(LargeObjectDesc *obj_desc)
 {
+    if (!IsTransactionBlock())
+        elog(ERROR, "inv_tell: Not in transaction. BLOBs should be used inside transaction.");
+
     Assert(PointerIsValid(obj_desc));

     return obj_desc->offset;
@@ -303,6 +321,9 @@
     bytea           *datafield;
     bool            pfreeit;

+    if (!IsTransactionBlock())
+        elog(ERROR, "inv_read: Not in transaction. BLOBs should be used inside transaction.");
+
     Assert(PointerIsValid(obj_desc));
     Assert(buf != NULL);

@@ -414,6 +435,9 @@
     char            replace[Natts_pg_largeobject];
     bool            write_indices;
     Relation        idescs[Num_pg_largeobject_indices];
+
+    if (!IsTransactionBlock())
+        elog(ERROR, "inv_write: Not in transaction. BLOBs should be used inside transaction.");

     Assert(PointerIsValid(obj_desc));
     Assert(buf != NULL);

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Re: [PATCHES] Patch to support transactions with BLOBs for current CVS
Next
From: Tom Lane
Date:
Subject: Re: Re: [PATCHES] Patch to support transactions with BLOBs for current CVS