}
/*
- * 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)
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. */
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,
}
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);
}
}
+/*
+ * Release a tuple, read with sequence_read_tuple, without saving it
+ */
void
sequence_release_tuple(SequenceHandle *seqh)
{