summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2019-03-21 16:37:14 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-03-21 16:37:14 +0000
commitaa326c937b0146269be78ff03a554d6c1d7826cb (patch)
treee0a3539d0b1aadb6ffd73f0e010393dc5f0a9f35
parent7b8c730e53326c89386ffc661a0200df2706e29f (diff)
parent65e9ee94be463b98148aff58dad4bd306ac206ba (diff)
downloadbuildstream-aa326c937b0146269be78ff03a554d6c1d7826cb.tar.gz
Merge branch 'aevri/you_only_write_once' into 'master'
cleanupjob, cascache: don't write cache size twice See merge request BuildStream/buildstream!1227
-rw-r--r--buildstream/_artifactcache.py3
-rw-r--r--buildstream/_cas/cascache.py29
-rw-r--r--buildstream/_scheduler/jobs/cleanupjob.py4
-rw-r--r--tests/artifactcache/cache_size.py2
4 files changed, 10 insertions, 28 deletions
diff --git a/buildstream/_artifactcache.py b/buildstream/_artifactcache.py
index 49f07cb50..11aa4bc1b 100644
--- a/buildstream/_artifactcache.py
+++ b/buildstream/_artifactcache.py
@@ -25,9 +25,6 @@ from ._cas import CASRemoteSpec
from .storage._casbaseddirectory import CasBasedDirectory
-CACHE_SIZE_FILE = "cache_size"
-
-
# An ArtifactCacheSpec holds the user configuration for a single remote
# artifact cache.
#
diff --git a/buildstream/_cas/cascache.py b/buildstream/_cas/cascache.py
index e07b4d4b4..6d52aaa0d 100644
--- a/buildstream/_cas/cascache.py
+++ b/buildstream/_cas/cascache.py
@@ -1064,31 +1064,15 @@ class CASQuota:
# compute_cache_size()
#
- # Computes the real artifact cache size by calling
- # the abstract calculate_cache_size() method.
+ # Computes the real artifact cache size.
#
# Returns:
# (int): The size of the artifact cache.
#
def compute_cache_size(self):
- old_cache_size = self._cache_size
- new_cache_size = self.calculate_cache_size()
-
- if old_cache_size != new_cache_size:
- self._cache_size = new_cache_size
-
+ self._cache_size = utils._get_dir_size(self.casdir)
return self._cache_size
- # calculate_cache_size()
- #
- # Return the real disk usage of the CAS cache.
- #
- # Returns:
- # (int): The size of the cache.
- #
- def calculate_cache_size(self):
- return utils._get_dir_size(self.casdir)
-
# get_cache_size()
#
# Fetches the cached size of the cache, this is sometimes
@@ -1109,7 +1093,7 @@ class CASQuota:
if stored_size is not None:
self._cache_size = stored_size
else:
- self._cache_size = self.compute_cache_size()
+ self.compute_cache_size()
return self._cache_size
@@ -1122,13 +1106,15 @@ class CASQuota:
#
# Args:
# cache_size (int): The size to set.
+ # write_to_disk (bool): Whether to write the value to disk.
#
- def set_cache_size(self, cache_size):
+ def set_cache_size(self, cache_size, *, write_to_disk=True):
assert cache_size is not None
self._cache_size = cache_size
- self._write_cache_size(self._cache_size)
+ if write_to_disk:
+ self._write_cache_size(self._cache_size)
# full()
#
@@ -1383,7 +1369,6 @@ class CASQuota:
utils._pretty_size(size, dec_places=2),
to_remove)))
- # Remove the size from the removed size
self.set_cache_size(self._cache_size - size)
# User callback
diff --git a/buildstream/_scheduler/jobs/cleanupjob.py b/buildstream/_scheduler/jobs/cleanupjob.py
index 9610d53f8..3ea1daa04 100644
--- a/buildstream/_scheduler/jobs/cleanupjob.py
+++ b/buildstream/_scheduler/jobs/cleanupjob.py
@@ -38,14 +38,14 @@ class CleanupJob(Job):
# Update the cache size in the main process as we go,
# this provides better feedback in the UI.
if message_type == 'update-cache-size':
- self._casquota.set_cache_size(message)
+ self._casquota.set_cache_size(message, write_to_disk=False)
return True
return False
def parent_complete(self, status, result):
if status == JobStatus.OK:
- self._casquota.set_cache_size(result)
+ self._casquota.set_cache_size(result, write_to_disk=False)
if self._complete_cb:
self._complete_cb(status, result)
diff --git a/tests/artifactcache/cache_size.py b/tests/artifactcache/cache_size.py
index 104c43ce0..c6ba15794 100644
--- a/tests/artifactcache/cache_size.py
+++ b/tests/artifactcache/cache_size.py
@@ -2,7 +2,7 @@ import os
from unittest import mock
from buildstream import _yaml
-from buildstream._artifactcache import CACHE_SIZE_FILE
+from buildstream._cas.cascache import CACHE_SIZE_FILE
from buildstream._exceptions import ErrorDomain
from buildstream.plugintestutils import cli