Skip to content

Instantly share code, notes, and snippets.

@clayg
Last active September 6, 2023 10:58
Show Gist options
  • Save clayg/7f66eab2a61c77869e1e84ac4ed6f1df to your computer and use it in GitHub Desktop.
Save clayg/7f66eab2a61c77869e1e84ac4ed6f1df to your computer and use it in GitHub Desktop.
check on the expirer queue
#!/usr/bin/env python
from collections import defaultdict
import sys
import time
from argparse import ArgumentParser
from swift.common.internal_client import InternalClient
from swift.common.utils import Timestamp
from swift.common.wsgi import ConfigString
from swift.container.sync import ic_conf_body
from swift.obj.expirer import parse_task_obj
parser = ArgumentParser()
parser.add_argument('-v', '--verbose', action='store_true',
help='more detailed info')
parser.add_argument('--objects-container-divisor', type=int, default=86400,
help='The window size for pending expirations')
parser.add_argument('-d', '--details', action='store_true',
help='more detailed counts')
def main():
args = parser.parse_args()
now = time.time()
t_now = Timestamp.now()
expiring_account = '.expiring_objects'
conf = ConfigString(ic_conf_body)
swift = InternalClient(conf, 'swift-expirer-status', 1)
stats = defaultdict(int)
for container_item in swift.iter_containers(expiring_account):
if args.verbose:
print ('%s/' % expiring_account +
'%(name)s: %(count)s' % container_item)
try:
container = int(container_item['name'])
except ValueError:
continue
stats['total'] += container_item['count']
if container < now:
if container < (now - args.objects_container_divisor):
stats['stale'] += container_item['count']
else:
if not args.details:
stats['pending'] += container_item['count']
continue
for object_item in swift.iter_objects(
expiring_account, container_item['name']):
if args.verbose:
print '%(name)s: %(content_type)s' % object_item
# this should probably be done in parse_task_obj
task_object = object_item['name'].encode('utf8')
delete_timestamp, _target_account, _target_container, \
_target_object = parse_task_obj(task_object)
if t_now > delete_timestamp:
stats['stale'] += 1
else:
stats['pending'] += 1
print ' Total entries: %(total)s' % stats
print 'Pending entries: %(pending)s' % stats
print ' Stale entries: %(stale)s' % stats
if __name__ == "__main__":
sys.exit(main())
@mcv21
Copy link

mcv21 commented Sep 6, 2023

I've finally got round to doing this - you can see the CR here:
https://review.opendev.org/c/openstack/swift/+/893861

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