This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch jennis/cache_quota in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 3479862abfa2f42ea22b6b26de84ebbe3a6b63f0 Author: James Ennis <[email protected]> AuthorDate: Thu Apr 18 15:54:16 2019 +0100 CASQuota: Don't calculate the quota when we don't need too --- buildstream/_basecache.py | 1 - buildstream/_cas/cascache.py | 6 ++++-- tests/artifactcache/cache_size.py | 3 ++- tests/artifactcache/expiry.py | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/buildstream/_basecache.py b/buildstream/_basecache.py index af3fe9b..d47199b 100644 --- a/buildstream/_basecache.py +++ b/buildstream/_basecache.py @@ -40,7 +40,6 @@ class BaseCache(): self.context = context self.cas = context.get_cascache() self.casquota = context.get_casquota() - self.casquota._calculate_cache_quota() self._remotes_setup = False # Check to prevent double-setup of remotes # Per-project list of _CASRemote instances. diff --git a/buildstream/_cas/cascache.py b/buildstream/_cas/cascache.py index 8d8f3f0..647ece5 100644 --- a/buildstream/_cas/cascache.py +++ b/buildstream/_cas/cascache.py @@ -58,6 +58,8 @@ CACHE_SIZE_FILE = "cache_size" class CASCacheUsage(): def __init__(self, casquota): + if not casquota._cache_quota_original: + casquota._calculate_cache_quota() self.quota_config = casquota._config_cache_quota # Configured quota self.quota_size = casquota._cache_quota_original # Resolved cache quota in bytes self.used_size = casquota.get_cache_size() # Size used by artifacts in bytes @@ -1151,8 +1153,6 @@ class CASQuota: self._ref_callbacks = [] # Call backs to get required refs self._remove_callbacks = [] # Call backs to remove refs - self._calculate_cache_quota() - # compute_cache_size() # # Computes the real artifact cache size. @@ -1218,6 +1218,8 @@ class CASQuota: # def full(self): + if not self._cache_quota: + self._calculate_cache_quota() if self.get_cache_size() > self._cache_quota: return True diff --git a/tests/artifactcache/cache_size.py b/tests/artifactcache/cache_size.py index 09f0f25..a7db496 100644 --- a/tests/artifactcache/cache_size.py +++ b/tests/artifactcache/cache_size.py @@ -75,6 +75,7 @@ def test_quota_over_1024T(cli, tmpdir): project = tmpdir.join("main") os.makedirs(str(project)) _yaml.dump({'name': 'main'}, str(project.join("project.conf"))) + create_element_size("file.bst", project, ".", [], 1024) volume_space_patch = mock.patch( "buildstream._cas.CASQuota._get_cache_volume_size", @@ -83,5 +84,5 @@ def test_quota_over_1024T(cli, tmpdir): ) with volume_space_patch: - result = cli.run(project, args=["build", "file.bst"]) + result = cli.run(project, args=["build", "file.bst"], project=project) result.assert_main_error(ErrorDomain.CAS, 'insufficient-storage-for-quota') diff --git a/tests/artifactcache/expiry.py b/tests/artifactcache/expiry.py index 6aa518f..46879cf 100644 --- a/tests/artifactcache/expiry.py +++ b/tests/artifactcache/expiry.py @@ -348,7 +348,7 @@ def test_never_delete_required_track(cli, datafiles): def test_invalid_cache_quota(cli, datafiles, quota, err_domain, err_reason): project = str(datafiles) os.makedirs(os.path.join(project, 'elements')) - + create_element_size("file.bst", project, 'elements', [], 1024) cli.configure({ 'cache': { 'quota': quota, @@ -382,7 +382,7 @@ def test_invalid_cache_quota(cli, datafiles, quota, err_domain, err_reason): ) with volume_space_patch, cache_size_patch: - res = cli.run(project=project, args=['workspace', 'list']) + res = cli.run(project=project, args=['build', 'file.bst']) if err_domain == 'success': res.assert_success()
