You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "Seol-JY (via GitHub)" <gi...@apache.org> on 2026/06/09 04:32:51 UTC
[PR] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Seol-JY opened a new pull request, #8138:
URL: https://github.com/apache/incubator-seata/pull/8138
- [x] I have read the [CONTRIBUTING.md](https://github.com/apache/incubator-seata/blob/2.x/CONTRIBUTING.md) guidelines.
- [x] I have registered the PR [changes](https://github.com/apache/incubator-seata/tree/2.x/changes).
### Ⅰ. Describe what this PR did
Fixes a correctness issue in the date-based TCC fence-log cleanup (`SpringFenceHandler#deleteFenceByDate`).
The cleanup selects expired end-status xids via `queryEndStatusXidsByDate` (`gmt_modified < ?` AND `status in (COMMITTED, ROLLBACKED, SUSPENDED)`), but then deletes them with `DELETE ... WHERE xid IN (...)` — **with no date or status predicate**. Because the `tcc_fence_log` primary key is `(xid, branch_id)`, a single global transaction can own several branch rows. Deleting by xid alone therefore also removes sibling branch rows of the same xid that are still in progress (`TRIED`) or not yet expired — the very records that guard idempotency / anti-hanging.
This PR:
1. Restricts the delete by `gmt_modified < ?` and end status, so only the rows the query intended are removed (the `DELETE_BY_BRANCH_XIDS` predicate now matches `QUERY_END_STATUS_BY_DATE`). The pre-existing but unused `DELETE_BY_DATE_AND_STATUS` constant — evidence the date/status filter was the original intent — is removed as it becomes redundant.
2. Changes the query to `select distinct xid`, so the row limit bounds the number of *distinct xids*. This keeps the `xidSet.size() < LIMIT_DELETE` loop-termination check in `deleteFenceByDate` consistent when one xid owns multiple branch rows (applies to MySQL/PostgreSQL/MariaDB via `limit ?`; on Oracle `ROWNUM` still bounds raw rows, i.e. unchanged / no regression).
The delete still batches by xid (PK-prefix indexed) exactly as before, so there is no performance change.
### Ⅱ. Does this pull request fix one issue?
No linked issue — this is a latent correctness bug found by code review.
### Ⅲ. Why don't you add test cases (unit test/integration test)?
Added `CommonFenceStoreSqlsTest` (asserts the delete SQL carries the `gmt_modified` + end-status guard and the query selects distinct xids) and extended `CommonFenceStoreDataBaseDAOTest` (asserts the `gmt_modified` parameter is bound right after the xid placeholders). These pin the fix without introducing a new test dependency to this module.
### Ⅳ. Describe how to verify it
With `useTCCFence=true` and a global transaction whose branches resolve to mixed states under one xid (e.g. branch A `COMMITTED` & expired, branch B `TRIED` or committed-but-recent), running the cleanup must delete only the expired end-status rows and preserve branch B. The added unit tests cover the SQL/binding contract; `mvn -pl integration-tx-api -am test` passes.
### Ⅴ. Special notes for reviews
- `CommonFenceStore#deleteTCCFenceDO` gains a `Date datetime` parameter. The only implementation and caller are internal (`CommonFenceStoreDataBaseDAO`, `SpringFenceHandler`) and are both updated; there is no `compatible` mirror.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#discussion_r3451007888
##########
integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/fence/store/db/sql/CommonFenceStoreSqlsTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.integration.tx.api.fence.store.db.sql;
+
+import org.apache.seata.integration.tx.api.fence.constant.CommonFenceConstant;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class CommonFenceStoreSqlsTest {
+
+ private static final String TABLE = "tcc_fence_log";
+
+ private static final String END_STATUS_IN = "status in (" + CommonFenceConstant.STATUS_COMMITTED + " , "
+ + CommonFenceConstant.STATUS_ROLLBACKED + " , " + CommonFenceConstant.STATUS_SUSPENDED + ")";
+
+ /**
+ * The date-based cleanup must select distinct xids, so a row limit bounds the number of distinct xids
+ * (one xid may own multiple branch rows) and the limit comparison in the cleanup loop stays consistent.
+ */
+ @Test
+ public void queryEndStatusByDateSelectsDistinctXids() {
+ String mysql = CommonFenceStoreSqls.getQueryEndStatusSQLByDate(TABLE, false);
+ assertTrue(mysql.contains("select distinct xid"), mysql);
+ assertTrue(mysql.contains("gmt_modified <"), mysql);
+ assertTrue(mysql.contains(END_STATUS_IN), mysql);
+ assertTrue(mysql.contains("limit ?"), mysql);
+
+ String oracle = CommonFenceStoreSqls.getQueryEndStatusSQLByDate(TABLE, true);
+ assertTrue(oracle.contains("ROWNUM <= ?"), oracle);
+ }
+
+ /**
+ * Core regression: deleting expired fence logs by xid must also be restricted by gmt_modified and end status.
+ * Without these predicates, deleting by xid alone would purge sibling branch rows of the same global
+ * transaction that are still in progress (TRIED) or not yet expired.
+ */
+ @Test
+ public void deleteByXidsIsRestrictedByDateAndEndStatus() {
+ String sql = CommonFenceStoreSqls.getDeleteSQLByXids(TABLE, "?, ?");
+
+ assertTrue(sql.contains("xid in (?, ?)"), sql);
+ // must not be a bare delete-by-xid: the date and end-status guards have to be present
+ assertTrue(sql.contains("gmt_modified <"), sql);
+ assertTrue(sql.contains(END_STATUS_IN), sql);
+ // the in-progress status must never be a deletion target
+ assertFalse(sql.contains("status in (" + CommonFenceConstant.STATUS_TRIED), sql);
Review Comment:
The assertion on line 62 is substring-based and can produce false failures or false passes if status codes share prefixes (e.g., `STATUS_TRIED=1` and another status is `11`) or if formatting changes (spaces/newlines). Prefer asserting the exact expected end-status list (e.g., match the full `status in (...)` clause) or parse/extract the `status in (...)` contents and compare as a set of integers.
##########
integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/fence/store/db/sql/CommonFenceStoreSqlsTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.integration.tx.api.fence.store.db.sql;
+
+import org.apache.seata.integration.tx.api.fence.constant.CommonFenceConstant;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class CommonFenceStoreSqlsTest {
+
+ private static final String TABLE = "tcc_fence_log";
+
+ private static final String END_STATUS_IN = "status in (" + CommonFenceConstant.STATUS_COMMITTED + " , "
+ + CommonFenceConstant.STATUS_ROLLBACKED + " , " + CommonFenceConstant.STATUS_SUSPENDED + ")";
+
+ /**
+ * The date-based cleanup must select distinct xids, so a row limit bounds the number of distinct xids
+ * (one xid may own multiple branch rows) and the limit comparison in the cleanup loop stays consistent.
+ */
+ @Test
+ public void queryEndStatusByDateSelectsDistinctXids() {
+ String mysql = CommonFenceStoreSqls.getQueryEndStatusSQLByDate(TABLE, false);
+ assertTrue(mysql.contains("select distinct xid"), mysql);
+ assertTrue(mysql.contains("gmt_modified <"), mysql);
+ assertTrue(mysql.contains(END_STATUS_IN), mysql);
+ assertTrue(mysql.contains("limit ?"), mysql);
Review Comment:
These `contains(...)` checks are sensitive to harmless SQL formatting changes (whitespace, line breaks, casing). To reduce test brittleness, normalize SQL before assertions (e.g., collapse whitespace and lowercase), or use a regex matcher focused on structure rather than exact spacing.
##########
integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/fence/store/db/sql/CommonFenceStoreSqls.java:
##########
@@ -86,16 +88,14 @@ private CommonFenceStoreSqls() {
"delete from " + LOCAL_TCC_LOG_PLACEHOLD + " where xid = ? and branch_id = ? ";
/**
- * The constant DELETE_BY_BRANCH_ID_AND_XID.
- */
- protected static final String DELETE_BY_BRANCH_XIDS =
- "delete from " + LOCAL_TCC_LOG_PLACEHOLD + " where xid in (" + PRAMETER_PLACEHOLD + ")";
-
- /**
- * The constant DELETE_BY_DATE_AND_STATUS.
+ * The constant DELETE_BY_BRANCH_XIDS.
+ * The gmt_modified and status predicates must match {@link #QUERY_END_STATUS_BY_DATE}: deleting by xid alone
+ * would also remove sibling branch rows of the same global transaction that are still in a non-end status
+ * (e.g. TRIED) or not yet expired, which must be preserved.
*/
- protected static final String DELETE_BY_DATE_AND_STATUS = "delete from " + LOCAL_TCC_LOG_PLACEHOLD
- + " where gmt_modified < ? "
+ protected static final String DELETE_BY_BRANCH_XIDS = "delete from " + LOCAL_TCC_LOG_PLACEHOLD + " where xid in ("
+ + PRAMETER_PLACEHOLD + ")"
+ + " and gmt_modified < ? "
+ " and status in (" + CommonFenceConstant.STATUS_COMMITTED + " , " + CommonFenceConstant.STATUS_ROLLBACKED
+ " , " + CommonFenceConstant.STATUS_SUSPENDED + ")";
Review Comment:
`DELETE_BY_BRANCH_XIDS` is misleading now that the SQL is “delete by xids + datetime + end-status” and doesn’t reference `branch_id`. Consider renaming to reflect the actual behavior (e.g., `DELETE_BY_XIDS_AND_DATE_AND_END_STATUS`) to reduce confusion and make call sites self-documenting.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "JinyeongSeol (via GitHub)" <gi...@apache.org>.
JinyeongSeol commented on PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#issuecomment-4775697329
@funky-eyes Addressed the latest Copilot comments. Please take a look whenever you have time. Thanks!
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "Seol-JY (via GitHub)" <gi...@apache.org>.
Seol-JY commented on PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#issuecomment-4665811699
@funky-eyes I replied to the two Copilot comments inline. The only codecov/patch miss is the single delegation line in deleteFenceByDate, which needs a Spring DataSource/static lookup to exercise; the new delete predicate and parameter binding are covered by the added tests. Please take a look whenever you have time. Thanks!
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "JinyeongSeol (via GitHub)" <gi...@apache.org>.
JinyeongSeol commented on code in PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#discussion_r3457078013
##########
integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/fence/store/db/sql/CommonFenceStoreSqlsTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.integration.tx.api.fence.store.db.sql;
+
+import org.apache.seata.integration.tx.api.fence.constant.CommonFenceConstant;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class CommonFenceStoreSqlsTest {
+
+ private static final String TABLE = "tcc_fence_log";
+
+ private static final String END_STATUS_IN = "status in (" + CommonFenceConstant.STATUS_COMMITTED + " , "
+ + CommonFenceConstant.STATUS_ROLLBACKED + " , " + CommonFenceConstant.STATUS_SUSPENDED + ")";
+
+ /**
+ * The date-based cleanup must select distinct xids, so a row limit bounds the number of distinct xids
+ * (one xid may own multiple branch rows) and the limit comparison in the cleanup loop stays consistent.
+ */
+ @Test
+ public void queryEndStatusByDateSelectsDistinctXids() {
+ String mysql = CommonFenceStoreSqls.getQueryEndStatusSQLByDate(TABLE, false);
+ assertTrue(mysql.contains("select distinct xid"), mysql);
+ assertTrue(mysql.contains("gmt_modified <"), mysql);
+ assertTrue(mysql.contains(END_STATUS_IN), mysql);
+ assertTrue(mysql.contains("limit ?"), mysql);
+
+ String oracle = CommonFenceStoreSqls.getQueryEndStatusSQLByDate(TABLE, true);
+ assertTrue(oracle.contains("ROWNUM <= ?"), oracle);
+ }
+
+ /**
+ * Core regression: deleting expired fence logs by xid must also be restricted by gmt_modified and end status.
+ * Without these predicates, deleting by xid alone would purge sibling branch rows of the same global
+ * transaction that are still in progress (TRIED) or not yet expired.
+ */
+ @Test
+ public void deleteByXidsIsRestrictedByDateAndEndStatus() {
+ String sql = CommonFenceStoreSqls.getDeleteSQLByXids(TABLE, "?, ?");
+
+ assertTrue(sql.contains("xid in (?, ?)"), sql);
+ // must not be a bare delete-by-xid: the date and end-status guards have to be present
+ assertTrue(sql.contains("gmt_modified <"), sql);
+ assertTrue(sql.contains(END_STATUS_IN), sql);
+ // the in-progress status must never be a deletion target
+ assertFalse(sql.contains("status in (" + CommonFenceConstant.STATUS_TRIED), sql);
Review Comment:
I switched the test to assert the full generated SQL with assertEquals, matching the convention used by the other SQL builder tests in the repo.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#discussion_r3379480948
##########
integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/fence/store/CommonFenceStore.java:
##########
@@ -74,12 +74,15 @@ public interface CommonFenceStore {
boolean deleteCommonFenceDO(Connection conn, String xid, Long branchId);
/**
- * Delete tcc fence do boolean.
+ * Delete tcc fence by the given xids, restricted to expired end-status rows.
+ * The datetime and end-status predicates guard against removing sibling branch rows of the same xid
+ * that are still in progress (TRIED) or not yet expired.
* @param conn the connection
* @param xids the global transaction ids
- * @return the boolean
+ * @param datetime the expiry threshold; only rows with gmt_modified before this are deleted
+ * @return the deleted row count
*/
- int deleteTCCFenceDO(Connection conn, List<String> xids);
+ int deleteTCCFenceDO(Connection conn, List<String> xids, Date datetime);
Review Comment:
`CommonFenceStore` is a public interface in `integration-tx-api`. Changing the `deleteTCCFenceDO` method signature is a breaking API/SPI change for any external `CommonFenceStore` implementations, even though the in-repo implementation/callers were updated. Consider keeping the old signature (possibly deprecated) and adding an overloaded method (or a default method) that accepts `datetime`, so existing implementations remain source/binary compatible while allowing the cleanup path to pass the expiry threshold.
##########
integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/fence/store/db/CommonFenceStoreDataBaseDAO.java:
##########
@@ -189,6 +189,8 @@ public int deleteTCCFenceDO(Connection conn, List<String> xids) {
for (int i = 0; i < xids.size(); i++) {
Review Comment:
`deleteTCCFenceDO` builds an `IN (...)` clause from `xids.size()`. If `xids` is null/empty, the generated SQL becomes invalid (e.g. `xid in ()`) and will throw at runtime. Since this is part of a public store API, it should defensively handle empty input and fail fast on a null `datetime` to avoid unclear NPEs.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#issuecomment-4786910771
> @funky-eyes The failing Spotless check doesn't look related to this PR — it's an import-order violation in LockStoreDataBaseDAOBatchAcquireTest.java that came from 2.x ([cb9c092](https://github.com/apache/incubator-seata/commit/cb9c092cc062f479117726bb8833ea2b6e15286d), #8145) via the merge build, not from my changes. Is it OK if I fix it here? If so, I'll go ahead.
Please feel free to submit a new PR to address this issue. Thank you.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "Seol-JY (via GitHub)" <gi...@apache.org>.
Seol-JY commented on code in PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#discussion_r3385000087
##########
integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/fence/store/db/CommonFenceStoreDataBaseDAO.java:
##########
@@ -189,6 +189,8 @@ public int deleteTCCFenceDO(Connection conn, List<String> xids) {
for (int i = 0; i < xids.size(); i++) {
Review Comment:
The only caller, SpringFenceHandler#deleteFenceByDate, already breaks out on an empty xid set before calling this, so IN () / null datetime aren't reachable. This is unchanged from the previous behavior, so I'll leave it as is.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "Seol-JY (via GitHub)" <gi...@apache.org>.
Seol-JY commented on code in PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#discussion_r3384998797
##########
integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/fence/store/CommonFenceStore.java:
##########
@@ -74,12 +74,15 @@ public interface CommonFenceStore {
boolean deleteCommonFenceDO(Connection conn, String xid, Long branchId);
/**
- * Delete tcc fence do boolean.
+ * Delete tcc fence by the given xids, restricted to expired end-status rows.
+ * The datetime and end-status predicates guard against removing sibling branch rows of the same xid
+ * that are still in progress (TRIED) or not yet expired.
* @param conn the connection
* @param xids the global transaction ids
- * @return the boolean
+ * @param datetime the expiry threshold; only rows with gmt_modified before this are deleted
+ * @return the deleted row count
*/
- int deleteTCCFenceDO(Connection conn, List<String> xids);
+ int deleteTCCFenceDO(Connection conn, List<String> xids, Date datetime);
Review Comment:
CommonFenceStore is obtained only via CommonFenceStoreDataBaseDAO.getInstance(), not loaded as an SPI, so there's no extension point for external implementations.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "JinyeongSeol (via GitHub)" <gi...@apache.org>.
JinyeongSeol commented on code in PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#discussion_r3457075102
##########
integration-tx-api/src/main/java/org/apache/seata/integration/tx/api/fence/store/db/sql/CommonFenceStoreSqls.java:
##########
@@ -86,16 +88,14 @@ private CommonFenceStoreSqls() {
"delete from " + LOCAL_TCC_LOG_PLACEHOLD + " where xid = ? and branch_id = ? ";
/**
- * The constant DELETE_BY_BRANCH_ID_AND_XID.
- */
- protected static final String DELETE_BY_BRANCH_XIDS =
- "delete from " + LOCAL_TCC_LOG_PLACEHOLD + " where xid in (" + PRAMETER_PLACEHOLD + ")";
-
- /**
- * The constant DELETE_BY_DATE_AND_STATUS.
+ * The constant DELETE_BY_BRANCH_XIDS.
+ * The gmt_modified and status predicates must match {@link #QUERY_END_STATUS_BY_DATE}: deleting by xid alone
+ * would also remove sibling branch rows of the same global transaction that are still in a non-end status
+ * (e.g. TRIED) or not yet expired, which must be preserved.
*/
- protected static final String DELETE_BY_DATE_AND_STATUS = "delete from " + LOCAL_TCC_LOG_PLACEHOLD
- + " where gmt_modified < ? "
+ protected static final String DELETE_BY_BRANCH_XIDS = "delete from " + LOCAL_TCC_LOG_PLACEHOLD + " where xid in ("
+ + PRAMETER_PLACEHOLD + ")"
+ + " and gmt_modified < ? "
+ " and status in (" + CommonFenceConstant.STATUS_COMMITTED + " , " + CommonFenceConstant.STATUS_ROLLBACKED
+ " , " + CommonFenceConstant.STATUS_SUSPENDED + ")";
Review Comment:
DELETE_BY_BRANCH_XIDS is a pre-existing constant; this PR only extended its predicate. Since it's an internal protected constant with no functional impact, I'd prefer to keep the current name to keep the diff focused on the fix.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "Seol-JY (via GitHub)" <gi...@apache.org>.
Seol-JY commented on PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#issuecomment-4776538624
@funky-eyes The failing Spotless check doesn't look related to this PR — it's an import-order violation in LockStoreDataBaseDAOBatchAcquireTest.java that came from 2.x (cb9c092c, #8145) via the merge build, not from my changes. Is it OK if I fix it here? If so, I'll go ahead.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes merged PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#issuecomment-4658196213
## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/8138?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `50.00000%` with `1 line` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 72.91%. Comparing base ([`2f3de1c`](https://app.codecov.io/gh/apache/incubator-seata/commit/2f3de1cad03a81bd1145811d69ba7d097c3320dd?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`e61ba17`](https://app.codecov.io/gh/apache/incubator-seata/commit/e61ba175d10a217bff2437daa29431f1acd070c6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/8138?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [.../org/apache/seata/rm/fence/SpringFenceHandler.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8138?src=pr&el=tree&filepath=spring%2Fseata-spring%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Ffence%2FSpringFenceHandler.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3ByaW5nL3NlYXRhLXNwcmluZy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZmVuY2UvU3ByaW5nRmVuY2VIYW5kbGVyLmphdmE=) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/8138?src=pr&el=tree&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 #8138 +/- ##
============================================
- Coverage 72.92% 72.91% -0.02%
Complexity 883 883
============================================
Files 1327 1327
Lines 50769 50770 +1
Branches 6058 6058
============================================
- Hits 37025 37019 -6
- Misses 10735 10741 +6
- Partials 3009 3010 +1
```
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/8138?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...pi/fence/store/db/CommonFenceStoreDataBaseDAO.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8138?src=pr&el=tree&filepath=integration-tx-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fintegration%2Ftx%2Fapi%2Ffence%2Fstore%2Fdb%2FCommonFenceStoreDataBaseDAO.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW50ZWdyYXRpb24tdHgtYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9pbnRlZ3JhdGlvbi90eC9hcGkvZmVuY2Uvc3RvcmUvZGIvQ29tbW9uRmVuY2VTdG9yZURhdGFCYXNlREFPLmphdmE=) | `93.93% <100.00%> (+0.06%)` | :arrow_up: |
| [...x/api/fence/store/db/sql/CommonFenceStoreSqls.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8138?src=pr&el=tree&filepath=integration-tx-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fintegration%2Ftx%2Fapi%2Ffence%2Fstore%2Fdb%2Fsql%2FCommonFenceStoreSqls.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aW50ZWdyYXRpb24tdHgtYXBpL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9pbnRlZ3JhdGlvbi90eC9hcGkvZmVuY2Uvc3RvcmUvZGIvc3FsL0NvbW1vbkZlbmNlU3RvcmVTcWxzLmphdmE=) | `85.71% <ø> (+14.28%)` | :arrow_up: |
| [.../org/apache/seata/rm/fence/SpringFenceHandler.java](https://app.codecov.io/gh/apache/incubator-seata/pull/8138?src=pr&el=tree&filepath=spring%2Fseata-spring%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Frm%2Ffence%2FSpringFenceHandler.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3ByaW5nL3NlYXRhLXNwcmluZy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2VhdGEvcm0vZmVuY2UvU3ByaW5nRmVuY2VIYW5kbGVyLmphdmE=) | `12.90% <0.00%> (ø)` | |
... and [7 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-seata/pull/8138/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/8138?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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "Seol-JY (via GitHub)" <gi...@apache.org>.
Seol-JY commented on PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#issuecomment-4787001637
@funky-eyes Opened #8148 to fix the Spotless import-order issue. Once it's merged, the check here should go green on a re-run.
--
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] bugfix: fix TCC fence cleanup deleting in-progress/unexpired sibling branch records [incubator-seata]
Posted by "JinyeongSeol (via GitHub)" <gi...@apache.org>.
JinyeongSeol commented on code in PR #8138:
URL: https://github.com/apache/incubator-seata/pull/8138#discussion_r3457076916
##########
integration-tx-api/src/test/java/org/apache/seata/integration/tx/api/fence/store/db/sql/CommonFenceStoreSqlsTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.integration.tx.api.fence.store.db.sql;
+
+import org.apache.seata.integration.tx.api.fence.constant.CommonFenceConstant;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class CommonFenceStoreSqlsTest {
+
+ private static final String TABLE = "tcc_fence_log";
+
+ private static final String END_STATUS_IN = "status in (" + CommonFenceConstant.STATUS_COMMITTED + " , "
+ + CommonFenceConstant.STATUS_ROLLBACKED + " , " + CommonFenceConstant.STATUS_SUSPENDED + ")";
+
+ /**
+ * The date-based cleanup must select distinct xids, so a row limit bounds the number of distinct xids
+ * (one xid may own multiple branch rows) and the limit comparison in the cleanup loop stays consistent.
+ */
+ @Test
+ public void queryEndStatusByDateSelectsDistinctXids() {
+ String mysql = CommonFenceStoreSqls.getQueryEndStatusSQLByDate(TABLE, false);
+ assertTrue(mysql.contains("select distinct xid"), mysql);
+ assertTrue(mysql.contains("gmt_modified <"), mysql);
+ assertTrue(mysql.contains(END_STATUS_IN), mysql);
+ assertTrue(mysql.contains("limit ?"), mysql);
Review Comment:
Switched to an exact full-SQL assertEquals to match how the existing SQL builder tests assert (they compare the exact string rather than normalizing/regex).
--
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