diff options
| author | Olivier Dony <odo@odoo.com> | 2021-01-29 18:43:17 +0000 |
|---|---|---|
| committer | Olivier Dony <odo@odoo.com> | 2021-02-01 11:58:25 +0000 |
| commit | 87aef4e3a36d92462454f51960abf7215c5ab7f1 (patch) | |
| tree | 1b4ddb7f1f8ad5f3b64609cae96609524dda7be2 /odoo/modules/registry.py | |
| parent | 45ea88e58d2a834da4c5ad8ff656481ac1f9ab5d (diff) | |
[FIX] registry: do not signal a phantom cache clear on load
During loading, the registry clears all `ormcache` data multiple
times, in order to ensure consistency with the newly loaded module
data.
Since 083c70bbb63f27839b2c9a4b549e216947bc4dd1, this was done by
calling `self.clear_caches()`, with the side-effect
of signalling to all other worker processes that the cache
*needs* to be invalidated, which is actually untrue.
If the other workers have any reason to reload their own registries,
they will also clear their own cache in the process - there is no
need to forcefully invalidate it globally.
One could think that combining the pre-fork mode with the `-d <db>`
parameter would mitigate this issue, by making all workers inherit from
a fully loaded registry, In reality it doesn't work, because they also
inherit from the `cache_invalidated=True` flag, that was never cleared
in the master process. So despite having a fully loaded registry, the
newly forked workers will signal a cache invalidation upon serving
their first request.
Further, in a multi-tenant setup with large numbers of databases,
registries may be recycled and loaded much more frequently than
new workers are starting, due to the limited registry LRU, amplifying
this effect a bit.
~~
This patch directly clears the cache LRU without going through
`clear_cache()`, avoiding setting the `cache_invalidated` flag of the
registry, and thus not signalling to other workers.
This is similar to what was being done before 083c70bbb63f27839b2c9a4b549e216947bc4dd1,
where the LRU was dropped like all other lazy properties.
Diffstat (limited to 'odoo/modules/registry.py')
| -rw-r--r-- | odoo/modules/registry.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py index e03d9ecf447..3397ab407ed 100644 --- a/odoo/modules/registry.py +++ b/odoo/modules/registry.py @@ -219,7 +219,9 @@ class Registry(Mapping): """ from .. import models - self.clear_caches() + # clear cache to ensure consistency, but do not signal it + self.__cache.clear() + lazy_property.reset_all(self) # Instantiate registered classes (via the MetaModel automatic discovery @@ -244,7 +246,9 @@ class Registry(Mapping): for model in env.values(): model._unregister_hook() - self.clear_caches() + # clear cache to ensure consistency, but do not signal it + self.__cache.clear() + lazy_property.reset_all(self) self.registry_invalidated = True |
