You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "zihenzzz (via GitHub)" <gi...@apache.org> on 2026/05/08 13:08:34 UTC
[PR] feature: add XA mode to benchmark CLI [incubator-seata]
zihenzzz opened a new pull request, #8094:
URL: https://github.com/apache/incubator-seata/pull/8094
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Please make sure you have read and understood the contributing guidelines -->
- [ ] I have read the [CONTRIBUTING.md](https://github.com/apache/incubator-seata/blob/2.x/CONTRIBUTING.md) guidelines.
- [ ] I have registered the PR [changes](https://github.com/apache/incubator-seata/tree/2.x/changes).
### Ⅰ. Describe what this PR did
### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
### Ⅲ. Why don't you add test cases (unit test/integration test)?
### Ⅳ. Describe how to verify it
### Ⅴ. Special notes for reviews
--
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: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: add XA mode to benchmark CLI [incubator-seata]
Posted by "WangzJi (via GitHub)" <gi...@apache.org>.
WangzJi commented on code in PR #8094:
URL: https://github.com/apache/incubator-seata/pull/8094#discussion_r3212814451
##########
changes/en-us/2.x.md:
##########
@@ -19,6 +19,7 @@ Add changes here for all PR submitted to the 2.x branch.
<!-- Please add the `changes` to the following location(feature/bugfix/optimize/test) based on the type of PR -->
### feature:
+- [[#8094](https://github.com/apache/incubator-seata/pull/???)] add XA mode to benchmark CLI
Review Comment:
@zihenzzz
Please replace the `???` placeholder in the PR URL
##########
changes/zh-cn/2.x.md:
##########
@@ -20,6 +20,7 @@
### feature:
+- [[#8094](https://github.com/apache/incubator-seata/pull/???)] 为 benchmark CLI 增加 XA 模式支持
Review Comment:
Ditto.
--
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: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: add XA mode to benchmark CLI [incubator-seata]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #8094:
URL: https://github.com/apache/incubator-seata/pull/8094#issuecomment-4406793474
## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/8094?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 72.09%. Comparing base ([`b3d3eb6`](https://app.codecov.io/gh/apache/incubator-seata/commit/b3d3eb6ae205f69de5d8797f5584d99111511d80?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`77c8b40`](https://app.codecov.io/gh/apache/incubator-seata/commit/77c8b405df5ed3ca8d8a8f0d267cb8fb3a833d8b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## 2.x #8094 +/- ##
=========================================
Coverage 72.09% 72.09%
Complexity 916 916
=========================================
Files 1325 1325
Lines 50814 50814
Branches 6083 6083
=========================================
+ Hits 36633 36636 +3
+ Misses 11153 11149 -4
- Partials 3028 3029 +1
```
[see 9 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-seata/pull/8094/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
[](https://app.codecov.io/gh/apache/incubator-seata/pull/8094?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: add XA mode to benchmark CLI [incubator-seata]
Posted by "WangzJi (via GitHub)" <gi...@apache.org>.
WangzJi merged PR #8094:
URL: https://github.com/apache/incubator-seata/pull/8094
--
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: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: add XA mode to benchmark CLI [incubator-seata]
Posted by "zihenzzz (via GitHub)" <gi...@apache.org>.
zihenzzz commented on code in PR #8094:
URL: https://github.com/apache/incubator-seata/pull/8094#discussion_r3213035922
##########
changes/zh-cn/2.x.md:
##########
@@ -20,6 +20,7 @@
### feature:
+- [[#8094](https://github.com/apache/incubator-seata/pull/???)] 为 benchmark CLI 增加 XA 模式支持
Review Comment:
sorry
--
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: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: add XA mode to benchmark CLI [incubator-seata]
Posted by "zihenzzz (via GitHub)" <gi...@apache.org>.
zihenzzz commented on PR #8094:
URL: https://github.com/apache/incubator-seata/pull/8094#issuecomment-4406655076
Test cases and documentation will be updated tomorrow
--
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: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] feature: add XA mode to benchmark CLI [incubator-seata]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #8094:
URL: https://github.com/apache/incubator-seata/pull/8094#discussion_r3208936833
##########
test-suite/seata-benchmark-cli/src/main/java/org/apache/seata/benchmark/executor/XAModeExecutor.java:
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.benchmark.executor;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+import org.apache.seata.benchmark.config.BenchmarkConfig;
+import org.apache.seata.benchmark.constant.BenchmarkConstants;
+import org.apache.seata.rm.datasource.xa.DataSourceProxyXA;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.MySQLContainer;
+import org.testcontainers.utility.DockerImageName;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.concurrent.ThreadLocalRandom;
+
+/**
+ * XA mode transaction executor supporting both empty and real transaction modes.
+ *
+ * <p>Supports two sub-modes controlled by {@code --branches}:
+ * <ul>
+ * <li><b>Empty mode</b> ({@code branches == 0}): starts and commits an empty global transaction.
+ * Measures pure Seata XA protocol overhead with no branch registration.</li>
+ * <li><b>Real mode</b> ({@code branches > 0}): executes {@code branches} XA branch operations
+ * per transaction using MySQL via Testcontainers and {@link DataSourceProxyXA}.</li>
+ * </ul>
+ */
+public class XAModeExecutor extends AbstractTransactionExecutor {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(XAModeExecutor.class);
+
+ private MySQLContainer<?> mysqlContainer;
+ private HikariDataSource rawDataSource;
+ private DataSourceProxyXA dataSourceProxyXA;
+
+ public XAModeExecutor(BenchmarkConfig config) {
+ super(config);
+ }
+
+ private boolean isRealMode() {
+ return config.getBranches() > 0;
+ }
+
+ @Override
+ public void init() {
+ if (isRealMode()) {
+ LOGGER.info("Initializing XA mode executor (MySQL XA via Testcontainers)");
+ initRealMode();
+ } else {
+ LOGGER.info("XA mode executor initialized (empty transaction mode)");
+ }
+ }
+
+ private void initRealMode() {
+ try {
+ startMySQLContainer();
+ createDataSource();
+ initDatabase();
+ dataSourceProxyXA = new DataSourceProxyXA(rawDataSource);
+ LOGGER.info("XA DataSourceProxy initialized, dbType: {}", dataSourceProxyXA.getDbType());
+ LOGGER.info("Real XA mode executor initialized with {} accounts", BenchmarkConstants.ACCOUNT_COUNT);
+ } catch (Exception e) {
+ cleanupOnFailure();
+ throw e instanceof RuntimeException
+ ? (RuntimeException) e
+ : new RuntimeException("Failed to initialize real XA mode executor", e);
+ }
+ }
+
+ private void cleanupOnFailure() {
+ LOGGER.warn("Cleaning up XA mode resources due to initialization failure");
+ if (rawDataSource != null && !rawDataSource.isClosed()) {
+ try {
+ rawDataSource.close();
+ } catch (Exception e) {
+ LOGGER.warn("Failed to close XA DataSource during cleanup", e);
+ }
+ }
+ if (mysqlContainer != null && mysqlContainer.isRunning()) {
+ try {
+ mysqlContainer.stop();
+ } catch (Exception e) {
+ LOGGER.warn("Failed to stop XA MySQL container during cleanup", e);
+ }
+ }
+ }
+
+ private void startMySQLContainer() {
+ LOGGER.info("Starting MySQL container for XA mode...");
+ mysqlContainer = new MySQLContainer<>(DockerImageName.parse("mysql:8.0"))
+ .withDatabaseName("benchmark_xa")
+ .withUsername("test")
+ .withPassword("test")
+ .withCommand("--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci");
+ mysqlContainer.start();
+ LOGGER.info("XA MySQL container started: {}", mysqlContainer.getJdbcUrl());
+ }
+
+ private void createDataSource() {
+ HikariConfig hikariConfig = new HikariConfig();
+ hikariConfig.setJdbcUrl(mysqlContainer.getJdbcUrl());
+ hikariConfig.setUsername(mysqlContainer.getUsername());
+ hikariConfig.setPassword(mysqlContainer.getPassword());
+ hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
+ hikariConfig.setMaximumPoolSize(config.getThreads() * 2);
+ hikariConfig.setMinimumIdle(Math.max(1, config.getThreads()));
+ hikariConfig.setConnectionTimeout(30000);
+ hikariConfig.setIdleTimeout(600000);
+ hikariConfig.setMaxLifetime(1800000);
+ rawDataSource = new HikariDataSource(hikariConfig);
+ LOGGER.info("XA HikariCP DataSource created");
+ }
+
+ private void initDatabase() {
+ try (Connection conn = rawDataSource.getConnection();
+ Statement stmt = conn.createStatement()) {
+ stmt.execute("CREATE TABLE IF NOT EXISTS xa_accounts ("
+ + "id BIGINT PRIMARY KEY, "
+ + "balance INT NOT NULL, "
+ + "updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
+ + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
+
+ stmt.execute("TRUNCATE TABLE xa_accounts");
+ try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO xa_accounts (id, balance) VALUES (?, ?)")) {
+ for (int i = 1; i <= BenchmarkConstants.ACCOUNT_COUNT; i++) {
+ pstmt.setLong(1, i);
+ pstmt.setInt(2, BenchmarkConstants.INITIAL_BALANCE);
+ pstmt.addBatch();
+ if (i % 100 == 0) {
+ pstmt.executeBatch();
+ }
+ }
+ pstmt.executeBatch();
+ }
+
+ LOGGER.info(
+ "XA database initialized: {} accounts with balance {}",
+ BenchmarkConstants.ACCOUNT_COUNT,
+ BenchmarkConstants.INITIAL_BALANCE);
+ } catch (SQLException e) {
+ throw new RuntimeException("Failed to initialize XA database", e);
+ }
+ }
+
+ @Override
+ protected String getTransactionName() {
+ return isRealMode() ? "benchmark-real-xa-tx" : "benchmark-xa-tx";
+ }
+
+ @Override
+ protected int getBranchCount() {
+ return config.getBranches();
+ }
+
+ @Override
+ protected void executeBusinessLogic() throws Exception {
+ if (!isRealMode()) {
+ return;
+ }
+ executeBranchOperations(config.getBranches());
+ }
+
+ private void executeBranchOperations(int branchCount) throws SQLException {
+ for (int i = 0; i < branchCount; i++) {
+ executeSingleBranch();
+ }
+ }
+
+ private void executeSingleBranch() throws SQLException {
+ try (Connection conn = dataSourceProxyXA.getConnection()) {
+ conn.setAutoCommit(false);
+
+ long fromAccount = ThreadLocalRandom.current().nextInt(BenchmarkConstants.ACCOUNT_COUNT) + 1L;
+ long toAccount = (fromAccount % BenchmarkConstants.ACCOUNT_COUNT) + 1L;
+ int amount = ThreadLocalRandom.current().nextInt(BenchmarkConstants.MAX_TRANSFER_AMOUNT)
Review Comment:
## CodeQL / Insecure randomness
Potential Insecure randomness due to a [Insecure randomness source.](1).
[Show more details](https://github.com/apache/incubator-seata/security/code-scanning/61)
--
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: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org