Skip to content

Commit 8d2e679

Browse files
committed
adaptive random bucket load: per-BE bucket assignment with threshold-based rotation
1 parent 5ed5825 commit 8d2e679

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

be/src/exec/sink/vtablet_finder.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,22 @@ Status OlapTabletFinder::find_tablets(RuntimeState* state, Block* block, int row
120120
}
121121
}
122122

123-
int64_t cur_bucket = seqs.empty()
124-
? partition->load_tablet_idx % partition->num_buckets
125-
: seqs[seq_pos];
123+
// Determine the current bucket:
124+
// - adaptive mode: use the cached position in local_bucket_seqs (O(1))
125+
// - fallback (no seqs, or dynamically added partition without seqs): use
126+
// load_tablet_idx if valid, otherwise fall back to fast_rand() to match
127+
// the FIND_TABLET_EVERY_BATCH behaviour for partitions that were added
128+
// at runtime (e.g. auto-partition, overwrite replace) and did not go
129+
// through assignRandomBucketPerBe.
130+
int64_t cur_bucket;
131+
if (!seqs.empty()) {
132+
cur_bucket = seqs[seq_pos];
133+
} else if (partition->load_tablet_idx >= 0) {
134+
cur_bucket = partition->load_tablet_idx % partition->num_buckets;
135+
} else {
136+
cur_bucket =
137+
static_cast<int64_t>(butil::fast_rand()) % partition->num_buckets;
138+
}
126139
int64_t cur_tablet_id = partition->indexes[0].tablets[cur_bucket];
127140

128141
// Credit only the rows that actually went to this partition.

0 commit comments

Comments
 (0)