You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2023/04/18 05:37:12 UTC
[iotdb] 02/02: add write concurrent control
This is an automated email from the ASF dual-hosted git repository.
xingtanzjr pushed a commit to branch guonengtest_smooth
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 6099daf2fc769c5d642361f9c6ab9b1c2413e777
Author: Jinrui.Zhang <xi...@gmail.com>
AuthorDate: Tue Apr 18 12:42:33 2023 +0800
add write concurrent control
---
example/session/src/main/java/org/apache/iotdb/WriterTest.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/example/session/src/main/java/org/apache/iotdb/WriterTest.java b/example/session/src/main/java/org/apache/iotdb/WriterTest.java
index 9ee7bd2187..0876345eec 100644
--- a/example/session/src/main/java/org/apache/iotdb/WriterTest.java
+++ b/example/session/src/main/java/org/apache/iotdb/WriterTest.java
@@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -78,14 +79,15 @@ public class WriterTest {
protected volatile boolean needResetLatch = true;
protected CountDownLatch latch;
protected long currentTimestamp;
-
+ protected Semaphore semaphore;
protected int count;
protected SyncWriteSignal(int count) {
this.count = count;
+ this.semaphore = new Semaphore(20);
}
- protected void syncCountDownBeforeInsert() {
+ protected void syncCountDownBeforeInsert() throws InterruptedException {
if (needResetLatch) {
synchronized (this) {
if (needResetLatch) {
@@ -95,9 +97,11 @@ public class WriterTest {
}
}
}
+ semaphore.acquire();
}
protected void finishInsertAndWait(int loopIndex) throws InterruptedException {
+ semaphore.release();
CountDownLatch currentLatch = latch;
synchronized (this) {
currentLatch.countDown();
@@ -127,8 +131,8 @@ public class WriterTest {
@Override
public void run() {
for (int j = 0; j < WRITE_LOOP; j++) {
- signal.syncCountDownBeforeInsert();
try {
+ signal.syncCountDownBeforeInsert();
int insertDeviceCount = insertRecords(index, signal.currentTimestamp);
totalRowNumber.addAndGet(insertDeviceCount);
signal.finishInsertAndWait(j);