This is an automated email from the ASF dual-hosted git repository.
wyxxxcat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new b32e4da3751 [fix](cloud) Reuse the original transaction on OLAP insert
begin retries (#71016)
b32e4da3751 is described below
commit b32e4da37515e6345cbe7a6fcabe69968e6431f6
Author: Yixuan Wang <[email protected]>
AuthorDate: Mon Nov 30 10:34:27 2026 +0800
[fix](cloud) Reuse the original transaction on OLAP insert begin retries
(#71016)
### Background
In cloud mode, the FE asks Meta Service to begin a transaction before an
OLAP INSERT writes any rows. Meta Service uses the label and request ID
to recognize repeated begin requests for the same pending transaction.
### What problem does this PR solve?
Issue Number: None
Related PR: None
PR Type: Bugfix
Problem Summary:
If Meta Service created the transaction but the FE lost the response, an
internal RPC retry could fail the INSERT with `TXN_LABEL_ALREADY_USED`.
The FE now sends the current query ID as the request ID and continues
the INSERT with the original transaction ID when Meta Service recognizes
the retry.
### Details
- **Frequency:** Intermittent. The first begin request must create the
transaction and its response must be lost before the FE retries.
- **Root cause:** Cloud OLAP INSERT omitted the request ID. On retry,
Meta Service found the label but had no request ID to match against the
pending transaction.
- **Why existing tests missed it:** The Meta Service test supplies a
request ID directly. The FE transaction manager test checks that a
duplicate response raises an exception. Neither exercises recovery
through the INSERT executor.
- **Fix:** Pass `ctx.queryId()` to `beginTransaction()` in cloud mode.
When Meta Service returns `TXN_DUPLICATED_REQ`, take the transaction ID
from `DuplicatedRequestException`. A separate INSERT with the same label
and a different query ID still gets a label conflict while the original
transaction is pending.
- **Other paths and branches:** Non-cloud INSERT keeps its existing
behavior. The OLAP INSERT executor also omits the request ID on
`branch-3.1`, `branch-4.0`, `branch-4.1`, and `branch-4.2`.
### Testing
Compiled `OlapInsertExecutor` and its parent class locally with JDK 17
against cached FE dependencies. `git diff --check` passed. No FE unit
tests or cluster regression tests were run.
### Release note
Cloud OLAP INSERT now recovers from a lost begin-transaction response
when its RPC retry finds the original pending transaction.
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Partially verified: local compilation passed.
End-to-end retry recovery was not tested.
### AI Disclosure
- Tool: OpenAI Codex (GPT-6)
- Generated: This PR description.
- Human review: Author review of this description is pending.
---
.../plans/commands/insert/OlapInsertExecutor.java | 9 ++++-
.../commands/insert/OlapInsertExecutorTest.java | 44 +++++++++++++++++++++-
2 files changed, 50 insertions(+), 3 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/OlapInsertExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/OlapInsertExecutor.java
index 9b980d5aadf..04bd9a2b8c1 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/OlapInsertExecutor.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/OlapInsertExecutor.java
@@ -25,6 +25,7 @@ import org.apache.doris.catalog.Table;
import org.apache.doris.catalog.TableIf.TableType;
import org.apache.doris.cloud.system.CloudSystemInfoService;
import org.apache.doris.common.Config;
+import org.apache.doris.common.DuplicatedRequestException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.MetaNotFoundException;
import org.apache.doris.common.UserException;
@@ -53,6 +54,7 @@ import org.apache.doris.service.FrontendOptions;
import org.apache.doris.system.Backend;
import org.apache.doris.system.SystemInfoService;
import org.apache.doris.thrift.TPartitionType;
+import org.apache.doris.thrift.TUniqueId;
import org.apache.doris.transaction.BeginTransactionException;
import org.apache.doris.transaction.TabletCommitInfo;
import org.apache.doris.transaction.TransactionState;
@@ -125,12 +127,15 @@ public class OlapInsertExecutor extends
AbstractInsertExecutor {
if (streamingInsertTask != null) {
loadJobSourceType = LoadJobSourceType.STREAMING_JOB;
}
+ TUniqueId requestId = Config.isCloudMode() ? ctx.queryId() : null;
this.txnId = Env.getCurrentGlobalTransactionMgr().beginTransaction(
- database.getId(), ImmutableList.of(table.getId()),
labelName,
+ database.getId(), ImmutableList.of(table.getId()),
labelName, requestId,
new TxnCoordinator(TxnSourceType.FE, 0,
FrontendOptions.getLocalHostAddress(),
ExecuteEnv.getInstance().getStartupTime()),
- loadJobSourceType, ctx.getExecTimeoutS());
+ loadJobSourceType, -1, ctx.getExecTimeoutS());
+ } catch (DuplicatedRequestException e) {
+ this.txnId = e.getTxnId();
} catch (Exception e) {
throw new AnalysisException("begin transaction failed. " +
e.getMessage(), e);
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/insert/OlapInsertExecutorTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/insert/OlapInsertExecutorTest.java
index 45923c5ffee..01341a2c90f 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/insert/OlapInsertExecutorTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/insert/OlapInsertExecutorTest.java
@@ -23,6 +23,8 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.EnvFactory;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.stream.TableStreamUpdateInfo;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.DuplicatedRequestException;
import org.apache.doris.common.Status;
import org.apache.doris.common.profile.ExecutionProfile;
import org.apache.doris.common.profile.Profile;
@@ -40,6 +42,7 @@ import org.apache.doris.qe.InsertResult;
import org.apache.doris.qe.QueryState.MysqlStateType;
import org.apache.doris.qe.SessionVariable;
import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.service.ExecuteEnv;
import org.apache.doris.thrift.TQueryOptions;
import org.apache.doris.thrift.TStatusCode;
import org.apache.doris.thrift.TUniqueId;
@@ -60,7 +63,7 @@ import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
/**
- * Tests for publish-timeout behaviors in {@link OlapInsertExecutor}.
+ * Tests for the transaction lifecycle in {@link OlapInsertExecutor}.
*/
class OlapInsertExecutorTest {
@@ -69,6 +72,45 @@ class OlapInsertExecutorTest {
ConnectContext.remove();
}
+ @Test
+ void testCloudInsertReturnsOkWithOriginalTxnIdOnDuplicateBegin() throws
Exception {
+ ConnectContext ctx = createExecutorContext();
+ ctx.getSessionVariable().setCloudCluster("test_cluster");
+ Coordinator coordinator = createCoordinator();
+ StmtExecutor stmtExecutor = createStmtExecutor();
+ GlobalTransactionMgrIface txnMgr =
Mockito.mock(GlobalTransactionMgrIface.class);
+ Env currentEnv = createCurrentEnv(Mockito.mock(LoadManager.class));
+ long originalTxnId = 10008L;
+
+ try (MockedStatic<EnvFactory> envFactoryMock =
Mockito.mockStatic(EnvFactory.class);
+ MockedStatic<Env> envMock = Mockito.mockStatic(Env.class);
+ MockedStatic<Config> configMock =
Mockito.mockStatic(Config.class);
+ MockedStatic<ExecuteEnv> executeEnvMock =
Mockito.mockStatic(ExecuteEnv.class)) {
+ prepareFactoryMocks(envFactoryMock, envMock, coordinator, txnMgr,
+ Mockito.mock(TransactionState.class), currentEnv);
+ ctx.setEnv(currentEnv);
+ OlapInsertExecutor executor = createExecutor(ctx);
+ configMock.when(Config::isCloudMode).thenReturn(true);
+
executeEnvMock.when(ExecuteEnv::getInstance).thenReturn(Mockito.mock(ExecuteEnv.class));
+ TUniqueId queryId = ctx.queryId();
+ Mockito.when(txnMgr.beginTransaction(Mockito.anyLong(),
Mockito.anyList(), Mockito.eq("label_test"),
+ Mockito.eq(queryId), Mockito.any(), Mockito.any(),
Mockito.anyLong(), Mockito.anyLong()))
+ .thenThrow(new
DuplicatedRequestException(queryId.toString(), originalTxnId, "duplicate
begin"));
+ Mockito.when(txnMgr.commitAndPublishTransactionWithRetry(
+ Mockito.eq(executor.getDatabase()), Mockito.anyList(),
Mockito.eq(originalTxnId),
+ Mockito.anyList(), Mockito.anyLong(), Mockito.isNull(),
Mockito.anyList())).thenReturn(true);
+
+ executor.beginTransaction();
+ executor.executeSingleInsert(stmtExecutor);
+
+ Assertions.assertEquals(MysqlStateType.OK,
ctx.getState().getStateType());
+ InsertResult result = ctx.getInsertResult();
+ Assertions.assertNotNull(result);
+ Assertions.assertEquals(originalTxnId, result.txnId);
+ Assertions.assertEquals(TransactionStatus.VISIBLE,
result.txnStatus);
+ }
+ }
+
@Test
void
testExecuteSingleInsertPublishTimeoutReturnErrorKeepsCommittedAccounting()
throws Exception {
ConnectContext ctx = createExecutorContext();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]