zhannngchen commented on code in PR #31666: URL: https://github.com/apache/doris/pull/31666#discussion_r1512103917
########## fe/fe-core/src/main/java/org/apache/doris/transaction/TransactionEntry.java: ########## @@ -126,4 +162,119 @@ public Types.PUniqueId getpLoadId() { public void setpLoadId(Types.PUniqueId pLoadId) { this.pLoadId = pLoadId; } + + public void beginTransaction(DatabaseIf database, TableIf table) + throws DdlException, BeginTransactionException, MetaNotFoundException, AnalysisException, + QuotaExceedException { + if (isTxnBegin()) { + throw new AnalysisException( + "Transaction insert can not insert into values and insert into select at the same time"); + } + if (!isTransactionBegan) { + this.transactionId = Env.getCurrentGlobalTransactionMgr().beginTransaction( + database.getId(), Lists.newArrayList(table.getId()), label, + new TxnCoordinator(TxnSourceType.FE, FrontendOptions.getLocalHostAddress()), + LoadJobSourceType.INSERT_STREAMING, ConnectContext.get().getExecTimeout()); + this.isTransactionBegan = true; + this.database = database; + this.transactionState = Env.getCurrentGlobalTransactionMgr() + .getTransactionState(database.getId(), transactionId); + } else { + if (this.database.getId() != database.getId()) { + throw new AnalysisException( + "Transaction insert must be in the same database, expect db_id=" + this.database.getId()); + } + this.transactionState.getTableIdList().add(table.getId()); + } + } + + public TransactionStatus commitTransaction() + throws Exception { + if (isTransactionBegan) { + if (Env.getCurrentGlobalTransactionMgr() + .commitAndPublishTransaction(database, tableList, transactionId, + TabletCommitInfo.fromThrift(tabletCommitInfos), ConnectContext.get().getExecTimeout())) { + return TransactionStatus.VISIBLE; + } else { + return TransactionStatus.COMMITTED; + } + } else if (isTxnBegin()) { Review Comment: what's the difference between the previous branch `isTransactionBegan`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org