Skip to content

Commit c68ebb5

Browse files
committed
cache the maxBucketId
1 parent d419d2c commit c68ebb5

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

paimon-core/src/main/java/org/apache/paimon/index/HashBucketAssigner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class HashBucketAssigner implements BucketAssigner {
4646
private final int assignId;
4747
private final long targetBucketRowNumber;
4848
private final int maxBucketsNum;
49+
private int maxBucketId;
4950

5051
private final Map<BinaryRow, PartitionIndex> partitionIndex;
5152

@@ -87,11 +88,14 @@ public int assign(BinaryRow partition, int hash) {
8788
this.partitionIndex.put(partition, index);
8889
}
8990

90-
int assigned = index.assign(hash, this::isMyBucket, maxBucketsNum);
91+
int assigned = index.assign(hash, this::isMyBucket, maxBucketsNum, maxBucketId);
9192
if (LOG.isDebugEnabled()) {
9293
LOG.debug(
9394
"Assign " + assigned + " to the partition " + partition + " key hash " + hash);
9495
}
96+
if (assigned > maxBucketId) {
97+
maxBucketId = assigned;
98+
}
9599
return assigned;
96100
}
97101

paimon-core/src/main/java/org/apache/paimon/index/PartitionIndex.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public PartitionIndex(
6464
this.accessed = true;
6565
}
6666

67-
public int assign(int hash, IntPredicate bucketFilter, int maxBucketsNum) {
67+
public int assign(int hash, IntPredicate bucketFilter, int maxBucketsNum, int maxBucketId) {
6868
accessed = true;
6969

7070
// 1. is it a key that has appeared before
@@ -88,10 +88,6 @@ public int assign(int hash, IntPredicate bucketFilter, int maxBucketsNum) {
8888
}
8989
}
9090

91-
int maxBucketId =
92-
totalBucket.isEmpty()
93-
? 0
94-
: totalBucket.stream().mapToInt(Integer::intValue).max().getAsInt();
9591
if (-1 == maxBucketsNum || totalBucket.isEmpty() || maxBucketId < maxBucketsNum - 1) {
9692
// 3. create a new bucket
9793
for (int i = 0; i < Short.MAX_VALUE; i++) {

paimon-core/src/main/java/org/apache/paimon/index/SimpleHashBucketAssigner.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class SimpleHashBucketAssigner implements BucketAssigner {
3535
private final int assignId;
3636
private final long targetBucketRowNumber;
3737
private final int maxBucketsNum;
38+
private int maxBucketId;
3839

3940
private final Map<BinaryRow, SimplePartitionIndex> partitionIndex;
4041

@@ -55,7 +56,11 @@ public int assign(BinaryRow partition, int hash) {
5556
index = new SimplePartitionIndex();
5657
this.partitionIndex.put(partition, index);
5758
}
58-
return index.assign(hash);
59+
int assigned = index.assign(hash);
60+
if (assigned > maxBucketId) {
61+
maxBucketId = assigned;
62+
}
63+
return assigned;
5964
}
6065

6166
@Override
@@ -89,13 +94,6 @@ public int assign(int hash) {
8994
Long num = bucketInformation.computeIfAbsent(currentBucket, i -> 0L);
9095

9196
if (num >= targetBucketRowNumber) {
92-
int maxBucketId =
93-
bucketInformation.isEmpty()
94-
? 0
95-
: bucketInformation.keySet().stream()
96-
.mapToInt(Integer::intValue)
97-
.max()
98-
.getAsInt();
9997
if (-1 == maxBucketsNum
10098
|| bucketInformation.isEmpty()
10199
|| maxBucketId < maxBucketsNum - 1) {

0 commit comments

Comments
 (0)