cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.16k stars 3.82k forks source link

sql: avoid unnecessary singleflight requests for role membership cache #135852

Open rafiss opened 1 day ago

rafiss commented 1 day ago

See individual commits for refactors that make the enhancement easier.


Since we use a query that scans the whole role_members table to populate the membership cache, it is wasteful to launch multiple singleflight requests for different users. This patch changes the cache refresh logic of the singleflight so that it always populates the entire cache, which means there will only ever be one in-flight query per each node.

fixes https://github.com/cockroachdb/cockroach/issues/135931 Release note (performance improvement): Improved the internal caching logic for role membership information. This reduces the latency impact of commands such as DROP ROLE, CREATE ROLE, and GRANT role TO user, which cause the role membership cache to be invalidated.

blathers-crl[bot] commented 1 day ago

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

cockroach-teamcity commented 1 day ago

This change is Reviewable