leventov commented on a change in pull request #7938: locking in Theta sketch 
buffer aggregator
URL: https://github.com/apache/incubator-druid/pull/7938#discussion_r317982339
 
 

 ##########
 File path: 
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchBufferAggregator.java
 ##########
 @@ -54,32 +59,58 @@ public void init(ByteBuffer buf, int position)
     createNewUnion(buf, position, false);
   }
 
+  /**
+   * This method uses locks because it can be used during indexing,
+   * and Druid can call aggregate() and get() concurrently
+   * https://github.com/apache/incubator-druid/pull/3956
+   */
   @Override
   public void aggregate(ByteBuffer buf, int position)
   {
     Object update = selector.getObject();
     if (update == null) {
       return;
     }
-
-    Union union = getOrCreateUnion(buf, position);
-    SketchAggregator.updateUnion(union, update);
+    final Lock lock = 
stripedLock.getAt(StripedLockHelper.lockIndex(position)).writeLock();
+    lock.lock();
+    try {
+      Union union = getOrCreateUnion(buf, position);
+      SketchAggregator.updateUnion(union, update);
+    }
+    finally {
+      lock.unlock();
+    }
   }
 
+  /**
+   * This method uses locks because it can be used during indexing,
+   * and Druid can call aggregate() and get() concurrently
+   * https://github.com/apache/incubator-druid/pull/3956
+   * The returned sketch is a separate instance of Sketch
+   * representing the current state of the aggregation, and is not affected by 
consequent
+   * aggregate() calls
 
 Review comment:
   Please make `{@link #aggregate}` a Javadoc link

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


With regards,
Apache Git Services

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

Reply via email to