src/backend/replication/logical/reorderbuffer.c
static Snapshot
ReorderBufferCopySnap(ReorderBuffer *rb, Snapshot orig_snap,
					  ReorderBufferTXN *txn, CommandId cid)
{
	Snapshot	snap;
	dlist_iter	iter;
	int			i = 0;
	Size		size;

	size = sizeof(SnapshotData) +
		sizeof(TransactionId) * orig_snap->xcnt +
		sizeof(TransactionId) * (txn->nsubtxns + 1);

	snap = MemoryContextAllocZero(rb->context, size);
	memcpy(snap, orig_snap, sizeof(SnapshotData));

	snap->copied = true;
	snap->active_count = 1;		/* mark as active so nobody frees it */
	snap->regd_count = 0;
	snap->xip = (TransactionId *) (snap + 1);

	memcpy(snap->xip, orig_snap->xip, sizeof(TransactionId) * snap->xcnt);

	/*
	 * snap->subxip contains all txids that belong to our transaction which we
	 * need to check via cmin/cmax. Thats why we store the toplevel
	 * transaction in there as well.
	 */
	snap->subxip = snap->xip + snap->xcnt;
	snap->subxip[i++] = txn->xid;

	/*
	 * nsubxcnt isn't decreased when subtransactions abort, so count manually.
	 * Since it's an upper boundary it is safe to use it for the allocation
	 * above.
	 */
	snap->subxcnt = 1;

	dlist_foreach(iter, &txn->subtxns)
	{
		ReorderBufferTXN *sub_txn;

		sub_txn = dlist_container(ReorderBufferTXN, node, iter.cur);
		snap->subxip[i++] = sub_txn->xid;
		snap->subxcnt++;
	}

	/* sort so we can bsearch() later */
	qsort(snap->subxip, snap->subxcnt, sizeof(TransactionId), xidComparator);

	/* store the specified current CommandId */
	snap->curcid = cid;

	return snap;
}
/*
 * Copy a provided snapshot so we can modify it privately. This is needed so
 * that catalog modifying transactions can look into intermediate catalog
 * states.
 */
Copy a provided snapshot so we can modify it privately. This is needed so
that catalog modifying transactions can look into intermediate catalog
states.
Copy a provided snapshot so we can modify it privately . This is needed so that catalog modifying transactions can look into intermediate catalog states .
static Snapshot
ReorderBufferCopySnap(ReorderBuffer *rb, Snapshot orig_snap,
					  ReorderBufferTXN *txn, CommandId cid)
{
	Snapshot	snap;
	dlist_iter	iter;
	int			i = 0;
	Size		size;
	size = sizeof(SnapshotData) +
		sizeof(TransactionId) * orig_snap->xcnt +
		sizeof(TransactionId) * (txn->nsubtxns + 1);
	snap = MemoryContextAllocZero(rb->context, size);
	memcpy(snap, orig_snap, sizeof(SnapshotData));
	snap->copied = true;
	snap->active_count = 1;		
	snap->regd_count = 0;
	snap->xip = (TransactionId *) (snap + 1);
	memcpy(snap->xip, orig_snap->xip, sizeof(TransactionId) * snap->xcnt);
	snap->subxip = snap->xip + snap->xcnt;
	snap->subxip[i++] = txn->xid;
	snap->subxcnt = 1;
	dlist_foreach(iter, &txn->subtxns)
	{
		ReorderBufferTXN *sub_txn;
		sub_txn = dlist_container(ReorderBufferTXN, node, iter.cur);
		snap->subxip[i++] = sub_txn->xid;
		snap->subxcnt++;
	}
	qsort(snap->subxip, snap->subxcnt, sizeof(TransactionId), xidComparator);
	snap->curcid = cid;
	return snap;
}
static Snapshot ReorderBufferCopySnap ( ReorderBuffer * rb , Snapshot orig_snap , ReorderBufferTXN * txn , CommandId cid ) { Snapshot snap ; dlist_iter iter ; int i = 0 ; Size size ; size = sizeof ( SnapshotData ) + sizeof ( TransactionId ) * orig_snap -> xcnt + sizeof ( TransactionId ) * ( txn -> nsubtxns + 1 ) ; snap = MemoryContextAllocZero ( rb -> context , size ) ; memcpy ( snap , orig_snap , sizeof ( SnapshotData ) ) ; snap -> copied = true ; snap -> active_count = 1 ; snap -> regd_count = 0 ; snap -> xip = ( TransactionId * ) ( snap + 1 ) ; memcpy ( snap -> xip , orig_snap -> xip , sizeof ( TransactionId ) * snap -> xcnt ) ; snap -> subxip = snap -> xip + snap -> xcnt ; snap -> subxip [ i ++ ] = txn -> xid ; snap -> subxcnt = 1 ; dlist_foreach ( iter , & txn -> subtxns ) { ReorderBufferTXN * sub_txn ; sub_txn = dlist_container ( ReorderBufferTXN , node , iter . cur ) ; snap -> subxip [ i ++ ] = sub_txn -> xid ; snap -> subxcnt ++ ; } qsort ( snap -> subxip , snap -> subxcnt , sizeof ( TransactionId ) , xidComparator ) ; snap -> curcid = cid ; return snap ; }
Copy a provided snapshot so we can modify it privately.
Copy a provided snapshot so we can modify it privately .
/* mark as active so nobody frees it */ /*
	 * snap->subxip contains all txids that belong to our transaction which we
	 * need to check via cmin/cmax. Thats why we store the toplevel
	 * transaction in there as well.
	 */ /*
	 * nsubxcnt isn't decreased when subtransactions abort, so count manually.
	 * Since it's an upper boundary it is safe to use it for the allocation
	 * above.
	 */ /* sort so we can bsearch() later */ /* store the specified current CommandId */