MCPcopy Create free account
hub / github.com/apache/cloudberry / fill_seq_with_data

Function fill_seq_with_data

src/backend/commands/sequence.c:414–486  ·  view source on GitHub ↗

* Initialize a sequence's relation with the specified tuple as content */

Source from the content-addressed store, hash-verified

412 * Initialize a sequence's relation with the specified tuple as content
413 */
414static void
415fill_seq_with_data(Relation rel, HeapTuple tuple)
416{
417 Buffer buf;
418 Page page;
419 sequence_magic *sm;
420 OffsetNumber offnum;
421
422 /* Initialize first page of relation with special magic number */
423
424 buf = ReadBuffer(rel, P_NEW);
425 Assert(BufferGetBlockNumber(buf) == 0);
426
427 page = BufferGetPage(buf);
428
429 LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
430
431 PageInit(page, BufferGetPageSize(buf), sizeof(sequence_magic));
432 sm = (sequence_magic *) PageGetSpecialPointer(page);
433 sm->magic = SEQ_MAGIC;
434
435 /* Now insert sequence tuple */
436
437 /*
438 * Since VACUUM does not process sequences, we have to force the tuple to
439 * have xmin = FrozenTransactionId now. Otherwise it would become
440 * invisible to SELECTs after 2G transactions. It is okay to do this
441 * because if the current transaction aborts, no other xact will ever
442 * examine the sequence tuple anyway.
443 */
444 HeapTupleHeaderSetXmin(tuple->t_data, FrozenTransactionId);
445 HeapTupleHeaderSetXminFrozen(tuple->t_data);
446 HeapTupleHeaderSetCmin(tuple->t_data, FirstCommandId);
447 HeapTupleHeaderSetXmax(tuple->t_data, InvalidTransactionId);
448 tuple->t_data->t_infomask |= HEAP_XMAX_INVALID;
449 ItemPointerSet(&tuple->t_data->t_ctid, 0, FirstOffsetNumber);
450
451 /* check the comment above nextval_internal()'s equivalent call. */
452 if (RelationNeedsWAL(rel))
453 GetTopTransactionId();
454
455 START_CRIT_SECTION();
456
457 MarkBufferDirty(buf);
458
459 offnum = PageAddItem(page, (Item) tuple->t_data, tuple->t_len,
460 InvalidOffsetNumber, false, false);
461 if (offnum != FirstOffsetNumber)
462 elog(ERROR, "failed to add sequence tuple to page");
463
464 /* XLOG stuff */
465 if (RelationNeedsWAL(rel))
466 {
467 xl_seq_rec xlrec;
468 XLogRecPtr recptr;
469
470 XLogBeginInsert();
471 XLogRegisterBuffer(0, buf, REGBUF_WILL_INIT);

Callers 3

DefineSequenceFunction · 0.85
ResetSequenceFunction · 0.85
AlterSequenceFunction · 0.85

Calls 11

ReadBufferFunction · 0.85
BufferGetBlockNumberFunction · 0.85
LockBufferFunction · 0.85
PageInitFunction · 0.85
GetTopTransactionIdFunction · 0.85
MarkBufferDirtyFunction · 0.85
XLogBeginInsertFunction · 0.85
XLogRegisterBufferFunction · 0.85
XLogRegisterDataFunction · 0.85
XLogInsertFunction · 0.85
UnlockReleaseBufferFunction · 0.85

Tested by

no test coverage detected