Skip to content

Instantly share code, notes, and snippets.

@clayg
Created December 1, 2015 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayg/039a19b9d1d320b01a5d to your computer and use it in GitHub Desktop.
Save clayg/039a19b9d1d320b01a5d to your computer and use it in GitHub Desktop.
diff --git a/swift/obj/diskfile.py b/swift/obj/diskfile.py
index 277f865..c5b5bc4 100644
--- a/swift/obj/diskfile.py
+++ b/swift/obj/diskfile.py
@@ -581,6 +581,8 @@ class BaseDiskFileManager(object):
# set final choice of files
if exts['.ts']:
+ results['ts_info'] = exts['.ts'][0]
+ # everything needed is in ts_info; .ts key is for backwards compat
results['.ts'] = exts['.ts'][0]['filename']
if '.data' in results and exts['.meta']:
# only report a meta file if there is a data file
@@ -614,25 +616,20 @@ class BaseDiskFileManager(object):
key 'obsolete'; a list of files remaining in the directory,
reverse sorted, stored under the key 'files'.
"""
- def is_reclaimable(file_):
- # accept either a file info dict or a filename, and figure out if
- # the file is old enough to be reclaimed
- try:
- timestamp = file_.get('timestamp')
- except AttributeError:
- timestamp = self.parse_on_disk_filename(file_)['timestamp']
+ def is_reclaimable(timestamp):
return (time.time() - float(timestamp)) > reclaim_age
files = listdir(hsh_path)
files.sort(reverse=True)
results = self.get_ondisk_files(
files, datadir=None, verify=False, **kwargs)
- if '.ts' in results and is_reclaimable(results['.ts']):
- remove_file(join(hsh_path, results['.ts']))
- files.remove(results.pop('.ts'))
+ if 'ts_info' in results and is_reclaimable(
+ results['ts_info']['timestamp']):
+ remove_file(join(hsh_path, results['ts_info']['filename']))
+ files.remove(results.pop('ts_info')['filename'])
for file_info in results.get('possible_reclaim', []):
# stray fragments are not deleted until reclaim-age
- if is_reclaimable(file_info):
+ if is_reclaimable(file_info['timestamp']):
results.setdefault('obsolete', []).append(file_info)
for file_info in results.get('obsolete', []):
remove_file(join(hsh_path, file_info['filename']))
@clayg
Copy link
Author

clayg commented Dec 1, 2015

One of stronger character than I would remove the .ts key altogether and update all callers and tests to use the richer file_info data-structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment