HOT + MVCC-safe cluster conflict fix - Mailing list pgsql-patches

From Heikki Linnakangas
Subject HOT + MVCC-safe cluster conflict fix
Date
Msg-id 46275DA0.1070307@enterprisedb.com
Whole thread Raw
Responses Re: HOT + MVCC-safe cluster conflict fix  ("Pavan Deolasee" <pavan.deolasee@gmail.com>)
Re: HOT + MVCC-safe cluster conflict fix  (Bruce Momjian <bruce@momjian.us>)
List pgsql-patches
Hi Pavan,

Here's a little patch against CVS HEAD + NewHOT-v7.0.patch to fix the
conflict between MVCC-safe cluster and HOT.

index_getnext is modified to return all tuples in a HOT chain when
called with SnapshotAny. Cluster will insert them all as normal cold
updates.

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com
Index: src/backend/access/index/indexam.c
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository2/pgsql/src/backend/access/index/indexam.c,v
retrieving revision 1.97
diff -c -r1.97 indexam.c
*** src/backend/access/index/indexam.c    5 Jan 2007 22:19:23 -0000    1.97
--- src/backend/access/index/indexam.c    19 Apr 2007 12:07:35 -0000
***************
*** 404,409 ****
--- 404,428 ----

      SCAN_CHECKS;
      GET_SCAN_PROCEDURE(amgettuple);
+
+     /*
+      * With SnapshotAny, there can be multiple visible tuples in a HOT chain,
+      * all represented by a single index entry. We need to return all of them
+      * to the caller. The first one is returned in the loop below as usual,
+      * but before we move to the next index tuple, return any remaining tuples
+      * from the previous chain.
+      */
+     if (BufferIsValid(scan->xs_cbuf) && scan->xs_snapshot == SnapshotAny)
+     {
+         bool found;
+
+         LockBuffer(scan->xs_cbuf, BUFFER_LOCK_SHARE);
+         found = heap_hot_fetch(scan->heapRelation, scan->xs_snapshot,
+                                heapTuple, scan->xs_cbuf);
+         LockBuffer(scan->xs_cbuf, BUFFER_LOCK_UNLOCK);
+         if (found)
+             return heapTuple;
+     }

      /* just make sure this is false... */
      scan->kill_prior_tuple = false;
Index: src/backend/commands/cluster.c
===================================================================
RCS file: /home/hlinnaka/pgcvsrepository2/pgsql/src/backend/commands/cluster.c,v
retrieving revision 1.159
diff -c -r1.159 cluster.c
*** src/backend/commands/cluster.c    8 Apr 2007 01:26:28 -0000    1.159
--- src/backend/commands/cluster.c    19 Apr 2007 12:02:00 -0000
***************
*** 717,722 ****
--- 717,723 ----
                                           scan->xs_cbuf))
          {
              case HEAPTUPLE_DEAD:
+             case HEAPTUPLE_DEAD_CHAIN:
                  /* Definitely dead */
                  isdead = true;
                  break;

pgsql-patches by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Load distributed checkpoint V4
Next
From: "Pavan Deolasee"
Date:
Subject: Re: HOT + MVCC-safe cluster conflict fix