sollhui opened a new pull request, #62661:
URL: https://github.com/apache/doris/pull/62661
## Problem
For tables with random distribution, the current import logic has two modes
controlled by `load_to_single_tablet`:
- `false` (default): each BE rotates through **all** buckets every batch
→ every BE holds open channels to every tablet, high memory pressure
- `true`: every BE writes to the **same single** tablet
→ severe data skew, single-tablet bottleneck
There is no middle ground: distribute writes evenly while keeping each BE's
active bucket set small.
## Solution
Remove the `load_to_single_tablet` knob and replace it with a new
`FIND_TABLET_RANDOM_BUCKET` mode. FE plans which bucket each BE starts on
and which buckets it is allowed to rotate into; BE switches to the next
assigned bucket only when a per-tablet write threshold (200 MB) is reached.
### Key design points
**1. CalculateBucketNum — limit active buckets by concurrency**
activeBuckets = min(numBackendsWithSink, totalBucketNum, totalSinkInstances)
maxLocalBucketsPerBe = ceil(activeBuckets / numBackendsWithSink)
For stream load (`totalSinkInstances = 1`): `activeBuckets = 1`, each BE
gets at most 1 local bucket — no switching, no data scatter for small loads.
For batch load (`totalSinkInstances = numBackendsWithSink`): each BE gets 1
local bucket as its starting point, and can grow as data accumulates.
**2. Per-BE bucket ownership — handles single and multi-replica**
Each bucket must be assigned to **exactly one** writer BE to avoid multiple
BEs converging on the same tablet:
- *Single replica*: `node_ids` has one entry → that BE is the owner.
- *Multi-replica*: sort `node_ids` by BE ID; assign bucket `i` to the BE at
position `i % numReplicas` in the sorted list. Deterministic and
coordination-free.
**3. FE sends `local_bucket_seqs` to BE**
Instead of having the BE re-derive ownership at runtime (which would require
scanning `node_ids` and could still produce wrong results for multi-replica),
the FE computes the final list and sends it as `local_bucket_seqs` in
`TOlapTablePartition`. The BE only needs to walk this list when switching.
---
## Example 1 — single import, 3 BEs, 6 buckets, single replica
Tablet layout (one replica per tablet):
| Bucket | node_ids |
|--------|----------|
| 0 | [BE1] |
| 1 | [BE2] |
| 2 | [BE3] |
| 3 | [BE1] |
| 4 | [BE2] |
| 5 | [BE3] |
`TabletLoadIndexRecorderMgr` returns `tabletIndex = 2` for this load.
`totalSinkInstances = 3`, `numBackendsWithSink = 3` → `activeBuckets = 3`,
`maxLocalBucketsPerBe = 1`.
FE plans:
| BE | localBuckets (before trim) | after trim | load_tablet_idx |
local_bucket_seqs |
|-----|---------------------------|------------|-----------------|-------------------|
| BE1 | [0, 3] | [0] | **0** | [0]
|
| BE2 | [1, 4] | [1] | **1** | [1]
|
| BE3 | [2, 5] | [2] | **2** | [2]
|
Each BE writes to one dedicated bucket. `local_bucket_seqs` has a single
entry so no switching occurs (small loads stay on one bucket).
---
## Example 2 — multiple imports, bucket rotation across loads
Same cluster. `tabletIndex` increments by 1 per load per partition
(starting from a random offset; suppose offset = 0).
| Load | tabletIndex | BE1 starts on | BE2 starts on | BE3 starts on |
|------|-------------|---------------|---------------|---------------|
| 1 | 0 | bucket **0** | bucket **1** | bucket **2** |
| 2 | 1 | bucket **3** | bucket **4** | bucket **5** |
| 3 | 2 | bucket **0** | bucket **1** | bucket **2** |
| 4 | 3 | bucket **3** | bucket **4** | bucket **5** |
Consecutive loads alternate between the two local buckets of each BE,
spreading data evenly across all 6 buckets over time.
---
## Example 3 — stream load (single instance)
Same cluster, stream load: `totalSinkInstances = 1`, `numBackendsWithSink =
1`.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]