Skip to content

Ingester: keep only each tenant's ownership share - #7961

Draft
alanprot wants to merge 3 commits into
cortexproject:masterfrom
alanprot:ownership-own-zone
Draft

alanprot wants to merge 3 commits into
cortexproject:masterfrom
alanprot:ownership-own-zone

Conversation

@alanprot

@alanprot alanprot commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

What this PR does:

Follow-up to #7954. With -ingester.use-ring-ownership-for-limits, the ingester keeps only each tenant's ownership share and recomputes it only when a ring change can move it. The ring package gains ShuffleShardUsesWholeRing and a simpler ZonalOwnership; the rest is in pkg/ingester.

In #7954 the refresher recomputed every tenant's share on each 10 s refresh, building a shuffle-shard subring per tenant with ShuffleShard(tenant, size).ZonalOwnership(op)[me], and the fed ring cached every subring it built. A heartbeat changes no share, but at 3,000 ingesters that was over a second of CPU per 1,000 tenants on each refresh, and hundreds of MB of cached subrings.

Changes

  1. Keep only the share. The refresher keeps one share per tenant, still computed by ShuffleShard and ZonalOwnership. The ring used for it is built with the existing SubringCacheDisabled, so subrings are built only to read one share and then dropped.

  2. Recompute only when the share can change. The heartbeat delegate bumps a generation when, in this ingester's zone, an instance joins or leaves, changes its tokens, or becomes or stops being READONLY (shuffle-shard picks skip READONLY instances), or when the number of zones changes (it sets how many members each zone gets). Shard picks and ownership are per zone, so other changes in other zones cannot move this ingester's shares. The refresher recomputes a tenant when the generation or the tenant's shard size changes, or when the tenant switches between its subring and the whole ring because the instance count crossed its shard size.

  3. One ownership rule. Every instance owns the ranges of its tokens except READONLY instances, whose ranges go to the next instance in their zone. It is the same rule the recompute trigger follows, and it matches -distributor.extend-writes=false. With extend-writes on, the ranges of JOINING, LEAVING and PENDING instances are not counted for the instances writes go to instead. The ingester no longer needs the distributor's extend-writes setting, so Config.DistributorExtendWrites (added in Ingester: convert global limits to local using actual ring ownership #7954) is removed.

  4. ZonalOwnership without an operation (pkg/ring). It was added in Ingester: convert global limits to local using actual ring ownership #7954 and is unreleased, and its only caller always asked for WriteNoExtend, so the parameter is dropped and the rule lives in the ring: every instance owns the ranges of its tokens except READONLY instances. Its cache becomes one map, cleared when tokens change or an instance becomes or stops being READONLY (RingCompare reports that as EqualButReadOnly). A heartbeat or any other state change no longer clears it, and since a READONLY change also resets the subring cache, cached subrings need no check of their own.

  5. ShuffleShardUsesWholeRing (pkg/ring, no behaviour change). The condition under which ShuffleShard returns the whole ring instead of a subring is extracted, so the refresher and ShuffleShard use the same rule.

Cost at 3,000 ingesters × 128 random tokens, 1,000 tenants with shard size 30

After next refresh
a heartbeat, or any change in another zone that keeps the zone count 1 ms (was 1.3 s)
a change in this ingester's zone that can move a share about 1.3 s (recompute, unchanged)

The comparison runs in the heartbeat callback over this zone's instances. The subring cache, 43 MB for these 1,000 tenants and 214–401 MB for larger cases, no longer exists.

Tests

  • When the generation changes: a heartbeat, a non-READONLY state change in its own zone, and its own state change do not; an instance joining or leaving its zone, a token change in its zone, and READONLY in either direction do; joins, leaves, token and READONLY changes in another zone do not; a zone appearing or disappearing does.
  • Reuse: a change in another zone keeps the share; READONLY in its own zone recomputes it and matches the subring; a shard-size change recomputes it; departed tenants are dropped.
  • READONLY pick: a pinned layout where a neighbour going from LEAVING to READONLY moves the share from 0 to about 0.54.
  • Whole ring: a tenant whose shard size reaches the instance count after an instance leaves another zone switches to the whole ring and its share is recomputed.
  • Randomized: 300 steps of heartbeats, state changes, joins and leaves in any zone; after each, the reused shares of six tenants (shard sizes 0, 3, 6, 9, 14 and 30) equal a computation from scratch. The generation changed on 17 of the 300 steps.
  • No subring cache: two ShuffleShard calls for the same tenant return different subrings.
  • Mutations: ignoring READONLY, tokens, an instance leaving or the zone count; counting every zone; and the refresher ignoring the generation, the shard size or a whole-ring switch are each caught, as is caching subrings.
  • TestIngesterRingOwnershipLimits (9 ingesters, Docker) stores the same series as before: 3991 and 3979 of a 4000 limit.
  • go test -race -tags slicelabels ./pkg/ingester/ -run 'Ownership|Limiter' -count=5 passes; golangci-lint is clean.

Which issue(s) this PR fixes:
None filed. Follow-up to #7954.

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags

@alanprot alanprot changed the title Ingester: compute ring ownership shares from the ingester's own zone Ingester: keep only each tenant's ownership share Nov 21, 2026
@alanprot
alanprot force-pushed the ownership-own-zone branch 2 times, most recently from 443f067 to 130fc87 Compare November 21, 2026 05:50
The refresher recomputed every tenant's share on each 10s refresh, building
a shuffle-shard subring per tenant, and the fed ring cached every subring it
built. With 3,000 ingesters that was over a second per 1,000 tenants on each
refresh and hundreds of MB of cached subrings, although a heartbeat changes
no share.

Keep one share per tenant. The heartbeat delegate bumps a generation only
when an instance joins or leaves this ingester's zone, changes its tokens,
or becomes or stops being READONLY, or when the number of zones changes,
which sets how many members each zone gets. Shard picks and ownership are
per zone, so other changes in other zones do not move this ingester's
shares. The refresher recomputes a tenant when the generation or the
tenant's shard size changes, or when the tenant switches between its
subring and the whole ring as the instance count crosses its shard size.
The ring is built with SubringCacheDisabled, since a subring is now built
only to read one share.

Shares are computed with WriteNoExtend: every instance owns the ranges of
its tokens except READONLY instances, whose ranges go to the next instance
in their zone. That is the same rule the recompute trigger follows, and it
matches -distributor.extend-writes=false. With extend-writes on, the ranges
of JOINING, LEAVING and PENDING instances are not counted for the instances
writes go to instead. The ingester no longer needs the distributor's
extend-writes setting.

Signed-off-by: Alan Protasio <alanprot@gmail.com>
No change in behaviour. The condition under which ShuffleShard returns the
whole ring instead of a subring becomes ShuffleShardUsesWholeRing, so the
ingester's ownership refresher, which recomputes a tenant's share when the
condition flips, uses the same rule as ShuffleShard.

Signed-off-by: Alan Protasio <alanprot@gmail.com>
ZonalOwnership took the write operation and left out the tokens of every
instance it extends the replica set past. Its only caller now always asks
for WriteNoExtend, so drop the parameter: every instance owns the ranges of
its tokens except READONLY instances, whose ranges go to the next instance
in their zone. ZonalOwnership was added in cortexproject#7954 and is unreleased.

The cache becomes one map, cleared when tokens change or an instance becomes
or stops being READONLY, which RingCompare reports as EqualButReadOnly. A
heartbeat or any other state change no longer clears it. A READONLY change
also resets the shuffle-shard subring cache, so cached subrings no longer
need their own check.

Signed-off-by: Alan Protasio <alanprot@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant