You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2020/08/01 16:42:40 UTC

[GitHub] [hudi] nsivabalan commented on a change in pull request #1868: [HUDI-1083] Optimization in determining insert bucket location for a given key

nsivabalan commented on a change in pull request #1868:
URL: https://github.com/apache/hudi/pull/1868#discussion_r463977677



##########
File path: hudi-client/src/main/java/org/apache/hudi/table/action/commit/UpsertPartitioner.java
##########
@@ -99,7 +100,7 @@ public UpsertPartitioner(WorkloadProfile profile, JavaSparkContext jsc, HoodieTa
     assignInserts(profile, jsc);
 
     LOG.info("Total Buckets :" + totalBuckets + ", buckets info => " + bucketInfoMap + ", \n"
-        + "Partition to insert buckets => " + partitionPathToInsertBuckets + ", \n"
+        + "Partition to insert buckets => " + partitionPathToInsertBucketInfos + ", \n"

Review comment:
       did you check if this prints the value or the hash value for InsertBucketCumulativeWeightPair? if hash value, you may need to override toString for InsertBucketCumulativeWeightPair

##########
File path: hudi-client/src/main/java/org/apache/hudi/table/action/commit/UpsertPartitioner.java
##########
@@ -270,20 +273,24 @@ public int getPartition(Object key) {
       return updateLocationToBucket.get(location.getFileId());
     } else {
       String partitionPath = keyLocation._1().getPartitionPath();
-      List<InsertBucket> targetBuckets = partitionPathToInsertBuckets.get(partitionPath);
+      List<InsertBucketCumulativeWeightPair> targetBuckets = partitionPathToInsertBucketInfos.get(partitionPath);
       // pick the target bucket to use based on the weights.
-      double totalWeight = 0.0;
       final long totalInserts = Math.max(1, profile.getWorkloadStat(partitionPath).getNumInserts());
       final long hashOfKey = NumericUtils.getMessageDigestHash("MD5", keyLocation._1().getRecordKey());
       final double r = 1.0 * Math.floorMod(hashOfKey, totalInserts) / totalInserts;
-      for (InsertBucket insertBucket : targetBuckets) {
-        totalWeight += insertBucket.weight;
-        if (r <= totalWeight) {
-          return insertBucket.bucketNumber;
-        }
+
+      int index = Collections.binarySearch(targetBuckets, new InsertBucketCumulativeWeightPair(new InsertBucket(), r));
+
+      if (index >= 0) {

Review comment:
       sorry, probably I mis guided you. (should not happen) but incase the last buckets cumulative weight is not 1.0, there are chances that index value could be equal to size of collection when entry searched for is greater than all entries. Can we accommodate that as well.  

##########
File path: hudi-client/src/main/java/org/apache/hudi/table/action/commit/InsertBucketCumulativeWeightPair.java
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.hudi.table.action.commit;
+
+import org.apache.hudi.common.util.collection.Pair;
+
+public class InsertBucketCumulativeWeightPair extends Pair<InsertBucket, Double> {

Review comment:
       java docs as to what does cumulative weight means.

##########
File path: hudi-client/src/test/java/org/apache/hudi/table/action/commit/TestUpsertPartitioner.java
##########
@@ -269,8 +267,8 @@ public void testUpsertPartitionerWithSmallInsertHandling() throws Exception {
     assertEquals(BucketType.INSERT, partitioner.getBucketInfo(3).bucketType,
         "Bucket 3 is INSERT");
     assertEquals(4, insertBuckets.size(), "Total of 4 insert buckets");
-    assertEquals(0, insertBuckets.get(0).bucketNumber, "First insert bucket must be same as update bucket");
-    assertEquals(200.0 / 2400, insertBuckets.get(0).weight, 0.01, "First insert bucket should have weight 0.5");
+    assertEquals(0, insertBuckets.get(0).getKey().bucketNumber, "First insert bucket must be same as update bucket");
+    assertEquals(200.0 / 2400, insertBuckets.get(0).getKey().weight, 0.01, "First insert bucket should have weight 0.5");

Review comment:
       typo. weight is 0.08

##########
File path: hudi-client/src/test/java/org/apache/hudi/table/action/commit/TestUpsertPartitioner.java
##########
@@ -269,8 +267,8 @@ public void testUpsertPartitionerWithSmallInsertHandling() throws Exception {
     assertEquals(BucketType.INSERT, partitioner.getBucketInfo(3).bucketType,
         "Bucket 3 is INSERT");
     assertEquals(4, insertBuckets.size(), "Total of 4 insert buckets");
-    assertEquals(0, insertBuckets.get(0).bucketNumber, "First insert bucket must be same as update bucket");
-    assertEquals(200.0 / 2400, insertBuckets.get(0).weight, 0.01, "First insert bucket should have weight 0.5");
+    assertEquals(0, insertBuckets.get(0).getKey().bucketNumber, "First insert bucket must be same as update bucket");
+    assertEquals(200.0 / 2400, insertBuckets.get(0).getKey().weight, 0.01, "First insert bucket should have weight 0.5");

Review comment:
       just curious, why not asserting every buckets weight? 




----------------------------------------------------------------
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:
users@infra.apache.org