You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2025/10/11 09:13:56 UTC
(iotdb) 01/01: Fix the concurrency issue of UserLockInfo
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch fix_UserLockInfo_concurrency
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 36fd33461cf466a5759dd557de793df600858b58
Author: Tian Jiang <jt...@163.com>
AuthorDate: Sat Oct 11 17:13:46 2025 +0800
Fix the concurrency issue of UserLockInfo
---
.../org/apache/iotdb/db/auth/LoginLockManager.java | 4 +--
.../apache/iotdb/db/auth/LoginLockManagerTest.java | 30 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/LoginLockManager.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/LoginLockManager.java
index 66dbc8a7c8a..eaf43d65ca6 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/LoginLockManager.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/LoginLockManager.java
@@ -112,9 +112,7 @@ public class LoginLockManager {
void removeOldFailures(long cutoffTime) {
// Remove timestamps older than cutoffTime
- while (!failureTimestamps.isEmpty() && failureTimestamps.peekFirst() < cutoffTime) {
- failureTimestamps.pollFirst();
- }
+ failureTimestamps.removeIf(timestamp -> timestamp < cutoffTime);
}
int getFailureCount() {
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/auth/LoginLockManagerTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/auth/LoginLockManagerTest.java
index 845e1b4578c..ba4c812efd7 100644
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/auth/LoginLockManagerTest.java
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/auth/LoginLockManagerTest.java
@@ -19,6 +19,13 @@
package org.apache.iotdb.db.auth;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.db.auth.LoginLockManager.UserLockInfo;
import org.junit.Before;
import org.junit.Test;
@@ -535,4 +542,27 @@ public class LoginLockManagerTest {
// Final verification: no inconsistencies detected during test
assertTrue("Lock state should remain valid during concurrent access", consistencyFlag.get());
}
+
+ @Test
+ public void testConcurrentOperateLockInfo() throws InterruptedException, ExecutionException {
+ UserLockInfo userLockInfo = new UserLockInfo();
+ int numThreads = 100;
+ final int numAttempts = 100000;
+ ExecutorService executor = Executors.newFixedThreadPool(numThreads);
+ List<Future<Void>> threads = new ArrayList<>(numThreads);
+ for (int i = 0; i < numThreads; i++) {
+ threads.add(executor.submit(() -> {
+ for (int i1 = 0; i1 < numAttempts; i1++) {
+ userLockInfo.addFailureTime(i1);
+ if (i1 > 30) {
+ userLockInfo.removeOldFailures(i1 - 30);
+ }
+ }
+ return null;
+ }));
+ }
+ for (Future<Void> thread : threads) {
+ thread.get();
+ }
+ }
}