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

 ##########
 File path: 
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/StripedLockHelper.java
 ##########
 @@ -0,0 +1,57 @@
+/*
+ * 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.query.aggregation.datasketches;
+
+import com.google.common.util.concurrent.Striped;
+import java.util.concurrent.locks.ReadWriteLock;
+
+public class StripedLockHelper
+{
+
+  /** for locking per buffer position (power of 2 to make index computation 
faster) */
+  private static final int NUM_STRIPES = 64;
+
+  public static Striped<ReadWriteLock> getReadWriteLock()
+  {
+    return Striped.readWriteLock(NUM_STRIPES);
+  }
+
+  /**
+   * compute lock index to avoid boxing in Striped.get() call
+   * @param position
+   * @return index
+   */
+  public static int lockIndex(final int position)
+  {
+    return smear(position) % NUM_STRIPES;
+  }
+
+  /**
+   * see 
https://github.com/google/guava/blob/master/guava/src/com/google/common/util/concurrent/Striped.java#L536-L548
 
 Review comment:
   maybe copy the comment instead , as that file on those line numbers might 
change.
   
   ```suggestion
      * This method was written by Doug Lea with assistance from members of JCP 
JSR-166 Expert Group
      * and released to the public domain, as explained at
      * http://creativecommons.org/licenses/publicdomain
      *
      * As of 2010/06/11, this method is identical to the (package private) 
hash method in OpenJDK 7's
      * java.util.HashMap class.
   ```

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