📄 transam.c
字号:
* * Recovery checking is more difficult in the case where * several backends are executing concurrently because the * transactions may be executing in the other backends. * So, we only do recovery stuff when the backend is explicitly * passed a flag on the command line. * -------------------------------- */static voidTransRecover(Relation logRelation){#ifdef NOT_USED /* ---------------- * first get the last recorded transaction in the log. * ---------------- */ TransGetLastRecordedTransaction(logRelation, logLastXid, &fail); if (fail == true) elog(ERROR, "TransRecover: failed TransGetLastRecordedTransaction"); /* ---------------- * next get the "last" and "next" variables * ---------------- */ VariableRelationGetLastXid(&varLastXid); VariableRelationGetNextXid(&varNextXid); /* ---------------- * intregity test (1) * ---------------- */ if (TransactionIdIsLessThan(varNextXid, logLastXid)) elog(ERROR, "TransRecover: varNextXid < logLastXid"); /* ---------------- * intregity test (2) * ---------------- */ /* ---------------- * intregity test (3) * ---------------- */ /* ---------------- * here we have a valid " * * **** RESUME HERE **** * ---------------- */ varNextXid = TransactionIdDup(varLastXid); TransactionIdIncrement(&varNextXid); VarPut(var, VAR_PUT_LASTXID, varLastXid); VarPut(var, VAR_PUT_NEXTXID, varNextXid);#endif}/* ---------------------------------------------------------------- * Interface functions * * InitializeTransactionLog * ======== * this function (called near cinit) initializes * the transaction log, time and variable relations. * * TransactionId DidCommit * TransactionId DidAbort * TransactionId IsInProgress * ======== * these functions test the transaction status of * a specified transaction id. * * TransactionId Commit * TransactionId Abort * TransactionId SetInProgress * ======== * these functions set the transaction status * of the specified xid. TransactionIdCommit() also * records the current time in the time relation * and updates the variable relation counter. * * ---------------------------------------------------------------- *//* * InitializeTransactionLog * Initializes transaction logging. */voidInitializeTransactionLog(void){ Relation logRelation; MemoryContext oldContext; /* ---------------- * don't do anything during bootstrapping * ---------------- */ if (AMI_OVERRIDE) return; /* ---------------- * disable the transaction system so the access methods * don't interfere during initialization. * ---------------- */ OverrideTransactionSystem(true); /* ---------------- * make sure allocations occur within the top memory context * so that our log management structures are protected from * garbage collection at the end of every transaction. * ---------------- */ oldContext = MemoryContextSwitchTo(TopMemoryContext); /* ---------------- * first open the log and time relations * (these are created by amiint so they are guaranteed to exist) * ---------------- */ logRelation = heap_openr(LogRelationName); VariableRelation = heap_openr(VariableRelationName); /* ---------------- * XXX TransactionLogUpdate requires that LogRelation * is valid so we temporarily set it so we can initialize * things properly. This could be done cleaner. * ---------------- */ LogRelation = logRelation; /* ---------------- * if we have a virgin database, we initialize the log * relation by committing the AmiTransactionId (id 512) and we * initialize the variable relation by setting the next available * transaction id to FirstTransactionId (id 514). OID initialization * happens as a side effect of bootstrapping in varsup.c. * ---------------- */ SpinAcquire(OidGenLockId); if (!TransactionIdDidCommit(AmiTransactionId)) { /* ---------------- * SOMEDAY initialize the information stored in * the headers of the log/variable relations. * ---------------- */ TransactionLogUpdate(AmiTransactionId, XID_COMMIT); TransactionIdStore(AmiTransactionId, &cachedTestXid); cachedTestXidStatus = XID_COMMIT; VariableRelationPutNextXid(FirstTransactionId); } else if (RecoveryCheckingEnabled()) { /* ---------------- * if we have a pre-initialized database and if the * perform recovery checking flag was passed then we * do our database integrity checking. * ---------------- */ TransRecover(logRelation); } LogRelation = (Relation) NULL; SpinRelease(OidGenLockId); /* ---------------- * now re-enable the transaction system * ---------------- */ OverrideTransactionSystem(false); /* ---------------- * instantiate the global variables * ---------------- */ LogRelation = logRelation; /* ---------------- * restore the memory context to the previous context * before we return from initialization. * ---------------- */ MemoryContextSwitchTo(oldContext);}/* -------------------------------- * TransactionId DidCommit * TransactionId DidAbort * TransactionId IsInProgress * -------------------------------- *//* * 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){ if (AMI_OVERRIDE) return true; return TransactionLogTest(transactionId, XID_COMMIT);}/* * TransactionIdDidAborted * True iff transaction associated with the identifier did abort. * * Note: * Assumes transaction identifier is valid. * XXX Is this unneeded? */bool /* true if given transaction aborted */TransactionIdDidAbort(TransactionId transactionId){ if (AMI_OVERRIDE) return false; return TransactionLogTest(transactionId, XID_ABORT);}/* * Now this func in shmem.c and gives quality answer by scanning * PROC structures of all running backend. - vadim 11/26/96 * * Old comments: * true if given transaction neither committed nor abortedboolTransactionIdIsInProgress(TransactionId transactionId){ if (AMI_OVERRIDE) return false; return TransactionLogTest(transactionId, XID_INPROGRESS);} *//* -------------------------------- * TransactionId Commit * TransactionId Abort * TransactionId SetInProgress * -------------------------------- *//* * TransactionIdCommit * Commits the transaction associated with the identifier. * * Note: * Assumes transaction identifier is valid. */voidTransactionIdCommit(TransactionId transactionId){ if (AMI_OVERRIDE) return; TransactionLogUpdate(transactionId, XID_COMMIT);}/* * TransactionIdAbort * Aborts the transaction associated with the identifier. * * Note: * Assumes transaction identifier is valid. */voidTransactionIdAbort(TransactionId transactionId){ if (AMI_OVERRIDE) return; TransactionLogUpdate(transactionId, XID_ABORT);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -