From: Heikki Linnakangas Date: Mon, 20 Apr 2015 13:47:58 +0000 (+0300) Subject: Add comments X-Git-Url: http://git.postgresql.org/gitweb/review?a=commitdiff_plain;h=a1f6bc8582240a7b7186f6055fcc434f82165e6d;p=users%2Fheikki%2Fpostgres.git Add comments --- diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index f68dd9034f..a2ad7a5bbf 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -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) {