diff options
Diffstat (limited to 'src/backend/commands/sequence.c')
| -rw-r--r-- | src/backend/commands/sequence.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 27cb6307581..ab592ce2f15 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -378,8 +378,13 @@ fill_seq_with_data(Relation rel, HeapTuple tuple) /* check the comment above nextval_internal()'s equivalent call. */ if (RelationNeedsWAL(rel)) + { GetTopTransactionId(); + if (XLogLogicalInfoActive()) + GetCurrentTransactionId(); + } + START_CRIT_SECTION(); MarkBufferDirty(buf); @@ -399,6 +404,7 @@ fill_seq_with_data(Relation rel, HeapTuple tuple) XLogRegisterBuffer(0, buf, REGBUF_WILL_INIT); xlrec.node = rel->rd_node; + xlrec.created = true; XLogRegisterData((char *) &xlrec, sizeof(xl_seq_rec)); XLogRegisterData((char *) tuple->t_data, tuple->t_len); @@ -764,10 +770,28 @@ nextval_internal(Oid relid, bool check_permissions) * It's sufficient to ensure the toplevel transaction has an xid, no need * to assign xids subxacts, that'll already trigger an appropriate wait. * (Have to do that here, so we're outside the critical section) + * + * We have to ensure we have a proper XID, which will be included in + * the XLOG record by XLogRecordAssemble. Otherwise the first nextval() + * in a subxact (without any preceding changes) would get XID 0, and it + * would then be impossible to decide which top xact it belongs to. + * It'd also trigger assert in DecodeSequence. We only do that with + * wal_level=logical, though. + * + * XXX This might seem unnecessary, because if there's no XID the xact + * couldn't have done anything important yet, e.g. it could not have + * created a sequence. But that's incorrect, because of subxacts. The + * current subtransaction might not have done anything yet (thus no XID), + * but an earlier one might have created the sequence. */ if (logit && RelationNeedsWAL(seqrel)) + { GetTopTransactionId(); + if (XLogLogicalInfoActive()) + GetCurrentTransactionId(); + } + /* ready to change the on-disk (or really, in-buffer) tuple */ START_CRIT_SECTION(); @@ -803,6 +827,7 @@ nextval_internal(Oid relid, bool check_permissions) seq->log_cnt = 0; xlrec.node = seqrel->rd_node; + xlrec.created = false; XLogRegisterData((char *) &xlrec, sizeof(xl_seq_rec)); XLogRegisterData((char *) seqdatatuple.t_data, seqdatatuple.t_len); @@ -977,8 +1002,13 @@ do_setval(Oid relid, int64 next, bool iscalled) /* check the comment above nextval_internal()'s equivalent call. */ if (RelationNeedsWAL(seqrel)) + { GetTopTransactionId(); + if (XLogLogicalInfoActive()) + GetCurrentTransactionId(); + } + /* ready to change the on-disk (or really, in-buffer) tuple */ START_CRIT_SECTION(); @@ -999,6 +1029,8 @@ do_setval(Oid relid, int64 next, bool iscalled) XLogRegisterBuffer(0, buf, REGBUF_WILL_INIT); xlrec.node = seqrel->rd_node; + xlrec.created = false; + XLogRegisterData((char *) &xlrec, sizeof(xl_seq_rec)); XLogRegisterData((char *) seqdatatuple.t_data, seqdatatuple.t_len); |
