Repository navigation
Clear scaleInfo when scaler is disabled (#12026) - #12409
Conversation
## What changed? Clear scaleInfo when scaler is disabled ## Why? Not clearing scaleInfo meant that clients were still reading and writing based on scaleInfo.Read and scaleInfo.Write, even though target was cleared. We want disabling the scaler to be a clean and complete break back to the mode of dynamic-config hard-coded partition counts. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes task-queue partition routing and persisted scale state when scaling is disabled; incorrect behavior could misdirect polls/writes or leave backlog unpolled until timeout (documented tradeoff). > > **Overview** > When managed partition scaling is turned off (`NewTarget == 0`), the scale manager now **fully resets** managed state (backlog bits, counts, cap, private scaler state) and publishes **zero read/write** `PartitionScaleInfo` so clients stop routing on stale scale metadata and fall back to dynamic-config partition counts. > > `scaleStateToInfo` treats `Target == 0` as “scaling disabled” (zeros everywhere), and the no-op path in `callScaler` still runs when target is already zero but leftover managed fields need cleanup. Scale-up backlog seeding only runs when re-enabling (`prevTarget == 0 && target > 0`), not on disable. Matching clients use **`PartitionCounts.Valid()`** (read and write both > 0) instead of checking write or read alone when picking partitions. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0007832. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
| @@ -203,9 +203,15 @@ func (sm *scaleManager) callScaler() { | |||
| PrivateState: sm.scaleState.GetPrivateScalerState(), | |||
| }) | |||
| backlogCapC8 := number.EncodeCompact8(int64(decision.BacklogCap)) | |||
There was a problem hiding this comment.
The rule "BacklogCap must be zero when NewTarget is zero" is only written down in the interface comments. Nothing in the code enforces it, and breaking it causes a write loop. If a scaler returns {NewTarget: 0, BacklogCap: N} after the state has been cleaned, then disabledStateNeedsCleanup is false and NewTarget == Target. But backlogCapC8 != 0, so the early return is skipped. The code then forces newState.BacklogCap = 0 and calls UpdateScaleState. That write repeats every cooldown period forever, with a new TargetVersion each time.
You could normalize the cap here instead. Then the no-op check always passes once the state is clean, the newState.BacklogCap = 0 line in the target == 0 block is no longer needed, and the doc changes in partition_scaler_interface.go can go:
| backlogCapC8 := number.EncodeCompact8(int64(decision.BacklogCap)) | |
| var backlogCapC8 number.Compact8 | |
| if decision.NewTarget > 0 { | |
| backlogCapC8 = number.EncodeCompact8(int64(decision.BacklogCap)) | |
| } |
| s.userData.EXPECT().SetPartitionScale(gomock.Any()). | ||
| Do(func(info *taskqueuespb.PartitionScaleInfo) { scaleInfos <- info }).Times(2) | ||
|
|
||
| initial := &persistencespb.PartitionScaleState{ |
There was a problem hiding this comment.
This test starts from Target: 0, so it only covers the cleanup of leftover state. The bug this PR fixes is the switch from an active managed target (Target > 0) to disabled, and no test covers that path. That path also checks the prevTarget == 0 && target > 0 change: mayHaveBacklog must not re-seed bits from dynamic config on disable. Please add a case that starts with, for example, Target: 4 and BacklogState bits 0–3. It should assert that the persisted state has a nil BacklogState and that the pushed info has Read == Write == 0.
What changed?
Clear scaleInfo when scaler is disabled
Why?
Not clearing scaleInfo meant that clients were still reading and writing based on scaleInfo.Read and scaleInfo.Write, even though target was cleared.
We want disabling the scaler to be a clean and complete break back to the mode of dynamic-config hard-coded partition counts.
How did you test it?
Note
Medium Risk
Changes partition read/write routing when managed scaling is turned off; backlog outside the former read range may remain unpolled until tasks time out, as noted in code.
Overview
Disabling managed partition scaling now fully resets client-visible scale state so workers stop routing on stale
PartitionScaleInforead/write counts.When the scaler returns
NewTarget: 0,scaleManagerclears persisted/ephemeral backlog metadata (BacklogState,BacklogCounts,BacklogCap, private scaler state), forces a state update if leftover managed fields would otherwise be ignored as “no change”, and logs disabled managed scaling with the previous read/write counts. Scale-up from target 0 still seeds backlog bits from dynamic-config write partitions only on theprevTarget == 0 && target > 0path.Clients use
PartitionCounts.Valid()(both Read and Write > 0) instead of checking write or read alone, so zeroed scale info after disable falls back to dynamic-config partition counts. Tests cover disabled-state cleanup and load-balancer partition count fixtures.The partition scaler API docs now state that disabling scaling requires BacklogCap to be zero as well.
Reviewed by Cursor Bugbot for commit 89f912b. Bugbot is set up for automated code reviews on this repo. Configure here.