Skip to content

Commit 019254d

Browse files
committed
Fix s3fs to use cached metadata and files during network outage
1 parent f8ec87c commit 019254d

File tree

1 file changed

+18
-3
lines changed
  • hubblestack/extmods/fileserver

1 file changed

+18
-3
lines changed

hubblestack/extmods/fileserver/s3fs.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,12 @@ def find_file(path, saltenv='base', **kwargs):
179179

180180
cached_file_path = _get_cached_file_name(fnd['bucket'], saltenv, path)
181181

182-
# jit load the file from S3 if it's not in the cache or it's old
183-
_get_file_from_s3(metadata, saltenv, fnd['bucket'], path, cached_file_path)
182+
try:
183+
# jit load the file from S3 if it's not in the cache or it's old
184+
_get_file_from_s3(metadata, saltenv, fnd['bucket'], path, cached_file_path)
185+
except:
186+
if not os.path.isfile(cached_file_path):
187+
raise
184188

185189
return fnd
186190

@@ -363,7 +367,18 @@ def _init():
363367

364368
if metadata is None:
365369
# bucket files cache expired or does not exist
366-
metadata = _refresh_buckets_cache_file(cache_file)
370+
try:
371+
metadata = _refresh_buckets_cache_file(cache_file)
372+
except:
373+
# If we failed to fetch new metadata, then try to fallback on the cache
374+
try:
375+
if os.path.isfile(cache_file):
376+
metadata = _read_buckets_cache_file(cache_file)
377+
return metadata
378+
except OSError:
379+
pass
380+
# No cache file, so raise.
381+
raise
367382

368383
return metadata
369384

0 commit comments

Comments
 (0)