void DtxContextInfo_Reset(DtxContextInfo *dtxContextInfo) { dtxContextInfo->distributedTimeStamp = 0; dtxContextInfo->distributedXid = InvalidDistributedTransactionId; memcpy(dtxContextInfo->distributedId, TmGid_Init, TMGIDSIZE); Assert(strlen(dtxContextInfo->distributedId) < TMGIDSIZE); dtxContextInfo->curcid = 0; dtxContextInfo->segmateSync = 0; dtxContextInfo->nestingLevel = 0; dtxContextInfo->haveDistributedSnapshot = false; DistributedSnapshot_Reset(&dtxContextInfo->distributedSnapshot); dtxContextInfo->distributedTxnOptions = 0; }
/* * Make a copy of a DistributedSnapshot, allocating memory for the in-progress * array if necessary. */ void DistributedSnapshot_Copy( DistributedSnapshot *target, DistributedSnapshot *source) { if (source->header.maxCount <= 0 || source->header.count > source->header.maxCount) elog(ERROR,"Invalid distributed snapshot (maxCount %d, count %d)", source->header.maxCount, source->header.count); DistributedSnapshot_Reset(target); elog((Debug_print_full_dtm ? LOG : DEBUG5), "DistributedSnapshot_Copy target maxCount %d, inProgressXidArray %p, and " "source maxCount %d, count %d, inProgressXidArray %p", target->header.maxCount, target->inProgressXidArray, source->header.maxCount, source->header.count, source->inProgressXidArray); /* * If we have allocated space for the in-progress distributed * transactions, check against that space. Otherwise, * use the source maxCount as guide in allocating space. */ if (target->header.maxCount > 0) { Assert(target->inProgressXidArray != NULL); if(source->header.count > target->header.maxCount) elog(ERROR,"Too many distributed transactions for snapshot (maxCount %d, count %d)", target->header.maxCount, source->header.count); } else { Assert(target->inProgressXidArray == NULL); target->inProgressXidArray = (DistributedTransactionId*) malloc(source->header.maxCount * sizeof(DistributedTransactionId)); if (target->inProgressXidArray == NULL) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); target->header.maxCount = source->header.maxCount; } target->header.distribTransactionTimeStamp = source->header.distribTransactionTimeStamp; target->header.xminAllDistributedSnapshots = source->header.xminAllDistributedSnapshots; target->header.distribSnapshotId = source->header.distribSnapshotId; target->header.xmin = source->header.xmin; target->header.xmax = source->header.xmax; target->header.count = source->header.count; memcpy( target->inProgressXidArray, source->inProgressXidArray, source->header.count * sizeof(DistributedTransactionId)); }