Skip to content

Commit b574f89

Browse files
committed
cache the maxBucketId
1 parent d419d2c commit b574f89

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
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: 4 additions & 7 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

@@ -89,13 +90,6 @@ public int assign(int hash) {
8990
Long num = bucketInformation.computeIfAbsent(currentBucket, i -> 0L);
9091

9192
if (num >= targetBucketRowNumber) {
92-
int maxBucketId =
93-
bucketInformation.isEmpty()
94-
? 0
95-
: bucketInformation.keySet().stream()
96-
.mapToInt(Integer::intValue)
97-
.max()
98-
.getAsInt();
9993
if (-1 == maxBucketsNum
10094
|| bucketInformation.isEmpty()
10195
|| maxBucketId < maxBucketsNum - 1) {
@@ -108,6 +102,9 @@ public int assign(int hash) {
108102
}
109103
bucketInformation.compute(currentBucket, (i, l) -> l == null ? 1L : l + 1);
110104
hash2Bucket.put(hash, (short) currentBucket);
105+
if (currentBucket > maxBucketId) {
106+
maxBucketId = currentBucket;
107+
}
111108
return currentBucket;
112109
}
113110

0 commit comments

Comments
 (0)