Repository navigation
[server] Add resource-based KV leader replica capacity control - #3614
Conversation
68680f1 to
725b611
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a coordinator-side capacity guard for KV leader replicas, based on live TabletServer-reported resources (primarily memory), to prevent creating excessive KV leader replicas and reduce OOM risk in TabletServers.
Changes:
- Add TabletServer CPU/memory probing + registration reporting, with JSON serde version bump and backward compatibility handling.
- Introduce
KvLeaderReplicaCapacityManagerin the coordinator, integrate it into create/drop table & partition flows (including auto-partition), and expose metrics. - Add dynamic config support, RPC error mapping, and unit/integration tests for probing and capacity accounting.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| fluss-server/src/test/java/org/apache/fluss/server/zk/data/TabletServerRegistrationJsonSerdeTest.java | Updates serde tests for new registration version and optional resource fields. |
| fluss-server/src/test/java/org/apache/fluss/server/tablet/TabletServerResourceProbeTest.java | Adds tests for resource probing from config/cgroup/OS fallbacks. |
| fluss-server/src/test/java/org/apache/fluss/server/DynamicConfigChangeTest.java | Adds test for dynamic update of KV leader replica reserved memory config. |
| fluss-server/src/test/java/org/apache/fluss/server/coordinator/TableManagerITCase.java | Adds IT coverage for capacity enforcement on table and partition operations. |
| fluss-server/src/test/java/org/apache/fluss/server/coordinator/KvLeaderReplicaCapacityManagerTest.java | Adds unit tests for capacity calculation, accounting, and rebuild behavior. |
| fluss-server/src/test/java/org/apache/fluss/server/coordinator/AutoPartitionManagerTest.java | Ensures auto-partition create/drop reserves/releases capacity. |
| fluss-server/src/main/java/org/apache/fluss/server/zk/data/TabletServerRegistrationJsonSerde.java | Bumps registration JSON version and serializes/deserializes CPU/memory fields. |
| fluss-server/src/main/java/org/apache/fluss/server/zk/data/TabletServerRegistration.java | Extends registration model to carry TabletServerResource. |
| fluss-server/src/main/java/org/apache/fluss/server/tablet/TabletServerResourceProbe.java | Implements probing of CPU/memory from config, cgroups, or OS/JVM. |
| fluss-server/src/main/java/org/apache/fluss/server/tablet/TabletServer.java | Includes probed resources in tablet server registration. |
| fluss-server/src/main/java/org/apache/fluss/server/metadata/TabletServerResource.java | Adds a resource value object (cpu/memory) for reporting/aggregation. |
| fluss-server/src/main/java/org/apache/fluss/server/metadata/ServerInfo.java | Extends server metadata to include TabletServerResource. |
| fluss-server/src/main/java/org/apache/fluss/server/metadata/CoordinatorMetadataCache.java | Exposes “live” tablet servers (excluding permanently-offline) for capacity calc. |
| fluss-server/src/main/java/org/apache/fluss/server/DynamicServerConfig.java | Allows kv.leader-replica.memory-reserved to be dynamically reconfigured. |
| fluss-server/src/main/java/org/apache/fluss/server/coordinator/KvLeaderReplicaCapacityManager.java | New coordinator component calculating capacity and tracking reserved KV leader replicas. |
| fluss-server/src/main/java/org/apache/fluss/server/coordinator/event/watcher/TabletServerChangeWatcher.java | Propagates tablet server resource info into coordinator metadata updates. |
| fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorService.java | Enforces/reserves/releases capacity during create/drop table/partition operations. |
| fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorServer.java | Wires manager into coordinator lifecycle, registers metrics + dynamic config, rebuilds counts on leadership. |
| fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorEventProcessor.java | Includes resource info when building initial server metadata in coordinator context. |
| fluss-server/src/main/java/org/apache/fluss/server/coordinator/AutoPartitionManager.java | Reserves/releases capacity during auto partition create/drop paths. |
| fluss-rpc/src/main/java/org/apache/fluss/rpc/protocol/Errors.java | Adds RPC error mapping for insufficient KV leader replica capacity. |
| fluss-common/src/main/java/org/apache/fluss/metrics/MetricNames.java | Adds metric names for KV leader replica count/capacity gauges. |
| fluss-common/src/main/java/org/apache/fluss/exception/InsufficientKvLeaderReplicaCapacityException.java | Introduces a public API exception for capacity exhaustion. |
| fluss-common/src/main/java/org/apache/fluss/config/ConfigOptions.java | Adds new config options for reserved memory per KV leader replica and tablet-server resource reporting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wuchong
left a comment
There was a problem hiding this comment.
Thanks @swuferhong , I commented the major concern here:
Avoid maintaining an exactly-once KV leader count outside CoordinatorContext
currentKvLeaderReplicaCount creates a second mutable representation of coordinator state. Keeping it accurate requires reservation, rollback and release logic across every table/partition CRUD path, while failover rebuild performs an expensive and non-atomic metadata scan.
Please maintain an event-thread-owned Set<TableBucket> in CoordinatorContext instead. Add observed KV buckets on create, conservatively treat unknown orphan assignments as KV during failover, and remove them idempotently from onDeleteTableBucket as ResumeDropEvents are admitted by the lifecycle throttler. KvLeaderReplicaCapacityManager should only keep a volatile snapshot derived from kvBuckets.size() and perform a best-effort observed + requested > capacity check, without reservation, rollback, decrease, or full rebuild logic.
|
Btw, Could we rename
However, the current methods, metrics, and configuration should remain explicitly scoped to KV leaders, since that is the only replica type currently supported. |
be15052 to
edcb338
Compare
|
Hi, @wuchong comments addressed. PTAL, thanks. |
9ad40b7 to
83d5542
Compare
83d5542 to
0646189
Compare
| coordinatorContext.getCoordinatorServerInfo(), | ||
| tabletServerInfoList, | ||
| coordinatorContext.getServerTags()); | ||
| updateTabletServerMetadataCacheWhenStartup(tabletServerInfoList); |
There was a problem hiding this comment.
Is the failed case related to this change?
By the way, I believe it is acceptable if the auto-partition manager starts before the metadata cache update, as this does not cause server failure. The task will be rescheduled at the next interval, and the partition will eventually be created. On the other hand, we should add a delay (e.g., 1min) to the schedule in the auto-partition manager instead of using 0. Starting immediately is risky because the server is typically busy during startup.
There was a problem hiding this comment.
This should have been caused by the state before commit 004e514, where metadataCache was initialized twice, so the metadataCache instance passed as a constructor argument to ReplicaCapacityController got overwritten.
Adding the delay may cause many ITCases that rely on auto partition to fail. We'd need to expose the delay as a config parameter so it can be configured in tests. Could we do this in a follow-up PR?
|
Hi, @wuchong comments addressed and ci passed. |
Purpose
Linked issue: close #3613
Add
tabletServerresource reporting and a coordinator-sideKvLeaderReplicaCapacityManagerto protect clusters from creating too many KV leader replicas.TabletServersnow report optional CPU and memory information during registration. The coordinator deriveskvLeaderReplicaCapacityfrom livetabletServermemory andkv.leader-replica.memory-reserved, tracks the current KV leader replica count in memory, rebuilds it on coordinator leadership startup, and checks/reserves capacity when creating KV tables or partitions.The capacity limit is disabled unless more than half of live tablet servers report memory. Unknown-memory
TabletServersuse the average known memory when the limit is enabled.Also add dynamic config support, metrics, RPC error mapping, serde compatibility, auto-partition accounting, and tests for resource probing, capacity calculation, manual create/drop, and auto partition create/drop.
Brief change log
Tests
API and Format
Documentation