Skip to content

Commit

Permalink
Merge branch 'lock-scheduling'
Browse files Browse the repository at this point in the history
* lock-scheduling:
  changes suggested by dwlocks
  Re-try scheduling build requests for slaves when locks are released

Conflicts:
	master/buildbot/buildslave.py
  • Loading branch information
djmitche committed Nov 18, 2011
2 parents e82868d + 66cce73 commit ffe5bb2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions master/buildbot/buildslave.py
Expand Up @@ -87,6 +87,7 @@ def __init__(self, name, password, max_builds=None,
self.access = []
if locks:
self.access = locks
self.lock_subscriptions = []

self.properties = Properties()
self.properties.update(properties, "BuildSlave")
Expand All @@ -112,6 +113,12 @@ def __repr__(self):
return "<%s %r>" % (self.__class__.__name__, self.slavename)

def updateLocks(self):
"""Convert the L{LockAccess} objects in C{self.locks} into real lock
objects, while also maintaining the subscriptions to lock releases."""
# unsubscribe from any old locks
for s in self.lock_subscriptions:
s.unsubscribe()

# convert locks into their real form
locks = []
for access in self.access:
Expand All @@ -120,6 +127,8 @@ def updateLocks(self):
lock = self.botmaster.getLockByID(access.lockid)
locks.append((lock, access))
self.locks = [(l.getLock(self), la) for l, la in locks]
self.lock_subscriptions = [ l.subscribeToReleases(self._lockReleased)
for l, la in self.locks ]

def locksAvailable(self):
"""
Expand Down Expand Up @@ -157,6 +166,13 @@ def releaseLocks(self):
for lock, access in self.locks:
lock.release(self, access)

def _lockReleased(self):
"""One of the locks for this slave was released; try scheduling
builds."""
if not self.botmaster:
return # oh well..
self.botmaster.maybeStartBuildsForSlave(self.slavename)

def startService(self):
self.updateLocks()
self.startMissingTimer()
Expand Down
13 changes: 13 additions & 0 deletions master/buildbot/locks.py
Expand Up @@ -17,6 +17,7 @@
from twisted.python import log
from twisted.internet import reactor, defer
from buildbot import util
from buildbot.util import subscription

if False: # for debugging
debuglog = log.msg
Expand All @@ -42,6 +43,10 @@ def __init__(self, name, maxCount=1):
self.owners = [] # Current owners, tuples (owner, LockAccess)
self.maxCount = maxCount # maximal number of counting owners

# subscriptions to this lock being released
self.release_subs = subscription.SubscriptionPoint("%r releases"
% (self,))

def __repr__(self):
return self.description

Expand Down Expand Up @@ -85,6 +90,11 @@ def claim(self, owner, access):
self.owners.append((owner, access))
debuglog(" %s is claimed '%s'" % (self, access.mode))

def subscribeToReleases(self, callback):
"""Schedule C{callback} to be invoked every time this lock is
released. Returns a L{Subscription}."""
return self.release_subs.subscribe(callback)

def release(self, owner, access):
""" Release the lock """
assert isinstance(access, LockAccess)
Expand Down Expand Up @@ -114,6 +124,9 @@ def release(self, owner, access):
del self.waiting[0]
reactor.callLater(0, d.callback, self)

# notify any listeners
self.release_subs.deliver()

def waitUntilMaybeAvailable(self, owner, access):
"""Fire when the lock *might* be available. The caller will need to
check with isAvailable() when the deferred fires. This loose form is
Expand Down

0 comments on commit ffe5bb2

Please sign in to comment.