From 117ff80cc597bcc4f6be5af59c67865987a07a1f Mon Sep 17 00:00:00 2001 From: Johannes Kampmeyer Date: Tue, 15 Oct 2019 09:27:50 +0200 Subject: [PATCH 1/2] Fix caching problem in probegroups There has been a long going issue, that if aggressive caching is used, the Cache is always expired if a client checks in. This is due to a bug, that clears the cache before retrieving the old information, which leads to the new groups assigned by a probe to be always new, as olddata is always []. This should fix performance for servers that are utilizing the "aggressive" caching mode. --- src/lib/Bcfg2/Server/Plugins/Probes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py index 270bfa62df..3785944038 100644 --- a/src/lib/Bcfg2/Server/Plugins/Probes.py +++ b/src/lib/Bcfg2/Server/Plugins/Probes.py @@ -141,8 +141,8 @@ def _load_groups(self, hostname): @Bcfg2.Server.Plugin.DatabaseBacked.get_db_lock def set_groups(self, hostname, groups): - Bcfg2.Server.Cache.expire("Probes", "probegroups", hostname) olddata = self._groupcache.get(hostname, []) + Bcfg2.Server.Cache.expire("Probes", "probegroups", hostname) self._groupcache[hostname] = groups for group in groups: try: From 59e03c5139d3ff6784a6963ec6ecd4fa7895463f Mon Sep 17 00:00:00 2001 From: Johannes Kampmeyer Date: Tue, 15 Oct 2019 09:49:40 +0200 Subject: [PATCH 2/2] Change logic, so less queries need to be executed --- src/lib/Bcfg2/Server/Plugins/Probes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py index 3785944038..2fed5dda7b 100644 --- a/src/lib/Bcfg2/Server/Plugins/Probes.py +++ b/src/lib/Bcfg2/Server/Plugins/Probes.py @@ -142,6 +142,8 @@ def _load_groups(self, hostname): @Bcfg2.Server.Plugin.DatabaseBacked.get_db_lock def set_groups(self, hostname, groups): olddata = self._groupcache.get(hostname, []) + if olddata == groups: + return Bcfg2.Server.Cache.expire("Probes", "probegroups", hostname) self._groupcache[hostname] = groups for group in groups: @@ -157,8 +159,7 @@ def set_groups(self, hostname, groups): group=group) ProbesGroupsModel.objects.filter( hostname=hostname).exclude(group__in=groups).delete() - if olddata != groups: - self.core.metadata_cache.expire(hostname) + self.core.metadata_cache.expire(hostname) def _load_data(self, hostname): Bcfg2.Server.Cache.expire("Probes", "probegroups", hostname)