本文整理汇总了C++中TransactionIdIsValid函数的典型用法代码示例。如果您正苦于以下问题:C++ TransactionIdIsValid函数的具体用法?C++ TransactionIdIsValid怎么用?C++ TransactionIdIsValid使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TransactionIdIsValid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SubTransSetParent
/*
* Record the parent of a subtransaction in the subtrans log.
*
* In some cases we may need to overwrite an existing value.
*/
void
SubTransSetParent(TransactionId xid, TransactionId parent, bool overwriteOK)
{
int pageno = TransactionIdToPage(xid);
int entryno = TransactionIdToEntry(xid);
int slotno;
TransactionId *ptr;
Assert(TransactionIdIsValid(parent));
LWLockAcquire(SubtransControlLock, LW_EXCLUSIVE);
slotno = SimpleLruReadPage(SubTransCtl, pageno, true, xid);
ptr = (TransactionId *) SubTransCtl->shared->page_buffer[slotno];
ptr += entryno;
/* Current state should be 0 */
Assert(*ptr == InvalidTransactionId ||
(*ptr == parent && overwriteOK));
*ptr = parent;
SubTransCtl->shared->page_dirty[slotno] = true;
LWLockRelease(SubtransControlLock);
}
示例2: SubTransSetParent
/*
* Record the parent of a subtransaction in the subtrans log.
*/
void
SubTransSetParent(TransactionId xid, TransactionId parent)
{
int pageno = TransactionIdToPage(xid);
int entryno = TransactionIdToEntry(xid);
int slotno;
TransactionId *ptr;
Assert(TransactionIdIsValid(parent));
Assert(TransactionIdFollows(xid, parent));
LWLockAcquire(SubtransControlLock, LW_EXCLUSIVE);
slotno = SimpleLruReadPage(SubTransCtl, pageno, true, xid);
ptr = (TransactionId *) SubTransCtl->shared->page_buffer[slotno];
ptr += entryno;
/*
* It's possible we'll try to set the parent xid multiple times but we
* shouldn't ever be changing the xid from one valid xid to another valid
* xid, which would corrupt the data structure.
*/
if (*ptr != parent)
{
Assert(*ptr == InvalidTransactionId);
*ptr = parent;
SubTransCtl->shared->page_dirty[slotno] = true;
}
LWLockRelease(SubtransControlLock);
}
示例3: DtmGetSnapshot
static Snapshot DtmGetSnapshot(Snapshot snapshot)
{
if (TransactionIdIsValid(DtmNextXid) && snapshot != &CatalogSnapshotData)
{
if (!DtmHasGlobalSnapshot && (snapshot != DtmLastSnapshot || DtmCurcid != GetCurrentCommandId(false))) {
ArbiterGetSnapshot(DtmNextXid, &DtmSnapshot, &dtm->minXid);
}
DtmLastSnapshot = snapshot;
DtmMergeWithGlobalSnapshot(snapshot);
DtmCurcid = snapshot->curcid;
if (!IsolationUsesXactSnapshot())
{
/* Use single global snapshot during all transaction for repeatable read isolation level,
* but obtain new global snapshot each time it is requested for read committed isolation level
*/
DtmHasGlobalSnapshot = false;
}
}
else
{
/* For local transactions and catalog snapshots use default GetSnapshotData implementation */
snapshot = PgGetSnapshotData(snapshot);
}
DtmUpdateRecentXmin(snapshot);
return snapshot;
}
示例4: BeginTranGTM
GlobalTransactionId
BeginTranGTM(GTM_Timestamp *timestamp)
{
GlobalTransactionId xid = InvalidGlobalTransactionId;
CheckConnection();
// TODO Isolation level
if (conn)
xid = begin_transaction(conn, GTM_ISOLATION_RC, timestamp);
/* If something went wrong (timeout), try and reset GTM connection
* and retry. This is safe at the beginning of a transaction.
*/
if (!TransactionIdIsValid(xid))
{
CloseGTM();
InitGTM();
if (conn)
xid = begin_transaction(conn, GTM_ISOLATION_RC, timestamp);
}
#ifdef XCP
if (xid)
IsXidFromGTM = true;
#endif
currentGxid = xid;
return xid;
}
示例5: PLy_procedure_argument_valid
/*
* Check if our cached information about a datatype is still valid
*/
static bool
PLy_procedure_argument_valid(PLyTypeInfo *arg)
{
HeapTuple relTup;
bool valid;
/* Nothing to cache unless type is composite */
if (arg->is_rowtype != 1)
return true;
/*
* Zero typ_relid means that we got called on an output argument of a
* function returning a unnamed record type; the info for it can't change.
*/
if (!OidIsValid(arg->typ_relid))
return true;
/* Else we should have some cached data */
Assert(TransactionIdIsValid(arg->typrel_xmin));
Assert(ItemPointerIsValid(&arg->typrel_tid));
/* Get the pg_class tuple for the data type */
relTup = SearchSysCache1(RELOID, ObjectIdGetDatum(arg->typ_relid));
if (!HeapTupleIsValid(relTup))
elog(ERROR, "cache lookup failed for relation %u", arg->typ_relid);
/* If it has changed, the cached data is not valid */
valid = (arg->typrel_xmin == HeapTupleHeaderGetXmin(relTup->t_data) &&
ItemPointerEquals(&arg->typrel_tid, &relTup->t_self));
ReleaseSysCache(relTup);
return valid;
}
示例6: ReplicationSlotsComputeRequiredXmin
/*
* Compute the oldest xmin across all slots and store it in the ProcArray.
*
* If already_locked is true, ProcArrayLock has already been acquired
* exclusively.
*/
void
ReplicationSlotsComputeRequiredXmin(bool already_locked)
{
int i;
TransactionId agg_xmin = InvalidTransactionId;
TransactionId agg_catalog_xmin = InvalidTransactionId;
Assert(ReplicationSlotCtl != NULL);
LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);
for (i = 0; i < max_replication_slots; i++)
{
ReplicationSlot *s = &ReplicationSlotCtl->replication_slots[i];
TransactionId effective_xmin;
TransactionId effective_catalog_xmin;
if (!s->in_use)
continue;
{
volatile ReplicationSlot *vslot = s;
SpinLockAcquire(&s->mutex);
effective_xmin = vslot->effective_xmin;
effective_catalog_xmin = vslot->effective_catalog_xmin;
SpinLockRelease(&s->mutex);
}
/* check the data xmin */
if (TransactionIdIsValid(effective_xmin) &&
(!TransactionIdIsValid(agg_xmin) ||
TransactionIdPrecedes(effective_xmin, agg_xmin)))
agg_xmin = effective_xmin;
/* check the catalog xmin */
if (TransactionIdIsValid(effective_catalog_xmin) &&
(!TransactionIdIsValid(agg_catalog_xmin) ||
TransactionIdPrecedes(effective_catalog_xmin, agg_catalog_xmin)))
agg_catalog_xmin = effective_catalog_xmin;
}
LWLockRelease(ReplicationSlotControlLock);
ProcArraySetReplicationSlotXmin(agg_xmin, agg_catalog_xmin, already_locked);
}
示例7: MMJoinTransaction
void MMJoinTransaction(TransactionId xid)
{
if (TransactionIdIsValid(DtmNextXid))
elog(ERROR, "dtm_begin/join_transaction should be called only once for global transaction");
DtmNextXid = xid;
if (!TransactionIdIsValid(DtmNextXid))
elog(ERROR, "Arbiter was not able to assign XID");
DtmVoted = false;
ArbiterGetSnapshot(DtmNextXid, &DtmSnapshot, &dtm->minXid);
XTM_INFO("%d: Join global transaction %d, dtm->minXid=%d\n", getpid(), DtmNextXid, dtm->minXid);
DtmHasGlobalSnapshot = true;
DtmLastSnapshot = NULL;
MMIsDistributedTrans = true;
MMMarkTransAsLocal(DtmNextXid);
}
示例8: MMBeginTransaction
void MMBeginTransaction(void)
{
if (TransactionIdIsValid(DtmNextXid))
elog(ERROR, "MMBeginTransaction should be called only once for global transaction");
if (dtm == NULL)
elog(ERROR, "DTM is not properly initialized, please check that pg_dtm plugin was added to shared_preload_libraries list in postgresql.conf");
Assert(!RecoveryInProgress());
XTM_INFO("%d: Try to start global transaction\n", getpid());
DtmNextXid = ArbiterStartTransaction(&DtmSnapshot, &dtm->minXid, dtm->nNodes);
if (!TransactionIdIsValid(DtmNextXid))
elog(ERROR, "Arbiter was not able to assign XID");
XTM_INFO("%d: Start global transaction %d, dtm->minXid=%d\n", getpid(), DtmNextXid, dtm->minXid);
DtmVoted = false;
DtmHasGlobalSnapshot = true;
DtmLastSnapshot = NULL;
MMIsDistributedTrans = false;
}
示例9: DtmSerializeLock
static void DtmSerializeLock(PROCLOCK* proclock, void* arg)
{
ByteBuffer* buf = (ByteBuffer*)arg;
LOCK* lock = proclock->tag.myLock;
PGPROC* proc = proclock->tag.myProc;
if (lock != NULL) {
PGXACT* srcPgXact = &ProcGlobal->allPgXact[proc->pgprocno];
if (TransactionIdIsValid(srcPgXact->xid) && proc->waitLock == lock) {
LockMethod lockMethodTable = GetLocksMethodTable(lock);
int numLockModes = lockMethodTable->numLockModes;
int conflictMask = lockMethodTable->conflictTab[proc->waitLockMode];
SHM_QUEUE *procLocks = &(lock->procLocks);
int lm;
ByteBufferAppendInt32(buf, srcPgXact->xid); /* waiting transaction */
proclock = (PROCLOCK *) SHMQueueNext(procLocks, procLocks,
offsetof(PROCLOCK, lockLink));
while (proclock)
{
if (proc != proclock->tag.myProc) {
PGXACT* dstPgXact = &ProcGlobal->allPgXact[proclock->tag.myProc->pgprocno];
if (TransactionIdIsValid(dstPgXact->xid)) {
Assert(srcPgXact->xid != dstPgXact->xid);
for (lm = 1; lm <= numLockModes; lm++)
{
if ((proclock->holdMask & LOCKBIT_ON(lm)) && (conflictMask & LOCKBIT_ON(lm)))
{
XTM_INFO("%d: %u(%u) waits for %u(%u)\n", getpid(), srcPgXact->xid, proc->pid, dstPgXact->xid, proclock->tag.myProc->pid);
ByteBufferAppendInt32(buf, dstPgXact->xid); /* transaction holding lock */
break;
}
}
}
}
proclock = (PROCLOCK *) SHMQueueNext(procLocks, &proclock->lockLink,
offsetof(PROCLOCK, lockLink));
}
ByteBufferAppendInt32(buf, 0); /* end of lock owners list */
}
}
}
示例10: MMMarkTransAsLocal
void MMMarkTransAsLocal(TransactionId xid)
{
LocalTransaction* lt;
Assert(TransactionIdIsValid(xid));
LWLockAcquire(dtm->hashLock, LW_EXCLUSIVE);
lt = hash_search(local_trans, &xid, HASH_ENTER, NULL);
lt->count = dtm->nNodes-1;
LWLockRelease(dtm->hashLock);
}
示例11: TransactionIdDidCommit
/*
* TransactionIdDidCommit
* True iff transaction associated with the identifier did commit.
*
* Note:
* Assumes transaction identifier is valid.
*/
bool /* true if given transaction committed */
TransactionIdDidCommit(TransactionId transactionId)
{
XidStatus xidstatus;
xidstatus = TransactionLogFetch(transactionId);
/*
* If it's marked committed, it's committed.
*/
if (xidstatus == TRANSACTION_STATUS_COMMITTED)
#ifdef PGXC
{
syncGXID_GTM((GlobalTransactionId)transactionId);
#endif
return true;
#ifdef PGXC
}
#endif
/*
* If it's marked subcommitted, we have to check the parent recursively.
* However, if it's older than TransactionXmin, we can't look at
* pg_subtrans; instead assume that the parent crashed without cleaning up
* its children.
*
* Originally we Assert'ed that the result of SubTransGetParent was not
* zero. However with the introduction of prepared transactions, there can
* be a window just after database startup where we do not have complete
* knowledge in pg_subtrans of the transactions after TransactionXmin.
* StartupSUBTRANS() has ensured that any missing information will be
* zeroed. Since this case should not happen under normal conditions, it
* seems reasonable to emit a WARNING for it.
*/
if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED)
{
TransactionId parentXid;
if (TransactionIdPrecedes(transactionId, TransactionXmin))
return false;
parentXid = SubTransGetParent(transactionId);
if (!TransactionIdIsValid(parentXid))
{
elog(WARNING, "no pg_subtrans entry for subcommitted XID %u",
transactionId);
return false;
}
return TransactionIdDidCommit(parentXid);
}
/*
* It's not committed.
*/
return false;
}
示例12: HeapTupleHeaderIsOnlyLocked
/*
* Is the tuple really only locked? That is, is it not updated?
*
* It's easy to check just infomask bits if the locker is not a multi; but
* otherwise we need to verify that the updating transaction has not aborted.
*
* This function is here because it follows the same time qualification rules
* laid out at the top of this file.
*/
bool
HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple)
{
TransactionId xmax;
/* if there's no valid Xmax, then there's obviously no update either */
if (tuple->t_infomask & HEAP_XMAX_INVALID)
return true;
if (tuple->t_infomask & HEAP_XMAX_LOCK_ONLY)
return true;
/* invalid xmax means no update */
if (!TransactionIdIsValid(HeapTupleHeaderGetRawXmax(tuple)))
return true;
/*
* if HEAP_XMAX_LOCK_ONLY is not set and not a multi, then this must
* necessarily have been updated
*/
if (!(tuple->t_infomask & HEAP_XMAX_IS_MULTI))
return false;
/* ... but if it's a multi, then perhaps the updating Xid aborted. */
xmax = HeapTupleGetUpdateXid(tuple);
/* not LOCKED_ONLY, so it has to have an xmax */
Assert(TransactionIdIsValid(xmax));
if (TransactionIdIsCurrentTransactionId(xmax))
return false;
if (TransactionIdIsInProgress(xmax))
return false;
if (TransactionIdDidCommit(xmax))
return false;
/*
* not current, not in progress, not committed -- must have aborted or
* crashed
*/
return true;
}
示例13: DtmSetTransactionStatus
static void DtmSetTransactionStatus(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn)
{
XTM_INFO("%d: DtmSetTransactionStatus %u = %u\n", getpid(), xid, status);
if (!RecoveryInProgress())
{
if (TransactionIdIsValid(DtmNextXid))
{
DtmVoted = true;
if (status == TRANSACTION_STATUS_ABORTED || !MMIsDistributedTrans)
{
PgTransactionIdSetTreeStatus(xid, nsubxids, subxids, status, lsn);
ArbiterSetTransStatus(xid, TRANSACTION_STATUS_ABORTED, false);
XTM_INFO("Abort transaction %d\n", xid);
return;
}
else
{
XidStatus verdict;
XTM_INFO("Begin commit transaction %d\n", xid);
/* Mark transaction as in-doubt in xid_in_doubt hash table */
LWLockAcquire(dtm->hashLock, LW_EXCLUSIVE);
hash_search(xid_in_doubt, &DtmNextXid, HASH_ENTER, NULL);
LWLockRelease(dtm->hashLock);
verdict = ArbiterSetTransStatus(xid, status, true);
if (verdict != status) {
XTM_INFO("Commit of transaction %d is rejected by arbiter: staus=%d\n", xid, verdict);
DtmNextXid = InvalidTransactionId;
DtmLastSnapshot = NULL;
MMIsDistributedTrans = false;
MarkAsAborted();
END_CRIT_SECTION();
elog(ERROR, "Commit of transaction %d is rejected by DTM", xid);
} else {
XTM_INFO("Commit transaction %d\n", xid);
}
}
}
else
{
XTM_INFO("Set transaction %u status in local CLOG\n" , xid);
}
}
else if (status != TRANSACTION_STATUS_ABORTED)
{
XidStatus gs;
gs = ArbiterGetTransStatus(xid, false);
if (gs != TRANSACTION_STATUS_UNKNOWN) {
Assert(gs != TRANSACTION_STATUS_IN_PROGRESS);
status = gs;
}
}
PgTransactionIdSetTreeStatus(xid, nsubxids, subxids, status, lsn);
}
示例14: SubTransGetTopmostTransaction
/*
* SubTransGetTopmostTransaction
*
* Returns the topmost transaction of the given transaction id.
*
* Because we cannot look back further than TransactionXmin, it is possible
* that this function will lie and return an intermediate subtransaction ID
* instead of the true topmost parent ID. This is OK, because in practice
* we only care about detecting whether the topmost parent is still running
* or is part of a current snapshot's list of still-running transactions.
* Therefore, any XID before TransactionXmin is as good as any other.
*/
TransactionId
SubTransGetTopmostTransaction(TransactionId xid)
{
TransactionId parentXid = xid,
previousXid = xid;
/* Can't ask about stuff that might not be around anymore */
Assert(TransactionIdFollowsOrEquals(xid, TransactionXmin));
while (TransactionIdIsValid(parentXid))
{
previousXid = parentXid;
if (TransactionIdPrecedes(parentXid, TransactionXmin))
break;
parentXid = SubTransGetParent(parentXid);
}
Assert(TransactionIdIsValid(previousXid));
return previousXid;
}
示例15: heap_prune_record_prunable
/* Record lowest soon-prunable XID */
static void
heap_prune_record_prunable(PruneState *prstate, TransactionId xid)
{
/*
* This should exactly match the PageSetPrunable macro. We can't store
* directly into the page header yet, so we update working state.
*/
Assert(TransactionIdIsNormal(xid));
if (!TransactionIdIsValid(prstate->new_prune_xid) ||
TransactionIdPrecedes(xid, prstate->new_prune_xid))
prstate->new_prune_xid = xid;
}