Skip to content

Invalidate namespace descendants cache

Adam Hegyi requested to merge 433482-invalidate-namespace-descendants-cache into master

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 the outdated_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

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)

Edited by Adam Hegyi

Merge request reports

Loading