summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-09-08 16:16:39 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-09-10 16:53:56 +0900
commit26ccc1ba12aae8d2f0bff2d1dc4abc39fe595381 (patch)
tree9b939175efa0a9aa166a9ec6fac436686237b482
parent1f118ba4d9ff1a342ddcebf22be57205161209b8 (diff)
downloadbuildstream-26ccc1ba12aae8d2f0bff2d1dc4abc39fe595381.tar.gz
_artifactcache: Making public methods public
The artifact cache provides the following public methods for external callers, but was hiding them away as if they are private. o ArtifactCache.add_artifact_size() o ArtifactCache.set_cache_size() Mark these properly public
-rw-r--r--buildstream/_artifactcache/artifactcache.py61
-rw-r--r--buildstream/_scheduler/jobs/cachesizejob.py2
-rw-r--r--buildstream/_scheduler/jobs/cleanupjob.py2
-rw-r--r--buildstream/_scheduler/queues/buildqueue.py2
4 files changed, 35 insertions, 32 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py
index f162c7f08..b7a51793e 100644
--- a/buildstream/_artifactcache/artifactcache.py
+++ b/buildstream/_artifactcache/artifactcache.py
@@ -294,6 +294,38 @@ class ArtifactCache():
return self.estimated_size
+ # add_artifact_size()
+ #
+ # Adds the reported size of a newly cached artifact to the
+ # overall ArtifactCache.estimated_size.
+ #
+ # Args:
+ # artifact_size (int): The size to add.
+ #
+ def add_artifact_size(self, artifact_size):
+ if not self.estimated_size:
+ self.estimated_size = self.calculate_cache_size()
+
+ self.estimated_size += artifact_size
+ self._write_cache_size(self.estimated_size)
+
+ # set_cache_size()
+ #
+ # Forcefully set the overall cache size.
+ #
+ # This is used to update the size in the main process after
+ # having calculated in a cleanup or a cache size calculation job.
+ #
+ # Args:
+ # cache_size (int): The size to set.
+ #
+ def set_cache_size(self, cache_size):
+ self.estimated_size = cache_size
+
+ # set_cache_size is called in cleanup, where it may set the cache to None
+ if self.estimated_size is not None:
+ self._write_cache_size(self.estimated_size)
+
################################################
# Abstract methods for subclasses to implement #
################################################
@@ -535,35 +567,6 @@ class ArtifactCache():
with self.context.timed_activity("Initializing remote caches", silent_nested=True):
self.initialize_remotes(on_failure=remote_failed)
- # _add_artifact_size()
- #
- # Since we cannot keep track of the cache size between threads,
- # this method will be called by the main process every time a
- # process that added something to the cache finishes.
- #
- # This will then add the reported size to
- # ArtifactCache.estimated_size.
- #
- def _add_artifact_size(self, artifact_size):
- if not self.estimated_size:
- self.estimated_size = self.calculate_cache_size()
-
- self.estimated_size += artifact_size
- self._write_cache_size(self.estimated_size)
-
- # _set_cache_size()
- #
- # Similarly to the above method, when we calculate the actual size
- # in a child thread, we can't update it. We instead pass the value
- # back to the main thread and update it there.
- #
- def _set_cache_size(self, cache_size):
- self.estimated_size = cache_size
-
- # set_cache_size is called in cleanup, where it may set the cache to None
- if self.estimated_size is not None:
- self._write_cache_size(self.estimated_size)
-
# _write_cache_size()
#
# Writes the given size of the artifact to the cache's size file
diff --git a/buildstream/_scheduler/jobs/cachesizejob.py b/buildstream/_scheduler/jobs/cachesizejob.py
index f73a09c74..a3d247fe3 100644
--- a/buildstream/_scheduler/jobs/cachesizejob.py
+++ b/buildstream/_scheduler/jobs/cachesizejob.py
@@ -30,7 +30,7 @@ class CacheSizeJob(Job):
return self._cache.calculate_cache_size()
def parent_complete(self, success, result):
- self._cache._set_cache_size(result)
+ self._cache.set_cache_size(result)
if self._complete_cb:
self._complete_cb(result)
diff --git a/buildstream/_scheduler/jobs/cleanupjob.py b/buildstream/_scheduler/jobs/cleanupjob.py
index bb78e8751..199ae70f8 100644
--- a/buildstream/_scheduler/jobs/cleanupjob.py
+++ b/buildstream/_scheduler/jobs/cleanupjob.py
@@ -30,7 +30,7 @@ class CleanupJob(Job):
return self._cache.clean()
def parent_complete(self, success, result):
- self._cache._set_cache_size(result)
+ self._cache.set_cache_size(result)
if self._complete_cb:
self._complete_cb()
diff --git a/buildstream/_scheduler/queues/buildqueue.py b/buildstream/_scheduler/queues/buildqueue.py
index 54eb09c0d..410223bb5 100644
--- a/buildstream/_scheduler/queues/buildqueue.py
+++ b/buildstream/_scheduler/queues/buildqueue.py
@@ -95,7 +95,7 @@ class BuildQueue(Queue):
if artifact_size:
cache = element._get_artifact_cache()
- cache._add_artifact_size(artifact_size)
+ cache.add_artifact_size(artifact_size)
if cache.get_approximate_cache_size() > cache.cache_quota:
self._scheduler._check_cache_size_real()