Skip to content

Commit 894aa60

Browse files
committed
Use double checked locking in OperatorAdaptor
Synchronizing on get() method causes planning congestion when there is high query concurrency.
1 parent 14393b2 commit 894aa60

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

core/trino-spi/src/main/java/io/trino/spi/type/TypeOperators.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,21 @@ private OperatorAdaptor getOperatorAdaptor(Type type, Optional<SortOrder> sortOr
192192
private class OperatorAdaptor
193193
{
194194
private final OperatorConvention operatorConvention;
195-
private MethodHandle adapted;
195+
private volatile MethodHandle adapted;
196196

197197
public OperatorAdaptor(OperatorConvention operatorConvention)
198198
{
199199
this.operatorConvention = operatorConvention;
200200
}
201201

202-
public synchronized MethodHandle get()
202+
public MethodHandle get()
203203
{
204204
if (adapted == null) {
205-
adapted = adaptOperator(operatorConvention);
205+
synchronized (this) {
206+
if (adapted == null) {
207+
adapted = adaptOperator(operatorConvention);
208+
}
209+
}
206210
}
207211
return adapted;
208212
}

0 commit comments

Comments
 (0)