summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Moody <daniel.moody@mongodb.com>2022-01-14 16:31:22 -0600
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-01 04:29:04 +0000
commit792c2e072d3a3d7c0cf18e31ae2cfa7bee0ab2b0 (patch)
treeb920ec57db986d4ae7b7ce953b51b81ac592407e
parentd90f61381730c82bff2205aba99391b169480293 (diff)
downloadmongo-792c2e072d3a3d7c0cf18e31ae2cfa7bee0ab2b0.tar.gz
SERVER-62680 write cache retrievals into a tmp location before final destination.
(cherry picked from commit d20d317c08fd48b71f790c1bb013aa61c6f0f4b7)
-rw-r--r--buildscripts/scons_cache_prune.py6
-rw-r--r--site_scons/site_tools/validate_cache_dir.py13
2 files changed, 15 insertions, 4 deletions
diff --git a/buildscripts/scons_cache_prune.py b/buildscripts/scons_cache_prune.py
index 9b32db16b1f..4306cc56a96 100644
--- a/buildscripts/scons_cache_prune.py
+++ b/buildscripts/scons_cache_prune.py
@@ -100,6 +100,12 @@ def prune_cache(cache_path, cache_size_gb, clean_ratio):
return False
cache_item = contents.pop()
+
+ # check the atime again just to make sure something wasn't accessed while
+ # we pruning other files.
+ if cache_item.time < os.stat(cache_item.path).st_atime:
+ continue
+
to_remove = cache_item.path + ".del"
try:
os.rename(cache_item.path, to_remove)
diff --git a/site_scons/site_tools/validate_cache_dir.py b/site_scons/site_tools/validate_cache_dir.py
index 2c78fb7deca..2fc62e31c2d 100644
--- a/site_scons/site_tools/validate_cache_dir.py
+++ b/site_scons/site_tools/validate_cache_dir.py
@@ -26,6 +26,7 @@ import logging
import os
import pathlib
import shutil
+import tempfile
import traceback
@@ -107,10 +108,14 @@ class CacheDirValidate(SCons.CacheDir.CacheDir):
if not csig:
raise InvalidChecksum(cls.get_hash_path(src_file), dst, f"no content_hash data found")
- try:
- shutil.copy2(src_file, dst)
- except OSError as ex:
- raise CacheTransferFailed(src_file, dst, f"failed to copy from cache: {ex}") from ex
+ with tempfile.TemporaryDirectory() as tmpdirname:
+ dst_tmp = pathlib.Path(tmpdirname) / os.path.basename(dst)
+ try:
+ shutil.copy2(src_file, dst_tmp)
+ except OSError as ex:
+ raise CacheTransferFailed(src_file, dst, f"failed to copy from cache: {ex}") from ex
+ else:
+ shutil.move(dst_tmp, dst)
new_csig = SCons.Util.MD5filesignature(dst,
chunksize=SCons.Node.FS.File.md5_chunksize*1024)