Copilot commented on code in PR #8160:
URL: https://github.com/apache/incubator-seata/pull/8160#discussion_r3556720048
##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/undo/parser/Fastjson2UndoLogParser.java:
##########
@@ -28,6 +28,8 @@
public class Fastjson2UndoLogParser implements UndoLogParser, Initialize {
public static final String NAME = "fastjson2";
+ private static final Object PARSE_LOCK = new Object();
Review Comment:
This global `PARSE_LOCK` makes every undo-log decode single-threaded, which
can be a scalability bottleneck for busy RMs. Please document why this is
required (fastjson2 JSONB $ref race) and consider whether eager reader
initialization in `init()` could remove the need to lock the entire hot path.
##########
serializer/seata-serializer-fastjson2/src/main/java/org.apache.seata.serializer.fastjson2/Fastjson2Serializer.java:
##########
@@ -23,17 +23,21 @@
@LoadLevel(name = "FASTJSON2")
public class Fastjson2Serializer implements Serializer {
+ private static final Object PARSE_LOCK = new Object();
Review Comment:
`PARSE_LOCK` serializes *all* JSONB deserialization through this serializer,
which can become a throughput bottleneck under load. At minimum, add an in-code
comment explaining the fastjson2 race this is working around (so future
refactors don’t remove it unintentionally) and consider whether a more targeted
mitigation (e.g., pre-warming readers) could avoid locking the hot path.
##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/undo/parser/Fastjson2ConcurrentRefDeserializationTest.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.rm.datasource.undo.parser;
+
+import com.alibaba.fastjson2.JSONFactory;
+import com.alibaba.fastjson2.reader.ObjectReaderProvider;
+import org.apache.seata.common.loader.EnhancedServiceLoader;
+import org.apache.seata.rm.datasource.sql.struct.Field;
+import org.apache.seata.rm.datasource.sql.struct.Row;
+import org.apache.seata.rm.datasource.sql.struct.TableRecords;
+import org.apache.seata.rm.datasource.undo.BranchUndoLog;
+import org.apache.seata.rm.datasource.undo.SQLUndoLog;
+import org.apache.seata.rm.datasource.undo.UndoLogParser;
+import org.apache.seata.sqlparser.SQLType;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Fastjson2ConcurrentRefDeserializationTest {
+
+ private static final String ENABLE_STRESS_TEST_PROPERTY =
"seata.fastjson2.concurrentRef";
+
+ private final Fastjson2UndoLogParser parser =
+ (Fastjson2UndoLogParser)
EnhancedServiceLoader.load(UndoLogParser.class, Fastjson2UndoLogParser.NAME);
+
+ @Test
+ public void deserializeReferenceHeavyUndoLogDoesNotDropRefFields() {
+ byte[] bytes = parser.encode(referenceHeavyUndoLog());
+
+ assertThat(countNullRefFields(parser.decode(bytes))).isZero();
+ }
+
+ @Test
+ public void
concurrentDeserializeReferenceHeavyUndoLogDoesNotDropRefFields() throws
Exception {
+ Assumptions.assumeTrue(
+ Boolean.getBoolean(ENABLE_STRESS_TEST_PROPERTY),
+ "set -D" + ENABLE_STRESS_TEST_PROPERTY + "=true to run the
concurrent test");
+
+ byte[] bytes = parser.encode(referenceHeavyUndoLog());
+ assertThat(countNullRefFields(parser.decode(bytes))).isZero();
+
+ int nullTasks = runConcurrentStress(() ->
countNullRefFields(parser.decode(bytes)));
+
+ assertThat(nullTasks).isZero();
+ }
+
+ private static BranchUndoLog referenceHeavyUndoLog() {
+ BranchUndoLog branchUndoLog = new BranchUndoLog();
+ branchUndoLog.setXid("127.0.0.1:8091:123456");
+ branchUndoLog.setBranchId(123456L);
+
+ TableRecords sharedImage = tableRecords();
+ List<SQLUndoLog> sqlUndoLogs = new ArrayList<>();
+ for (int i = 0; i < 20; i++) {
+ SQLUndoLog sqlUndoLog = new SQLUndoLog();
+ sqlUndoLog.setSqlType(SQLType.UPDATE);
+ sqlUndoLog.setTableName("ref_test");
+ sqlUndoLog.setBeforeImage(sharedImage);
+ sqlUndoLog.setAfterImage(sharedImage);
+ sqlUndoLogs.add(sqlUndoLog);
+ }
+ branchUndoLog.setSqlUndoLogs(sqlUndoLogs);
+ return branchUndoLog;
+ }
+
+ private static TableRecords tableRecords() {
+ TableRecords tableRecords = new TableRecords();
+ tableRecords.setTableName("ref_test");
+ List<Row> rows = new ArrayList<>();
+ Row row = new Row();
+ row.add(new Field("id", Types.INTEGER, 1));
+ row.add(new Field("name", Types.VARCHAR, "seata"));
+ rows.add(row);
+ tableRecords.setRows(rows);
+ return tableRecords;
+ }
+
+ private static int countNullRefFields(BranchUndoLog branchUndoLog) {
+ if (branchUndoLog == null || branchUndoLog.getSqlUndoLogs() == null) {
+ return 1;
+ }
+ int nullCount = 0;
+ for (SQLUndoLog sqlUndoLog : branchUndoLog.getSqlUndoLogs()) {
+ if (sqlUndoLog == null) {
+ nullCount++;
+ continue;
+ }
+ if (sqlUndoLog.getBeforeImage() == null
+ || sqlUndoLog.getBeforeImage().getRows() == null) {
+ nullCount++;
+ }
+ if (sqlUndoLog.getAfterImage() == null ||
sqlUndoLog.getAfterImage().getRows() == null) {
+ nullCount++;
+ }
+ }
+ return nullCount;
+ }
+
+ private static int runConcurrentStress(NullCounter nullCounter) throws
Exception {
+ int rounds =
Integer.getInteger("seata.fastjson2.concurrentRef.rounds", 10);
+ int threadCount =
Integer.getInteger("seata.fastjson2.concurrentRef.threads", 200);
+ AtomicInteger totalNullTasks = new AtomicInteger();
+ AtomicReference<Throwable> failure = new AtomicReference<>();
+
+ for (int round = 0; round < rounds; round++) {
+ clearObjectReaderCache();
+ CyclicBarrier barrier = new CyclicBarrier(threadCount);
+ CountDownLatch endLatch = new CountDownLatch(threadCount);
+ AtomicInteger roundNullTasks = new AtomicInteger();
+ for (int i = 0; i < threadCount; i++) {
+ Thread thread = new Thread(
+ () -> {
+ try {
+ barrier.await();
Review Comment:
The stress test can hang indefinitely if the barrier is never tripped (e.g.,
thread creation stalls or one thread fails before calling await). Adding a
timeout makes failures deterministic and prevents CI/dev runs from getting
stuck when this test is enabled.
##########
serializer/seata-serializer-fastjson2/src/test/java/org/apache/seata/serializer/fastjson2/Fastjson2ConcurrentRefDeserializationTest.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.serializer.fastjson2;
+
+import com.alibaba.fastjson2.JSONFactory;
+import com.alibaba.fastjson2.reader.ObjectReaderProvider;
+import org.apache.seata.core.protocol.AbstractMessage;
+import org.apache.seata.core.protocol.BatchResultMessage;
+import org.apache.seata.core.protocol.MergedWarpMessage;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Fastjson2ConcurrentRefDeserializationTest {
+
+ private static final String ENABLE_STRESS_TEST_PROPERTY =
"seata.fastjson2.concurrentRef";
+
+ private final Fastjson2Serializer serializer = new Fastjson2Serializer();
+
+ @Test
+ public void deserializeReferenceHeavyProtocolMessageDoesNotDropRefFields()
{
+ byte[] bytes = serializer.serialize(referenceHeavyMessage());
+
+ assertThat(countNullRefFields(serializer.deserialize(bytes))).isZero();
+ }
+
+ @Test
+ public void
concurrentDeserializeReferenceHeavyProtocolMessageDoesNotDropRefFields() throws
Exception {
+ Assumptions.assumeTrue(
+ Boolean.getBoolean(ENABLE_STRESS_TEST_PROPERTY),
+ "set -D" + ENABLE_STRESS_TEST_PROPERTY + "=true to run the
concurrent test");
+
+ byte[] bytes = serializer.serialize(referenceHeavyMessage());
+ assertThat(countNullRefFields(serializer.deserialize(bytes))).isZero();
+
+ int nullTasks = runConcurrentStress(() ->
countNullRefFields(serializer.deserialize(bytes)));
+
+ assertThat(nullTasks).isZero();
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private static MergedWarpMessage referenceHeavyMessage() {
+ MergedWarpMessage message = new MergedWarpMessage();
+ List sharedList = new ArrayList();
+ for (int i = 0; i < 20; i++) {
+ BatchResultMessage resultMessage = new BatchResultMessage();
+ resultMessage.setResultMessages(sharedList);
+ resultMessage.setMsgIds(sharedList);
+ message.msgs.add(resultMessage);
+ message.msgIds.add(i);
+ }
+ return message;
+ }
+
+ private static int countNullRefFields(MergedWarpMessage message) {
+ if (message == null || message.msgs == null) {
+ return 1;
+ }
+ int nullCount = 0;
+ for (AbstractMessage child : message.msgs) {
+ if (!(child instanceof BatchResultMessage)) {
+ nullCount++;
+ continue;
+ }
+ BatchResultMessage batchResult = (BatchResultMessage) child;
+ if (batchResult.getResultMessages() == null) {
+ nullCount++;
+ }
+ if (batchResult.getMsgIds() == null) {
+ nullCount++;
+ }
+ }
+ return nullCount;
+ }
+
+ private static int runConcurrentStress(NullCounter nullCounter) throws
Exception {
+ int rounds =
Integer.getInteger("seata.fastjson2.concurrentRef.rounds", 10);
+ int threadCount =
Integer.getInteger("seata.fastjson2.concurrentRef.threads", 200);
+ AtomicInteger totalNullTasks = new AtomicInteger();
+ AtomicReference<Throwable> failure = new AtomicReference<>();
+
+ for (int round = 0; round < rounds; round++) {
+ clearObjectReaderCache();
+ CyclicBarrier barrier = new CyclicBarrier(threadCount);
+ CountDownLatch endLatch = new CountDownLatch(threadCount);
+ AtomicInteger roundNullTasks = new AtomicInteger();
+ for (int i = 0; i < threadCount; i++) {
+ Thread thread = new Thread(
+ () -> {
+ try {
+ barrier.await();
Review Comment:
The stress test can hang indefinitely if the barrier is never tripped (e.g.,
thread creation stalls or one thread fails before calling await). Adding a
timeout makes failures deterministic and prevents CI/dev runs from getting
stuck when this test is enabled.
##########
serializer/seata-serializer-fastjson2/src/test/java/org/apache/seata/serializer/fastjson2/Fastjson2ConcurrentRefDeserializationTest.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.serializer.fastjson2;
+
+import com.alibaba.fastjson2.JSONFactory;
+import com.alibaba.fastjson2.reader.ObjectReaderProvider;
+import org.apache.seata.core.protocol.AbstractMessage;
+import org.apache.seata.core.protocol.BatchResultMessage;
+import org.apache.seata.core.protocol.MergedWarpMessage;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Fastjson2ConcurrentRefDeserializationTest {
+
+ private static final String ENABLE_STRESS_TEST_PROPERTY =
"seata.fastjson2.concurrentRef";
+
+ private final Fastjson2Serializer serializer = new Fastjson2Serializer();
+
+ @Test
+ public void deserializeReferenceHeavyProtocolMessageDoesNotDropRefFields()
{
+ byte[] bytes = serializer.serialize(referenceHeavyMessage());
+
+ assertThat(countNullRefFields(serializer.deserialize(bytes))).isZero();
+ }
+
+ @Test
+ public void
concurrentDeserializeReferenceHeavyProtocolMessageDoesNotDropRefFields() throws
Exception {
+ Assumptions.assumeTrue(
+ Boolean.getBoolean(ENABLE_STRESS_TEST_PROPERTY),
+ "set -D" + ENABLE_STRESS_TEST_PROPERTY + "=true to run the
concurrent test");
+
+ byte[] bytes = serializer.serialize(referenceHeavyMessage());
+ assertThat(countNullRefFields(serializer.deserialize(bytes))).isZero();
+
+ int nullTasks = runConcurrentStress(() ->
countNullRefFields(serializer.deserialize(bytes)));
+
+ assertThat(nullTasks).isZero();
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private static MergedWarpMessage referenceHeavyMessage() {
+ MergedWarpMessage message = new MergedWarpMessage();
+ List sharedList = new ArrayList();
+ for (int i = 0; i < 20; i++) {
+ BatchResultMessage resultMessage = new BatchResultMessage();
+ resultMessage.setResultMessages(sharedList);
+ resultMessage.setMsgIds(sharedList);
+ message.msgs.add(resultMessage);
+ message.msgIds.add(i);
+ }
+ return message;
+ }
+
+ private static int countNullRefFields(MergedWarpMessage message) {
+ if (message == null || message.msgs == null) {
+ return 1;
+ }
+ int nullCount = 0;
+ for (AbstractMessage child : message.msgs) {
+ if (!(child instanceof BatchResultMessage)) {
+ nullCount++;
+ continue;
+ }
+ BatchResultMessage batchResult = (BatchResultMessage) child;
+ if (batchResult.getResultMessages() == null) {
+ nullCount++;
+ }
+ if (batchResult.getMsgIds() == null) {
+ nullCount++;
+ }
+ }
+ return nullCount;
+ }
+
+ private static int runConcurrentStress(NullCounter nullCounter) throws
Exception {
+ int rounds =
Integer.getInteger("seata.fastjson2.concurrentRef.rounds", 10);
+ int threadCount =
Integer.getInteger("seata.fastjson2.concurrentRef.threads", 200);
+ AtomicInteger totalNullTasks = new AtomicInteger();
+ AtomicReference<Throwable> failure = new AtomicReference<>();
+
+ for (int round = 0; round < rounds; round++) {
+ clearObjectReaderCache();
+ CyclicBarrier barrier = new CyclicBarrier(threadCount);
+ CountDownLatch endLatch = new CountDownLatch(threadCount);
+ AtomicInteger roundNullTasks = new AtomicInteger();
+ for (int i = 0; i < threadCount; i++) {
+ Thread thread = new Thread(
+ () -> {
+ try {
+ barrier.await();
+ if (nullCounter.countNulls() > 0) {
+ roundNullTasks.incrementAndGet();
+ }
+ } catch (Throwable throwable) {
+ failure.compareAndSet(null, throwable);
+ } finally {
+ endLatch.countDown();
+ }
+ },
+ "fastjson2-rpc-ref-" + i);
+ thread.start();
+ }
+ endLatch.await();
Review Comment:
`endLatch.await()` without a timeout can block forever if any worker thread
never reaches the `finally` block. Use a timed await and fail fast to avoid
hanging when this stress test is enabled.
##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/undo/parser/Fastjson2ConcurrentRefDeserializationTest.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.rm.datasource.undo.parser;
+
+import com.alibaba.fastjson2.JSONFactory;
+import com.alibaba.fastjson2.reader.ObjectReaderProvider;
+import org.apache.seata.common.loader.EnhancedServiceLoader;
+import org.apache.seata.rm.datasource.sql.struct.Field;
+import org.apache.seata.rm.datasource.sql.struct.Row;
+import org.apache.seata.rm.datasource.sql.struct.TableRecords;
+import org.apache.seata.rm.datasource.undo.BranchUndoLog;
+import org.apache.seata.rm.datasource.undo.SQLUndoLog;
+import org.apache.seata.rm.datasource.undo.UndoLogParser;
+import org.apache.seata.sqlparser.SQLType;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Fastjson2ConcurrentRefDeserializationTest {
+
+ private static final String ENABLE_STRESS_TEST_PROPERTY =
"seata.fastjson2.concurrentRef";
+
+ private final Fastjson2UndoLogParser parser =
+ (Fastjson2UndoLogParser)
EnhancedServiceLoader.load(UndoLogParser.class, Fastjson2UndoLogParser.NAME);
+
+ @Test
+ public void deserializeReferenceHeavyUndoLogDoesNotDropRefFields() {
+ byte[] bytes = parser.encode(referenceHeavyUndoLog());
+
+ assertThat(countNullRefFields(parser.decode(bytes))).isZero();
+ }
+
+ @Test
+ public void
concurrentDeserializeReferenceHeavyUndoLogDoesNotDropRefFields() throws
Exception {
+ Assumptions.assumeTrue(
+ Boolean.getBoolean(ENABLE_STRESS_TEST_PROPERTY),
+ "set -D" + ENABLE_STRESS_TEST_PROPERTY + "=true to run the
concurrent test");
+
+ byte[] bytes = parser.encode(referenceHeavyUndoLog());
+ assertThat(countNullRefFields(parser.decode(bytes))).isZero();
+
+ int nullTasks = runConcurrentStress(() ->
countNullRefFields(parser.decode(bytes)));
+
+ assertThat(nullTasks).isZero();
+ }
+
+ private static BranchUndoLog referenceHeavyUndoLog() {
+ BranchUndoLog branchUndoLog = new BranchUndoLog();
+ branchUndoLog.setXid("127.0.0.1:8091:123456");
+ branchUndoLog.setBranchId(123456L);
+
+ TableRecords sharedImage = tableRecords();
+ List<SQLUndoLog> sqlUndoLogs = new ArrayList<>();
+ for (int i = 0; i < 20; i++) {
+ SQLUndoLog sqlUndoLog = new SQLUndoLog();
+ sqlUndoLog.setSqlType(SQLType.UPDATE);
+ sqlUndoLog.setTableName("ref_test");
+ sqlUndoLog.setBeforeImage(sharedImage);
+ sqlUndoLog.setAfterImage(sharedImage);
+ sqlUndoLogs.add(sqlUndoLog);
+ }
+ branchUndoLog.setSqlUndoLogs(sqlUndoLogs);
+ return branchUndoLog;
+ }
+
+ private static TableRecords tableRecords() {
+ TableRecords tableRecords = new TableRecords();
+ tableRecords.setTableName("ref_test");
+ List<Row> rows = new ArrayList<>();
+ Row row = new Row();
+ row.add(new Field("id", Types.INTEGER, 1));
+ row.add(new Field("name", Types.VARCHAR, "seata"));
+ rows.add(row);
+ tableRecords.setRows(rows);
+ return tableRecords;
+ }
+
+ private static int countNullRefFields(BranchUndoLog branchUndoLog) {
+ if (branchUndoLog == null || branchUndoLog.getSqlUndoLogs() == null) {
+ return 1;
+ }
+ int nullCount = 0;
+ for (SQLUndoLog sqlUndoLog : branchUndoLog.getSqlUndoLogs()) {
+ if (sqlUndoLog == null) {
+ nullCount++;
+ continue;
+ }
+ if (sqlUndoLog.getBeforeImage() == null
+ || sqlUndoLog.getBeforeImage().getRows() == null) {
+ nullCount++;
+ }
+ if (sqlUndoLog.getAfterImage() == null ||
sqlUndoLog.getAfterImage().getRows() == null) {
+ nullCount++;
+ }
+ }
+ return nullCount;
+ }
+
+ private static int runConcurrentStress(NullCounter nullCounter) throws
Exception {
+ int rounds =
Integer.getInteger("seata.fastjson2.concurrentRef.rounds", 10);
+ int threadCount =
Integer.getInteger("seata.fastjson2.concurrentRef.threads", 200);
+ AtomicInteger totalNullTasks = new AtomicInteger();
+ AtomicReference<Throwable> failure = new AtomicReference<>();
+
+ for (int round = 0; round < rounds; round++) {
+ clearObjectReaderCache();
+ CyclicBarrier barrier = new CyclicBarrier(threadCount);
+ CountDownLatch endLatch = new CountDownLatch(threadCount);
+ AtomicInteger roundNullTasks = new AtomicInteger();
+ for (int i = 0; i < threadCount; i++) {
+ Thread thread = new Thread(
+ () -> {
+ try {
+ barrier.await();
+ if (nullCounter.countNulls() > 0) {
+ roundNullTasks.incrementAndGet();
+ }
+ } catch (Throwable throwable) {
+ failure.compareAndSet(null, throwable);
+ } finally {
+ endLatch.countDown();
+ }
+ },
+ "fastjson2-undolog-ref-" + i);
+ thread.start();
+ }
+ endLatch.await();
Review Comment:
`endLatch.await()` without a timeout can block forever if any worker thread
never reaches the `finally` block. Use a timed await and fail fast to avoid
hanging when this stress test is enabled.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]