refactor(sharddistributor): store shard stats under executor keys #7507
+266
−173
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changed?
Statistics for shards are now stored under executor keys at <prefix>/<namespace>/executors/<executorID>/statistics instead of under /shards/.../statistics.
GetStateis also updated to support this.DeleteShardStatsdeletes shard stats by editing those executor maps and committing a single txn.We no longer do batching as I don't believe we will reach etcd limits anymore (stats under ~128 different executors that are stale doesn't seem plausible)
Delete now unused helpers and tests for shard keys
The Subscribe logic was updated so changes to the statistics key are treated like heartbeats/assigned_state (so they dont trigger rebalances), and the etcd store tests were updated to use the new executor keyed setup.
Why?
Reduce load to etcd
How did you test it?
Unit test and running the canary
Potential risks
The etcd schema for shard statistics has changed, so any leftover stats keys under shard prefix will be ignored by the new code.
DeleteShardStats now issues all per-executor updates in a single transaction. So in an extreme scenario with many executors in one cleanup pass this could hit etcd’s op limit and leave some stale stats until the next run. Consider if it's worth adding batching if this we think this is ever possible.
Concurrent AssignShard calls to the same executor now share a single stats map without a CAS on the stats key, so shard telemetry (not assignments) could be lost in a rare ocasion where there will be a race which might affect future metrics or load-based decisions. But we made this trade-off since it's telemetry, and we don't want it to cause assignments to retry.
Release notes
Documentation Changes