Created
October 25, 2016 14:46
-
-
Save clayg/f659cc0fa001c0485390cbccb8420a2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import errno | |
from collections import defaultdict | |
from swift.common.ring import Ring | |
device_root = sys.argv[1] | |
r = Ring('/etc/swift/object.ring.gz') | |
dev2parts = defaultdict(set) | |
for replica, part2dev in enumerate(r._replica2part2dev_id): | |
for part, device_id in enumerate(part2dev): | |
dev2parts[r.devs[device_id]['device']].add(part) | |
# print dev2parts | |
handoffs = defaultdict(set) | |
device_dirs = os.listdir(device_root) | |
for device_dir in device_dirs: | |
parts_dir = os.path.join(device_root, device_dir, 'objects') | |
try: | |
parts = os.listdir(parts_dir) | |
except OSError as e: | |
if e.errno == errno.ENOENT: | |
continue | |
else: | |
raise | |
for part in parts: | |
if not part.isdigit(): | |
continue | |
part = int(part) | |
if part in dev2parts[device_dir]: | |
continue | |
handoffs[device_dir].add(part) | |
for device, parts in handoffs.items(): | |
print os.path.join(device_root, device) | |
for part in parts: | |
print ' ', part |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment