jihoonson commented on a change in pull request #9982:
URL: https://github.com/apache/druid/pull/9982#discussion_r437635575



##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/rel/QueryMaker.java
##########
@@ -126,7 +126,7 @@ public ObjectMapper getJsonMapper()
     return DataSourceAnalysis.forDataSource(query.getDataSource())
                              .getBaseQuerySegmentSpec()
                              .map(QuerySegmentSpec::getIntervals)
-                             .orElse(query.getIntervals());
+                             .orElseGet(query::getIntervals);

Review comment:
       Probably worth commenting why it should be lazy. Same for other 
`orElseGet()`.

##########
File path: 
processing/src/main/java/org/apache/druid/segment/join/HashJoinSegment.java
##########
@@ -98,4 +101,30 @@ public void close() throws IOException
   {
     baseSegment.close();
   }
+
+  @Override
+  public Optional<Closeable> acquireReferences()
+  {
+    Closer closer = Closer.create();
+    boolean acquireFailed = baseSegment.acquireReferences().map(closeable -> {
+      closer.register(closeable);
+      return false;
+    }).orElse(true);
+
+    for (JoinableClause claws : clauses) {
+      if (acquireFailed) {
+        break;
+      }
+      acquireFailed |= claws.acquireReferences().map(closeable -> {

Review comment:
       Hmm, should the contract of `acquireReferences()` clarify that this 
method should never throw an exception? Otherwise, we should make sure the 
`closer` will be safely closed on exceptions.

##########
File path: 
processing/src/main/java/org/apache/druid/segment/ReferenceCountingCloseableObject.java
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.segment;
+
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.EmittingLogger;
+
+import java.io.Closeable;
+import java.util.Optional;
+import java.util.concurrent.Phaser;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * ReferenceCountingCloseableObject implements something like automatic 
reference count-based resource management,
+ * backed by a {@link Phaser}.
+ *
+ * ReferenceCountingCloseableObject allows consumers to call {@link #close()} 
before some other "users", which called
+ * {@link #increment()} or {@link 
#incrementReferenceAndDecrementOnceCloseable()}, but have not called
+ * {@link #decrement()} yet or the closer for {@link 
#incrementReferenceAndDecrementOnceCloseable()}, and the wrapped
+ * object won't be actually closed until that all references are released.
+ */
+public abstract class ReferenceCountingCloseableObject<BaseObject extends 
Closeable> implements Closeable
+{
+  private static final EmittingLogger log = new 
EmittingLogger(ReferenceCountingCloseableObject.class);

Review comment:
       nit: it's emitting nothing and can be a `Logger`.

##########
File path: 
processing/src/main/java/org/apache/druid/segment/join/table/IndexedTable.java
##########
@@ -30,8 +31,11 @@
  *
  * The main user of this class is {@link IndexedTableJoinable}, and its main 
purpose is to participate in joins.
  */
-public interface IndexedTable
+public interface IndexedTable extends ReferenceCountedObject
 {
+  @SuppressWarnings("unused")
+  String version();

Review comment:
       nit: Javadoc?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to