diff options
author | James E. Blair <jim@acmegating.com> | 2021-11-11 19:11:02 -0800 |
---|---|---|
committer | James E. Blair <jim@acmegating.com> | 2021-11-12 15:00:55 -0800 |
commit | f97a6f627e13b133febb565d4a5e9d10d42fe606 (patch) | |
tree | a98b1b259dd99d0766ec52f69246e9a4d51f5bb0 /zuul/model.py | |
parent | a2be79979676c39b733e601120c2e4f37425fc65 (diff) | |
download | zuul-f97a6f627e13b133febb565d4a5e9d10d42fe606.tar.gz |
Only update ZKObject values in ZK if necessary
Several parts of the NNFI implementation set attributes without
checking their existing values. Usually they will be the same
from one pass to the next (like "item.active = active"). That
is inefficient. Rather than updating all that code and changing
our python programming habits, let's make ZKObject smarter so it
doesn't write to ZK when it's not necessary.
Change-Id: Ibbe0d52a0f6ce28ad26753f7c5133027f572b33c
Diffstat (limited to 'zuul/model.py')
-rw-r--r-- | zuul/model.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/zuul/model.py b/zuul/model.py index a1af8d61b..6dcfb7e1d 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -1873,7 +1873,8 @@ class JobData(zkobject.ShardedZKObject): obj = klass() kw['hash'] = JobData.getHash(kw['data']) obj._set(**kw) - obj._save(context, create=True) + data = obj._trySerialize(context) + obj._save(context, data, create=True) return obj @staticmethod @@ -1963,7 +1964,8 @@ class FrozenJob(zkobject.ZKObject): v = None kw['_' + k] = v obj._set(**kw) - obj._save(context, create=True) + data = obj._trySerialize(context) + obj._save(context, data, create=True) # If we need to make any JobData entries, do that now. update_kw = {} @@ -3832,12 +3834,14 @@ class BuildSet(zkobject.ZKObject): def removeJobNodeSetInfo(self, job_name): if job_name not in self.nodeset_info: raise Exception("No job nodeset for %s" % (job_name)) - del self.nodeset_info[job_name] + with self.activeContext(self.item.pipeline.manager.current_context): + del self.nodeset_info[job_name] def setJobNodeRequestID(self, job_name, request_id): if job_name in self.node_requests: raise Exception("Prior node request for %s" % (job_name)) - self.node_requests[job_name] = request_id + with self.activeContext(self.item.pipeline.manager.current_context): + self.node_requests[job_name] = request_id def getJobNodeRequestID(self, job_name): return self.node_requests.get(job_name) @@ -3858,7 +3862,8 @@ class BuildSet(zkobject.ZKObject): info['zone'] = None info['provider'] = node.provider info['nodes'] = [n.id for n in nodeset.getNodes()] - self.nodeset_info[job_name] = info + with self.activeContext(self.item.pipeline.manager.current_context): + self.nodeset_info[job_name] = info def getTries(self, job_name): return self.tries.get(job_name, 0) @@ -3946,7 +3951,8 @@ class QueueItem(zkobject.ZKObject): def new(klass, context, **kw): obj = klass() obj._set(**kw) - obj._save(context, create=True) + data = obj._trySerialize(context) + obj._save(context, data, create=True) files_state = (BuildSet.COMPLETE if obj.change.files is not None else BuildSet.NEW) obj.updateAttributes(context, current_build_set=BuildSet.new( |