Store branch cache minimum ltimes in layout state
In order to check whether the project branch cache of a connection is up-to-date we need store the cache ltimes as part of the layout state. Change-Id: I3450dfd584d5b2c21f1c7171337054c137eed12d
This commit is contained in:
parent
0b048295e4
commit
982aebe4c8
|
@ -37,7 +37,7 @@ from tests.base import (AnsibleZuulTestCase, BaseTestCase,
|
|||
simple_layout, random_sha1)
|
||||
from tests.base import ZuulWebFixture
|
||||
|
||||
EMPTY_LAYOUT_STATE = LayoutState("", "", 0, None)
|
||||
EMPTY_LAYOUT_STATE = LayoutState("", "", 0, None, {})
|
||||
|
||||
|
||||
class TestGithubDriver(ZuulTestCase):
|
||||
|
|
|
@ -27,7 +27,7 @@ from tests.base import ZuulTestCase, ZuulWebFixture
|
|||
|
||||
from testtools.matchers import MatchesRegex
|
||||
|
||||
EMPTY_LAYOUT_STATE = LayoutState("", "", 0, None)
|
||||
EMPTY_LAYOUT_STATE = LayoutState("", "", 0, None, {})
|
||||
|
||||
|
||||
class TestGitlabWebhook(ZuulTestCase):
|
||||
|
|
|
@ -27,7 +27,7 @@ from zuul.zk.layout import LayoutState
|
|||
from tests.base import ZuulTestCase, simple_layout
|
||||
from tests.base import ZuulWebFixture
|
||||
|
||||
EMPTY_LAYOUT_STATE = LayoutState("", "", 0, None)
|
||||
EMPTY_LAYOUT_STATE = LayoutState("", "", 0, None, {})
|
||||
|
||||
|
||||
class TestPagureDriver(ZuulTestCase):
|
||||
|
|
|
@ -51,7 +51,7 @@ from tests.base import (
|
|||
from zuul.zk.change_cache import ChangeKey
|
||||
from zuul.zk.layout import LayoutState
|
||||
|
||||
EMPTY_LAYOUT_STATE = LayoutState("", "", 0, None)
|
||||
EMPTY_LAYOUT_STATE = LayoutState("", "", 0, None, {})
|
||||
|
||||
|
||||
class TestSchedulerSSL(SSLZuulTestCase):
|
||||
|
|
|
@ -1164,16 +1164,25 @@ class TestLayoutStore(ZooKeeperBaseTestCase):
|
|||
def test_layout_state(self):
|
||||
store = LayoutStateStore(self.zk_client, lambda: None)
|
||||
layout_uuid = uuid.uuid4().hex
|
||||
state = LayoutState("tenant", "hostname", 0, layout_uuid)
|
||||
branch_cache_min_ltimes = {
|
||||
"gerrit": 123,
|
||||
"github": 456,
|
||||
}
|
||||
state = LayoutState("tenant", "hostname", 0, layout_uuid,
|
||||
branch_cache_min_ltimes)
|
||||
store["tenant"] = state
|
||||
self.assertEqual(state, store["tenant"])
|
||||
self.assertNotEqual(state.ltime, -1)
|
||||
self.assertNotEqual(store["tenant"].ltime, -1)
|
||||
self.assertEqual(store["tenant"].branch_cache_min_ltimes,
|
||||
branch_cache_min_ltimes)
|
||||
|
||||
def test_ordering(self):
|
||||
layout_uuid = uuid.uuid4().hex
|
||||
state_one = LayoutState("tenant", "hostname", 1, layout_uuid, ltime=1)
|
||||
state_two = LayoutState("tenant", "hostname", 2, layout_uuid, ltime=2)
|
||||
state_one = LayoutState("tenant", "hostname", 1, layout_uuid,
|
||||
{}, ltime=1)
|
||||
state_two = LayoutState("tenant", "hostname", 2, layout_uuid,
|
||||
{}, ltime=2)
|
||||
|
||||
self.assertGreater(state_two, state_one)
|
||||
|
||||
|
|
|
@ -1329,11 +1329,19 @@ class Scheduler(threading.Thread):
|
|||
for reporter in pipeline.actions:
|
||||
reporter.postConfig()
|
||||
|
||||
# Assemble a new list of min. ltimes of the project branch caches.
|
||||
branch_cache_min_ltimes = {
|
||||
s.connection.connection_name:
|
||||
s.getProjectBranchCacheLtime()
|
||||
for s in self.connections.getSources()
|
||||
}
|
||||
|
||||
layout_state = LayoutState(
|
||||
tenant_name=tenant.name,
|
||||
hostname=self.hostname,
|
||||
last_reconfigured=int(time.time()),
|
||||
uuid=tenant.layout.uuid,
|
||||
branch_cache_min_ltimes=branch_cache_min_ltimes,
|
||||
)
|
||||
# We need to update the local layout state before the remote state,
|
||||
# to avoid race conditions in the layout changed callback.
|
||||
|
|
|
@ -44,12 +44,13 @@ class LayoutState:
|
|||
"""
|
||||
|
||||
def __init__(self, tenant_name, hostname, last_reconfigured, uuid,
|
||||
ltime=-1):
|
||||
branch_cache_min_ltimes, ltime=-1):
|
||||
self.uuid = uuid
|
||||
self.ltime = ltime
|
||||
self.tenant_name = tenant_name
|
||||
self.hostname = hostname
|
||||
self.last_reconfigured = last_reconfigured
|
||||
self.branch_cache_min_ltimes = branch_cache_min_ltimes
|
||||
|
||||
def toDict(self):
|
||||
return {
|
||||
|
@ -57,6 +58,7 @@ class LayoutState:
|
|||
"hostname": self.hostname,
|
||||
"last_reconfigured": self.last_reconfigured,
|
||||
"uuid": self.uuid,
|
||||
"branch_cache_min_ltimes": self.branch_cache_min_ltimes,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
@ -66,6 +68,7 @@ class LayoutState:
|
|||
data["hostname"],
|
||||
data["last_reconfigured"],
|
||||
data.get("uuid"),
|
||||
data.get("branch_cache_min_ltimes"),
|
||||
data.get("ltime", -1),
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue