You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2022/02/17 04:47:15 UTC

[buildstream] branch bst-1 updated: Heal from corruption where cache_size is empty file

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch bst-1
in repository https://gitbox.apache.org/repos/asf/buildstream.git


The following commit(s) were added to refs/heads/bst-1 by this push:
     new 6c4c412  Heal from corruption where cache_size is empty file
     new 159eaed  Merge pull request #1575 from nanonyme/nanonyme/recover-from-corruption
6c4c412 is described below

commit 6c4c412b424b73f620337703a437a1033ee61711
Author: Seppo Yli-Olli <se...@gmail.com>
AuthorDate: Tue Jan 25 00:47:50 2022 +0200

    Heal from corruption where cache_size is empty file
---
 buildstream/_artifactcache/artifactcache.py | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py
index fc873e4..289ce9e 100644
--- a/buildstream/_artifactcache/artifactcache.py
+++ b/buildstream/_artifactcache/artifactcache.py
@@ -448,6 +448,10 @@ class ArtifactCache():
                 self._cache_size = stored_size
             else:
                 self.compute_cache_size()
+                # Computing cache doesn't actually write the value.
+                # Write cache size explicitly here since otherwise
+                # in some cases it's not stored on disk.
+                self.set_cache_size(self._cache_size)
 
         return self._cache_size
 
@@ -865,19 +869,21 @@ class ArtifactCache():
     def _read_cache_size(self):
         size_file_path = os.path.join(self.context.artifactdir, CACHE_SIZE_FILE)
 
-        if not os.path.exists(size_file_path):
+        try:
+            with open(size_file_path, "r", encoding="utf-8") as f:
+                size = f.read()
+        except FileNotFoundError:
             return None
 
-        with open(size_file_path, "r", encoding="utf-8") as f:
-            size = f.read()
-
         try:
             num_size = int(size)
-        except ValueError as e:
-            raise ArtifactError("Size '{}' parsed from '{}' was not an integer".format(
-                size, size_file_path)) from e
-
-        return num_size
+        except ValueError:
+            self._message(MessageType.WARN, "Failure resolving cache size",
+                          detail="Size '{}' parsed from '{}' was not an integer"
+                          .format(size, size_file_path))
+            return None
+        else:
+            return num_size
 
     # _calculate_cache_quota()
     #