Skip to content

Commit

Permalink
minimal patch to not write pickle in the master's basedir
Browse files Browse the repository at this point in the history
There are still relatively unknown scale use of the status objects in the core.

I prefer to delay this cleanup task until after buildbot 0.9.0 is released.

Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
  • Loading branch information
Pierre Tardy committed Apr 14, 2016
1 parent 484287c commit c2c220c
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 508 deletions.
26 changes: 1 addition & 25 deletions master/buildbot/status/build.py
Expand Up @@ -12,21 +12,16 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
import os
import re
import shutil

from twisted.internet import defer
from twisted.internet import reactor
from twisted.persisted import styles
from twisted.python import log
from twisted.python import runtime

from zope.interface import implements

from buildbot import interfaces
from buildbot import util
from buildbot.util import pickle


class BuildStatus(styles.Versioned):
Expand Down Expand Up @@ -369,26 +364,7 @@ def checkLogfiles(self):
s.checkLogfiles()

def saveYourself(self):
filename = os.path.join(self.builder.basedir, "%d" % self.number)
if os.path.isdir(filename):
# leftover from 0.5.0, which stored builds in directories
shutil.rmtree(filename, ignore_errors=True)
tmpfilename = filename + ".tmp"
try:
with open(tmpfilename, "wb") as f:
pickle.dump(self, f, -1)
if runtime.platformType == 'win32':
# windows cannot rename a file on top of an existing one, so
# fall back to delete-first. There are ways this can fail and
# lose the builder's history, so we avoid using it in the
# general (non-windows) case
if os.path.exists(filename):
os.unlink(filename)
os.rename(tmpfilename, filename)
except Exception:
log.msg("unable to save build %s-#%d" % (self.builder.name,
self.number))
log.err()
return

def asDict(self):
result = {}
Expand Down
47 changes: 2 additions & 45 deletions master/buildbot/status/builder.py
Expand Up @@ -20,7 +20,6 @@

from twisted.persisted import styles
from twisted.python import log
from twisted.python import runtime

from zope.interface import implements

Expand Down Expand Up @@ -140,42 +139,10 @@ def upgradeToVersion2(self):
del self.category
self.wasUpgraded = True

def determineNextBuildNumber(self):
"""Scan our directory of saved BuildStatus instances to determine
what our self.nextBuildNumber should be. Set it one larger than the
highest-numbered build we discover. This is called by the top-level
Status object shortly after we are created or loaded from disk.
"""
existing_builds = [int(f)
for f in os.listdir(self.basedir)
if re.match(r"^\d+$", f)]
if existing_builds:
self.nextBuildNumber = max(existing_builds) + 1
else:
self.nextBuildNumber = 0

def saveYourself(self):
for b in self.currentBuilds:
if not b.isFinished:
# interrupted build, need to save it anyway.
# BuildStatus.saveYourself will mark it as interrupted.
b.saveYourself()
filename = os.path.join(self.basedir, "builder")
tmpfilename = filename + ".tmp"
try:
with open(tmpfilename, "wb") as f:
pickle.dump(self, f, -1)
if runtime.platformType == 'win32':
# windows cannot rename a file on top of an existing one
if os.path.exists(filename):
os.unlink(filename)
os.rename(tmpfilename, filename)
except Exception:
log.msg("unable to save builder %s" % self.name)
log.err()
return

# build cache management

def setCacheSize(self, size):
self.buildCache.set_max_size(size)

Expand Down Expand Up @@ -550,17 +517,7 @@ def publishState(self, target=None):
log.err()

def newBuild(self):
"""The Builder has decided to start a build, but the Build object is
not yet ready to report status (it has not finished creating the
Steps). Create a BuildStatus object that it can use."""
number = self.nextBuildNumber
self.nextBuildNumber += 1
# TODO: self.saveYourself(), to make sure we don't forget about the
# build number we've just allocated. This is not quite as important
# as it was before we switch to determineNextBuildNumber, but I think
# it may still be useful to have the new build save itself.
s = BuildStatus(self, self.master, number)
s.waitUntilFinished().addCallback(self._buildFinished)
s = BuildStatus(self, self.master, 0)
return s

# buildStarted is called by our child BuildStatus instances
Expand Down
4 changes: 0 additions & 4 deletions master/buildbot/status/master.py
Expand Up @@ -378,10 +378,6 @@ def builderAdded(self, name, basedir, tags=None, description=None):
builder_status.name = name # it might have been updated
builder_status.status = self

if not os.path.isdir(builder_status.basedir):
os.makedirs(builder_status.basedir)
builder_status.determineNextBuildNumber()

builder_status.setBigState("offline")

for t in self.watchers:
Expand Down
68 changes: 0 additions & 68 deletions master/buildbot/test/unit/test_status_builder.py

This file was deleted.

72 changes: 0 additions & 72 deletions master/buildbot/test/unit/test_status_builder_cache.py

This file was deleted.

106 changes: 0 additions & 106 deletions master/buildbot/test/unit/test_status_buildset.py

This file was deleted.

0 comments on commit c2c220c

Please sign in to comment.