asdf2014 commented on a change in pull request #6868: Fix deadlock in
DruidStatement & DruidConnection
URL: https://github.com/apache/incubator-druid/pull/6868#discussion_r249639199
##########
File path: sql/src/main/java/org/apache/druid/sql/avatica/DruidConnection.java
##########
@@ -53,25 +54,29 @@
private final AtomicInteger statementCounter = new AtomicInteger();
private final AtomicReference<Future<?>> timeoutFuture = new
AtomicReference<>();
- @GuardedBy("statements")
- private final Map<Integer, DruidStatement> statements;
+ // Typically synchronized by connectionLock, except in one case: the onClose
function passed
+ // into DruidStatements contained by the map.
+ private final ConcurrentMap<Integer, DruidStatement> statements;
- @GuardedBy("statements")
+ @GuardedBy("connectionLock")
Review comment:
Thanks for explaining this @gianm @zhaojiandong . I mean we shouldn't remove
the `@GuardedBy("connectionLock")` from `statements` because the `statements`
is not always synchronized by `connectionLock` and the CI fails, which is
unreasonable. In addition, putting a `@GuardedBy` on `connectionLock` is also
not necessary. If this is done, it means that we should have the
`connectionLock` lock object when we use `connectionLock`, in fact it cannot
achieve the purpose that we should own the `connectionLock` when using
`statements`. So, i think there is a better way to solve this situation by
adding a `@SuppressWarnings("FieldAccessNotGuarded")` annotation to the
`Runnable#run` method, or adding a `// noinspection FieldAccessNotGuarded`
comment to the `statements.remove(statementId)` caluse, which will suppress
this check and make CI happy.
```java
@GuardedBy("connectionLock")
private final ConcurrentMap<Integer, DruidStatement> statements;
private final Object connectionLock = new Object();
public DruidStatement createStatement(SqlLifecycleFactory
sqlLifecycleFactory)
{
// ...
final DruidStatement statement = new DruidStatement(
// ...
() -> {
// noinspection FieldAccessNotGuarded
statements.remove(statementId);
}
);
// ...
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]