src/backend/replication/logical/reorderbuffer.c
static ReorderBufferTXN *
ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create,
					  bool *is_new, XLogRecPtr lsn, bool create_as_top)
{
	ReorderBufferTXN *txn;
	ReorderBufferTXNByIdEnt *ent;
	bool		found;

	Assert(TransactionIdIsValid(xid));
	Assert(!create || lsn != InvalidXLogRecPtr);

	/*
	 * Check the one-entry lookup cache first
	 */
	if (TransactionIdIsValid(rb->by_txn_last_xid) &&
		rb->by_txn_last_xid == xid)
	{
		txn = rb->by_txn_last_txn;

		if (txn != NULL)
		{
			/* found it, and it's valid */
			if (is_new)
				*is_new = false;
			return txn;
		}

		/*
		 * cached as non-existent, and asked not to create? Then nothing else
		 * to do.
		 */
		if (!create)
			return NULL;
		/* otherwise fall through to create it */
	}

	/*
	 * If the cache wasn't hit or it yielded an "does-not-exist" and we want
	 * to create an entry.
	 */

	/* search the lookup table */
	ent = (ReorderBufferTXNByIdEnt *)
		hash_search(rb->by_txn,
					(void *) &xid,
					create ? HASH_ENTER : HASH_FIND,
					&found);
	if (found)
		txn = ent->txn;
	else if (create)
	{
		/* initialize the new entry, if creation was requested */
		Assert(ent != NULL);

		ent->txn = ReorderBufferGetTXN(rb);
		ent->txn->xid = xid;
		txn = ent->txn;
		txn->first_lsn = lsn;
		txn->restart_decoding_lsn = rb->current_restart_decoding_lsn;

		if (create_as_top)
		{
			dlist_push_tail(&rb->toplevel_by_lsn, &txn->node);
			AssertTXNLsnOrder(rb);
		}
	}
	else
		txn = NULL;				/* not found and not asked to create */

	/* update cache */
	rb->by_txn_last_xid = xid;
	rb->by_txn_last_txn = txn;

	if (is_new)
		*is_new = !found;

	Assert(!create || txn != NULL);
	return txn;
}
/*
 * Return the ReorderBufferTXN from the given buffer, specified by Xid.
 * If create is true, and a transaction doesn't already exist, create it
 * (with the given LSN, and as top transaction if that's specified);
 * when this happens, is_new is set to true.
 */
Return the ReorderBufferTXN from the given buffer, specified by Xid.
If create is true, and a transaction doesn't already exist, create it
(with the given LSN, and as top transaction if that's specified);
when this happens, is_new is set to true.
Return the ReorderBufferTXN from the given buffer specified by Xid . If create is true and a transaction doesn ' t already exist create it ( with the given LSN and as top transaction if that ' s specified ) ; when this happens is_new is set to true .
static ReorderBufferTXN *
ReorderBufferTXNByXid(ReorderBuffer *rb, TransactionId xid, bool create,
					  bool *is_new, XLogRecPtr lsn, bool create_as_top)
{
	ReorderBufferTXN *txn;
	ReorderBufferTXNByIdEnt *ent;
	bool		found;
	Assert(TransactionIdIsValid(xid));
	Assert(!create || lsn != InvalidXLogRecPtr);
	if (TransactionIdIsValid(rb->by_txn_last_xid) &&
		rb->by_txn_last_xid == xid)
	{
		txn = rb->by_txn_last_txn;
		if (txn != NULL)
		{
			if (is_new)
				*is_new = false;
			return txn;
		}
		if (!create)
			return NULL;
	}
	ent = (ReorderBufferTXNByIdEnt *)
		hash_search(rb->by_txn,
					(void *) &xid,
					create ? HASH_ENTER : HASH_FIND,
					&found);
	if (found)
		txn = ent->txn;
	else if (create)
	{
		Assert(ent != NULL);
		ent->txn = ReorderBufferGetTXN(rb);
		ent->txn->xid = xid;
		txn = ent->txn;
		txn->first_lsn = lsn;
		txn->restart_decoding_lsn = rb->current_restart_decoding_lsn;
		if (create_as_top)
		{
			dlist_push_tail(&rb->toplevel_by_lsn, &txn->node);
			AssertTXNLsnOrder(rb);
		}
	}
	else
		txn = NULL;				
	rb->by_txn_last_xid = xid;
	rb->by_txn_last_txn = txn;
	if (is_new)
		*is_new = !found;
	Assert(!create || txn != NULL);
	return txn;
}
static ReorderBufferTXN * ReorderBufferTXNByXid ( ReorderBuffer * rb , TransactionId xid , bool create , bool * is_new , XLogRecPtr lsn , bool create_as_top ) { ReorderBufferTXN * txn ; ReorderBufferTXNByIdEnt * ent ; bool found ; Assert ( TransactionIdIsValid ( xid ) ) ; Assert ( ! create || lsn != InvalidXLogRecPtr ) ; if ( TransactionIdIsValid ( rb -> by_txn_last_xid ) && rb -> by_txn_last_xid == xid ) { txn = rb -> by_txn_last_txn ; if ( txn != NULL ) { if ( is_new ) * is_new = false ; return txn ; } if ( ! create ) return NULL ; } ent = ( ReorderBufferTXNByIdEnt * ) hash_search ( rb -> by_txn , ( void * ) & xid , create ? HASH_ENTER : HASH_FIND , & found ) ; if ( found ) txn = ent -> txn ; else if ( create ) { Assert ( ent != NULL ) ; ent -> txn = ReorderBufferGetTXN ( rb ) ; ent -> txn -> xid = xid ; txn = ent -> txn ; txn -> first_lsn = lsn ; txn -> restart_decoding_lsn = rb -> current_restart_decoding_lsn ; if ( create_as_top ) { dlist_push_tail ( & rb -> toplevel_by_lsn , & txn -> node ) ; AssertTXNLsnOrder ( rb ) ; } } else txn = NULL ; rb -> by_txn_last_xid = xid ; rb -> by_txn_last_txn = txn ; if ( is_new ) * is_new = ! found ; Assert ( ! create || txn != NULL ) ; return txn ; }
Return the ReorderBufferTXN from the given buffer, specified by Xid.
Return the ReorderBufferTXN from the given buffer specified by Xid .
/*
	 * Check the one-entry lookup cache first
	 */ /* found it, and it's valid */ /*
		 * cached as non-existent, and asked not to create? Then nothing else
		 * to do.
		 */ /* otherwise fall through to create it */ /*
	 * If the cache wasn't hit or it yielded an "does-not-exist" and we want
	 * to create an entry.
	 */ /* search the lookup table */ /* initialize the new entry, if creation was requested */ /* not found and not asked to create */ /* update cache */