arshilkxwork opened a new pull request, #3356:
URL: https://github.com/apache/hugegraph/pull/3356
## Purpose of the PR
- close #3135
PD balances partition leaders only when `/v1/task/balanceLeaders`,
`/v1/balanceLeaders` or the `balanceLeaders` gRPC call is made. When a Store
restarts, raft elects new leaders for its groups on the surviving Stores, and
nothing moves them back. On Kubernetes, where pod restarts are routine,
leader-side work stays concentrated on the Stores that did not restart until
someone calls the endpoint by hand.
## Main Changes
- `PDConfig`: three new keys, `pd.balance-leader-enable` (default `false`),
`pd.balance-leader-interval` (seconds, default `300`) and
`pd.balance-leader-max-skew` (default `2`). Names follow the proposal in the
issue. With the defaults, behavior does not change.
- `TaskScheduleService.init()` schedules `autoBalancePartitionLeader()` with
`scheduleWithFixedDelay`, like the other periodic jobs, when the feature is
enabled. A non-positive interval logs a warning and schedules nothing, so a bad
value cannot fail PD startup with the executor's `IllegalArgumentException`.
- `autoBalancePartitionLeader()` does nothing on a follower PD. On the
leader it counts leaders per Store from the shard groups. A Store that holds
shards but leads none counts as 0. If max minus min is at or below `max-skew`
it returns without touching anything. Otherwise it calls the existing
`balancePartitionLeader(false)`, so the algorithm, the 30 s rate limit and the
refusal during split, move and shard-balance tasks are the same as for a manual
call. The scheduled wrapper logs those refusals (`PDException` code 1001) at
INFO level.
- One guard the manual path does not have: a run is skipped while any Store
that holds a shard is missing from the active-store list.
`balancePartitionLeader` computes its target from shard placement, so with a
Store down it would try to transfer leaders to that Store. The periodic job
waits until every Store holding a replica is heartbeating again.
- Docs: the new keys in `hugegraph-pd/docs/configuration.md` and
`architecture.md`, commented defaults in the shipped `hg-pd-dist`
`application.yml`, and a note in the Store operations guide next to the manual
`balanceLeaders` call.
Not included: the event-driven trigger on a Store returning to `Up`, which
the issue lists as a possible follow-up. The skew check uses max minus min over
the Stores that hold shards, as proposed in the issue. With uneven shard
placement, the best reachable distribution can itself exceed `max-skew`. In
that case each run calls `balancePartitionLeader`, which finds every leader
already on its target and transfers nothing.
## Verifying these changes
- [ ] Trivial rework / code cleanup without any test coverage. (No Need)
- [ ] Already covered by existing tests, such as *(please modify tests
here)*.
- [x] Need tests and can be verified as follows:
- `TaskScheduleServiceTest` (core) gets three cases on six shard groups
over Stores 1-3: leaders spread 2/2/2 makes no transfers; all six leaders on
Store 1 moves four leaders to Stores 2 and 3 and none to Store 1; Store 3
without a heartbeat skips the run.
- `mvn test -pl hugegraph-pd/hg-pd-test -P pd-core-test`: 153 tests, 0
failures, 2 skipped (both skips predate this change).
- Not tested against a running PD and Store cluster.
## Does this PR potentially affect the following parts?
- [ ] Dependencies ([add/update
license](https://hugegraph.apache.org/docs/contribution-guidelines/contribute/#321-check-licenses)
info &
[regenerate_known_dependencies.sh](../install-dist/scripts/dependency/regenerate_known_dependencies.sh))
- [x] Modify configurations
- [ ] The public API
- [ ] Other affects (typed here)
- [ ] Nope
## Documentation Status
- [ ] `Doc - TODO`: required documentation is pending; complete it before
merging.
- [x] `Doc - Done`: documentation is included here or linked below.
- [ ] `Doc - No Need`: no user-visible documentation is affected.
Documentation files in this PR or paired hugegraph-doc PR:
- `hugegraph-pd/docs/configuration.md`
- `hugegraph-pd/docs/architecture.md`
- `hugegraph-pd/hg-pd-dist/src/assembly/static/conf/application.yml`
- `hugegraph-store/docs/operations-guide.md`
--
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]