summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Moody <daniel.moody@mongodb.com>2022-01-11 09:49:09 -0600
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-11 23:39:22 +0000
commitee974eefd38564d69147cda4acd34c54f2796760 (patch)
tree2d480c0cf216bbb5f651f9775a58e3f90881166c
parent2e143917631ca3875a021768f0a5d8679ba4f205 (diff)
downloadmongo-ee974eefd38564d69147cda4acd34c54f2796760.tar.gz
SERVER-62285 added processing of cache-dir push failures
https://github.com/SCons/scons/pull/4078
-rw-r--r--buildscripts/scons_cache_prune.py28
-rw-r--r--site_scons/site_tools/validate_cache_dir.py31
-rw-r--r--src/third_party/scons-3.1.2/scons-local-3.1.2/SCons/CacheDir.py3
3 files changed, 46 insertions, 16 deletions
diff --git a/buildscripts/scons_cache_prune.py b/buildscripts/scons_cache_prune.py
index 9b32db16b1f..84f40f78ac8 100644
--- a/buildscripts/scons_cache_prune.py
+++ b/buildscripts/scons_cache_prune.py
@@ -24,10 +24,9 @@ GIGBYTES = 1024 * 1024 * 1024
CacheItem = collections.namedtuple("CacheContents", ["path", "time", "size"])
-def get_cachefile_size(file_path):
+def get_cachefile_size(file_path, is_cksum):
"""Get the size of the cachefile."""
-
- if file_path.lower().endswith('.cksum') or file_path.lower().endswith('.cksum.del'):
+ if is_cksum:
size = 0
for cksum_path in os.listdir(file_path):
cksum_path = os.path.join(file_path, cksum_path)
@@ -51,19 +50,26 @@ def collect_cache_contents(cache_path):
for file_name in os.listdir(path):
file_path = os.path.join(path, file_name)
# Cache prune script is allowing only directories with this extension
- # which comes from the validate_cache_dir.py tool in scons, it must match
+ # which comes from the validate_cache_dir.py tool in SCons, it must match
# the extension set in that file.
- if os.path.isdir(file_path) and not file_path.lower().endswith(
- '.cksum') and not file_path.lower().endswith('.cksum.del'):
- LOGGER.warning(
- "cache item %s is a directory and not a file. "
- "The cache may be corrupt.", file_path)
- continue
+ cksum_type = False
+ if os.path.isdir(file_path):
+ hash_length = -32
+ tmp_length = -len('.cksum.tmp') + hash_length
+ cksum_type = (file_path.lower().endswith('.cksum')
+ or file_path.lower().endswith('.cksum.del')
+ or file_path.lower()[tmp_length:hash_length] == '.cksum.tmp')
+
+ if not cksum_type:
+ LOGGER.warning(
+ "cache item %s is a directory and not a file. "
+ "The cache may be corrupt.", file_path)
+ continue
try:
item = CacheItem(path=file_path, time=os.stat(file_path).st_atime,
- size=get_cachefile_size(file_path))
+ size=get_cachefile_size(file_path, cksum_type))
total += item.size
diff --git a/site_scons/site_tools/validate_cache_dir.py b/site_scons/site_tools/validate_cache_dir.py
index 2c78fb7deca..e6d9118d3d1 100644
--- a/site_scons/site_tools/validate_cache_dir.py
+++ b/site_scons/site_tools/validate_cache_dir.py
@@ -24,6 +24,7 @@ import datetime
import json
import logging
import os
+import sys
import pathlib
import shutil
import traceback
@@ -33,7 +34,10 @@ import SCons
cache_debug_suffix = " (target: %s, cachefile: %s) "
-class InvalidChecksum(SCons.Errors.BuildError):
+class ValidateCacheDirError(SCons.Errors.BuildError):
+ pass
+
+class InvalidChecksum(ValidateCacheDirError):
def __init__(self, src, dst, reason, cache_csig='', computed_csig=''):
self.message = f"ERROR: md5 checksum {reason} for {src} ({dst})"
self.cache_csig = cache_csig
@@ -41,14 +45,14 @@ class InvalidChecksum(SCons.Errors.BuildError):
def __str__(self):
return self.message
-class CacheTransferFailed(SCons.Errors.BuildError):
+class CacheTransferFailed(ValidateCacheDirError):
def __init__(self, src, dst, reason):
self.message = f"ERROR: cachedir transfer {reason} while transfering {src} to {dst}"
def __str__(self):
return self.message
-class UnsupportedError(SCons.Errors.BuildError):
+class UnsupportedError(ValidateCacheDirError):
def __init__(self, class_name, feature):
self.message = f"{class_name} does not support {feature}"
@@ -174,7 +178,7 @@ class CacheDirValidate(SCons.CacheDir.CacheDir):
try:
return super().push(node)
except CacheTransferFailed as ex:
- self.print_cache_issue(node, ex)
+ self.print_push_issue(node, ex)
return False
def CacheDebugJson(self, json_data, target, cachefile):
@@ -197,6 +201,17 @@ class CacheDirValidate(SCons.CacheDir.CacheDir):
self.json_log.write(json.dumps(json_data) + '\n')
def CacheDebug(self, fmt, target, cachefile):
+
+ # Capture exception information for exception types
+ # which may bubble up from SCons proper. Non ValidateCacheDirError
+ # failures which come up from SCons may omit exception information.
+ # if this is a Non ValidateCacheDirError exception, we will emit a ValidateCacheDirError
+ # in place, which will capture the exception information and come back through
+ # this function to be logged in our normal CacheDirValidate process.
+ ex = sys.exc_info()[1]
+ if ex and not isinstance(ex, ValidateCacheDirError):
+ raise CacheTransferFailed(target, cachefile, f"failed: {ex}") from ex
+
# The target cachefile will live in a directory with the special
# extension for this cachedir class. Check if this cachefile is
# in a directory like that and customize the debug logs.
@@ -212,6 +227,14 @@ class CacheDirValidate(SCons.CacheDir.CacheDir):
self.CacheDebug(log_msg + cache_debug_suffix, realnode, cachefile)
self.CacheDebugJson(json_info, realnode, cachefile)
+ def print_push_issue(self, node, ex):
+
+ cksum_dir = pathlib.Path(self.cachepath(node)[1])
+ msg = ('An issue was detected while pushing to the cache:\n' +
+ ' ' + "\n ".join("".join(traceback.format_exc()).split("\n")))
+
+ self._log(msg, str(ex), {'type': 'push_fail', 'error': msg}, node, cksum_dir)
+
def print_cache_issue(self, node, ex):
cksum_dir = pathlib.Path(self.cachepath(node)[1])
diff --git a/src/third_party/scons-3.1.2/scons-local-3.1.2/SCons/CacheDir.py b/src/third_party/scons-3.1.2/scons-local-3.1.2/SCons/CacheDir.py
index 804a315c717..48f2e5447c5 100644
--- a/src/third_party/scons-3.1.2/scons-local-3.1.2/SCons/CacheDir.py
+++ b/src/third_party/scons-3.1.2/scons-local-3.1.2/SCons/CacheDir.py
@@ -131,7 +131,8 @@ def CachePushFunc(target, source, env):
# the CacheDir being on a separate file system that's full.
# In any case, inability to push a file to cache doesn't affect
# the correctness of the build, so just print a warning.
- msg = errfmt % (str(target), cachefile)
+ msg = errfmt % (str(t), cachefile)
+ cd.CacheDebug(errfmt, str(t), cachefile)
SCons.Warnings.warn(SCons.Warnings.CacheWriteErrorWarning, msg)
CachePush = SCons.Action.Action(CachePushFunc, None)