0
点赞
收藏
分享

微信扫一扫

PostgreSQL数据库事务系统Middle Layer——StartTransactionCommand


PostgreSQL数据库事务系统Middle Layer——StartTransactionCommand_sed

StartTransactionCommand函数将事务块状态从TBLOCK_DEFAULT改为TBLOCK_STARTED,并调用底层函数StartTransaction。

void StartTransactionCommand(void) {
TransactionState s = CurrentTransactionState;
switch (s->blockState) {
/* if we aren't in a transaction block, we just do our usual start transaction. */
case TBLOCK_DEFAULT:
StartTransaction();
s->blockState = TBLOCK_STARTED;
break;
/* We are somewhere in a transaction block or subtransaction and about to start a new command. For now we do nothing, but someday we may do command-local resource initialization. (Note that any needed CommandCounterIncrement was done by the previous CommitTransactionCommand.) */
case TBLOCK_INPROGRESS:
case TBLOCK_IMPLICIT_INPROGRESS:
case TBLOCK_SUBINPROGRESS:
break;
/* Here we are in a failed transaction block (one of the commands caused an abort) so we do nothing but remain in the abort state. Eventually we will get a ROLLBACK command which will get us out of this state. (It is up to other code to ensure that no commands other than ROLLBACK will be processed in these states.) */
case TBLOCK_ABORT:
case TBLOCK_SUBABORT:
break;
/* These cases are invalid. */
case TBLOCK_STARTED:
case TBLOCK_BEGIN:
case TBLOCK_PARALLEL_INPROGRESS:
case TBLOCK_SUBBEGIN:
case TBLOCK_END:
case TBLOCK_SUBRELEASE:
case TBLOCK_SUBCOMMIT:
case TBLOCK_ABORT_END:
case TBLOCK_SUBABORT_END:
case TBLOCK_ABORT_PENDING:
case TBLOCK_SUBABORT_PENDING:
case TBLOCK_SUBRESTART:
case TBLOCK_SUBABORT_RESTART:
case TBLOCK_PREPARE:
elog(ERROR, "StartTransactionCommand: unexpected state %s", BlockStateAsString(s->blockState));
break;
}
/* We must switch to CurTransactionContext before returning. This is already done if we called StartTransaction, otherwise not. */
Assert(CurTransactionContext != NULL);
MemoryContextSwitchTo(CurTransactionContext);
}


举报

相关推荐

0 条评论