Copilot commented on code in PR #16988:
URL: https://github.com/apache/iotdb/pull/16988#discussion_r2666977803
##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/coordinator/task/PipeTaskCoordinatorLock.java:
##########
@@ -35,46 +33,27 @@ public class PipeTaskCoordinatorLock {
private static final Logger LOGGER =
LoggerFactory.getLogger(PipeTaskCoordinatorLock.class);
- private final BlockingDeque<Long> deque = new LinkedBlockingDeque<>(1);
- private final AtomicLong idGenerator = new AtomicLong(0);
+ private final ReentrantLock lock = new ReentrantLock();
public void lock() {
- try {
- final long id = idGenerator.incrementAndGet();
- LOGGER.debug(
- "PipeTaskCoordinator lock (id: {}) waiting for thread {}",
- id,
- Thread.currentThread().getName());
- deque.put(id);
- LOGGER.debug(
- "PipeTaskCoordinator lock (id: {}) acquired by thread {}",
- id,
- Thread.currentThread().getName());
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- LOGGER.error(
- "Interrupted while waiting for PipeTaskCoordinator lock, current
thread: {}",
- Thread.currentThread().getName());
- }
+ LOGGER.debug(
+ "PipeTaskCoordinator lock waiting for thread {}",
Thread.currentThread().getName());
+ lock.lock();
+ LOGGER.debug(
+ "PipeTaskCoordinator lock acquired by thread {}",
Thread.currentThread().getName());
Review Comment:
The unlock() method now uses ReentrantLock.unlock() which will throw
IllegalMonitorStateException if called by a thread that doesn't own the lock.
However, the new lock() method at line 41 is not interruptible and doesn't
handle InterruptedException, which could lead to uninterruptible waits.
Consider using lockInterruptibly() instead to allow threads to be interrupted
while waiting for the lock, similar to how tryLock() handles interruption.
```suggestion
try {
lock.lockInterruptibly();
LOGGER.debug(
"PipeTaskCoordinator lock acquired by thread {}",
Thread.currentThread().getName());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.error(
"Interrupted while waiting for PipeTaskCoordinator lock, current
thread: {}",
Thread.currentThread().getName());
}
```
--
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]