Invalidate namespace descendants cache
What does this MR do and why?
This MR implements invalidation of namespace hierarchy cache when change happens in the hierarchy:
-
parent_id
changes - namespace is deleted
In this MR we implement the invalidation with ActiveRecord callbacks to minimize the impact on the system. With a feature flag we can gradually roll it out and see if there is any negative impact. At some point later the invalidation might be implemented as a SQL trigger.
Invalidation logic
When namespace is moved (parent_id changes) or new namespace is created:
- Take the current parent id and the previous parent id and invoke the
expire_for
method. - The
expire_for
method invokes a SQL query where all parent ids until the top level namespace (basically traversal_ids) are collected and then expired by bumping theoutdated_at
column of the cached records (if present).
When namespace is deleted:
- Take the current id and parent namespace ids and invoke the
expire_for
method.
Related epic: &11469
Worst case the expire_for
method would access around 40 rows (assuming maximum hierarchy depth of 20), in reality this will be only a few rows.
Database
- Query when no cache data is present: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/25189/commands/80019
- Query when some cache data is present: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/25189/commands/80047
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #433482 (closed)