You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ju...@apache.org on 2026/06/03 07:24:03 UTC
(iotdb) branch fix-stamped-lock-test-timeout created (now 5363380d576)
This is an automated email from the ASF dual-hosted git repository.
Caideyipi pushed a change to branch fix-stamped-lock-test-timeout
in repository https://gitbox.apache.org/repos/asf/iotdb.git
at 5363380d576 Fix flaky stamped lock test
This branch includes the following new commits:
new 5363380d576 Fix flaky stamped lock test
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(iotdb) 01/01: Fix flaky stamped lock test
Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
Caideyipi pushed a commit to branch fix-stamped-lock-test-timeout
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 5363380d576a4962a8e83b0dabc1d4bf117efc4d
Author: Caideyipi <87...@users.noreply.github.com>
AuthorDate: Wed Jun 3 15:23:43 2026 +0800
Fix flaky stamped lock test
---
.../mtree/lock/StampedWriterPreferredLockTest.java | 42 ++++++++++++++++------
1 file changed, 31 insertions(+), 11 deletions(-)
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/mtree/lock/StampedWriterPreferredLockTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/mtree/lock/StampedWriterPreferredLockTest.java
index 2c9fdbdfd3d..b559aaf8152 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/mtree/lock/StampedWriterPreferredLockTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/metadata/mtree/lock/StampedWriterPreferredLockTest.java
@@ -25,6 +25,7 @@ import org.awaitility.core.ConditionTimeoutException;
import org.junit.Assert;
import org.junit.Test;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -143,22 +144,41 @@ public class StampedWriterPreferredLockTest {
}
@Test
- public void testAcquireReadLockWhileWriting() {
+ public void testAcquireReadLockWhileWriting() throws InterruptedException {
StampedWriterPreferredLock lock = new StampedWriterPreferredLock();
lock.writeLock();
AtomicInteger counter = new AtomicInteger();
- new Thread(
+ CountDownLatch readerFinished = new CountDownLatch(1);
+ Thread readerThread =
+ new Thread(
() -> {
lock.threadReadLock();
- counter.incrementAndGet();
- lock.threadReadUnlock();
- })
- .start();
- // block reader util writer release write lock
- Assert.assertEquals(0, counter.get());
- lock.writeUnlock();
- Awaitility.await().atMost(2, TimeUnit.SECONDS).until(() -> counter.get() == 1);
- Assert.assertEquals(1, counter.get());
+ try {
+ counter.incrementAndGet();
+ } finally {
+ lock.threadReadUnlock();
+ readerFinished.countDown();
+ }
+ });
+ readerThread.setDaemon(true);
+ readerThread.start();
+
+ boolean writeLocked = true;
+ try {
+ // block reader until writer release write lock
+ Awaitility.await()
+ .atMost(10, TimeUnit.SECONDS)
+ .until(() -> readerThread.getState() == Thread.State.WAITING);
+ Assert.assertEquals(0, counter.get());
+ lock.writeUnlock();
+ writeLocked = false;
+ Assert.assertTrue(readerFinished.await(10, TimeUnit.SECONDS));
+ Assert.assertEquals(1, counter.get());
+ } finally {
+ if (writeLocked) {
+ lock.writeUnlock();
+ }
+ }
}
@Test