Add comments
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 20 Apr 2015 13:47:58 +0000 (16:47 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 20 Apr 2015 13:47:58 +0000 (16:47 +0300)
src/backend/commands/sequence.c

index f68dd9034f2b255754a340176d1ba2816838ef9f..a2ad7a5bbf1c1e95c298c75b5630382e8bc6554d 100644 (file)
@@ -1018,7 +1018,14 @@ sequence_read_tuple(SequenceHandle *seqh)
 }
 
 /*
- * Update the page, optionally do WAL logging of the tuple
+ * Update a sequence tuple.
+ *
+ * If 'newtup' is valid, the tuple on the page is replaced with 'newtup'.
+ * Otherwise, the caller has modified the tuple directly on the page, and
+ * we just handle WAL-logging and dirtying the buffer here.
+ *
+ * If 'do_wal' is false, the update doesn't need to be WAL-logged. After
+ * a crash, you might get an old copy of the tuple.
  */
 void
 sequence_save_tuple(SequenceHandle *seqh, HeapTuple newtup, bool do_wal)
@@ -1046,12 +1053,12 @@ sequence_save_tuple(SequenceHandle *seqh, HeapTuple newtup, bool do_wal)
        if (do_wal && RelationNeedsWAL(seqh->rel))
                GetTopTransactionId();
 
+       /*
+        * If the caller passed a new tuple, replace the old one with it.
+        * Otherwise just mark the buffer dirty and WAL-log it.
+        */
        if (HeapTupleIsValid(newtup))
        {
-               /*
-                * New tuple was passed, we must process it and replace the old one on
-                * the same page.
-                */
                Page    temppage;
 
                /* Sequence tuples are always frozen. */
@@ -1062,9 +1069,7 @@ sequence_save_tuple(SequenceHandle *seqh, HeapTuple newtup, bool do_wal)
                newtup->t_data->t_infomask |= HEAP_XMAX_INVALID;
                ItemPointerSet(&newtup->t_data->t_ctid, 0, FirstOffsetNumber);
 
-               /*
-                * Replace the original tuple on the page.
-                */
+               /* Replace the original tuple on the page. */
                temppage = PageGetTempPageCopySpecial(page);
 
                if (PageAddItem(temppage, (Item) newtup->t_data, newtup->t_len,
@@ -1087,11 +1092,6 @@ sequence_save_tuple(SequenceHandle *seqh, HeapTuple newtup, bool do_wal)
        }
        else
        {
-               /*
-                * New tuple was not sent, so the original tuple was probably just
-                * changed inline, all we need to do is mark the buffer dirty and
-                * optionally log the updated tuple.
-                */
                START_CRIT_SECTION();
 
                MarkBufferDirtyHint(seqh->buf, true);
@@ -1103,6 +1103,9 @@ sequence_save_tuple(SequenceHandle *seqh, HeapTuple newtup, bool do_wal)
        }
 }
 
+/*
+ * Release a tuple, read with sequence_read_tuple, without saving it
+ */
 void
 sequence_release_tuple(SequenceHandle *seqh)
 {