Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

full merge of storage policies to master #1

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b7659be
Add --quoted option to swift-temp-url
clayg May 3, 2014
c384d76
Merge "Add --quoted option to swift-temp-url"
Jun 3, 2014
c450dc0
Add Storage Policy Documentation
peluse Apr 7, 2014
0fa15b2
Add Storage Policy Support
peluse Mar 17, 2014
bbfeae4
Update FakeRing and FakeLogger
clayg Apr 29, 2014
5727f5d
Add Storage Policy support to Containers
clayg May 27, 2014
b2019ab
Add Storage Policy support to Object Server
clayg May 27, 2014
1996780
Add Storage Policy support to Object Updates
smerritt Mar 18, 2014
09806c3
Add Storage Policy Support to the Auditor
peluse Mar 18, 2014
725e361
Add storage policy support for the Replicator
peluse Mar 18, 2014
7078a76
Add Storage Policy Support to ssync
peluse Mar 18, 2014
81bedb8
Put X-Backend-Timestamp in object 404 responses
Mar 23, 2014
2cd90b7
Extend interface on InternalClient
clayg Apr 17, 2014
7272315
Extend direct_client
clayg May 27, 2014
83e6ed4
Add container-reconciler daemon
clayg Apr 29, 2014
79ecac9
Add reconciler probetest outline
clayg Apr 29, 2014
7f67147
Merge container storage_policy_index
clayg May 28, 2014
7c45fa0
Add Storage Policy Support to Accounts
clayg May 28, 2014
35ea1d9
Add functional tests for Storage Policy
zhouyuan Apr 9, 2014
4e5d341
Update bin scripts to be storage policy aware
clayg May 28, 2014
fc9c334
Enqueue misplaced objects during container replication
clayg Apr 29, 2014
6203abc
Add LRUCache to common.utils
clayg Apr 29, 2014
aaf1659
Fixes probe tests with non-zero default storage policy
zhouyuan Apr 15, 2014
d083bf0
Add Storage Policy Support to list_endpoints
peluse Mar 18, 2014
fc5a715
Add Storage Policy Support to Container Sync
peluse Apr 9, 2014
78bfb46
Add Storage Policy Support to Recon Middleware
peluse Apr 14, 2014
04392cb
Add Storage Policy support to the Account Reaper
peluse Apr 16, 2014
7180a2f
Fix object-expirer for missing objects
clayg Jun 6, 2014
56d4995
Add two vector timestamps
clayg Jun 11, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions bin/swift-container-reconciler
@@ -0,0 +1,21 @@
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from swift.container.reconciler import ContainerReconciler
from swift.common.utils import parse_options
from swift.common.daemon import run_daemon

if __name__ == '__main__':
conf_file, options = parse_options(once=True)
run_daemon(ContainerReconciler, conf_file, **options)
170 changes: 55 additions & 115 deletions bin/swift-get-nodes
Expand Up @@ -14,129 +14,69 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import optparse
import sys
import urllib
import os
from optparse import OptionParser

from swift.common.ring import Ring
from swift.common.utils import hash_path, storage_directory
from swift.cli.info import print_item_locations, InfoSystemExit


parser = optparse.OptionParser()
parser.add_option('-a', '--all', action='store_true',
help='Show all handoff nodes')
parser.add_option('-p', '--partition', metavar='PARTITION',
help='Show nodes for a given partition')
(options, args) = parser.parse_args()
if __name__ == '__main__':

if (len(args) < 2 or len(args) > 4) and \
(options.partition is None or not args):
print 'Usage: %s [-a] <ring.gz> <account> [<container>] [<object>]' \
% sys.argv[0]
print ' Or: %s [-a] <ring.gz> -p partition' % sys.argv[0]
print ' Note: account, container, object can also be a single arg ' \
'separated by /'
print 'Shows the nodes responsible for the item specified.'
print 'Example:'
print ' $ %s /etc/swift/account.ring.gz MyAccount' % sys.argv[0]
print ' Partition 5743883'
print ' Hash 96ae332a60b58910784e4417a03e1ad0'
print ' 10.1.1.7:8000 sdd1'
print ' 10.1.9.2:8000 sdb1'
print ' 10.1.5.5:8000 sdf1'
print ' 10.1.5.9:8000 sdt1 # [Handoff]'
sys.exit(1)
usage = '''
Shows the nodes responsible for the item specified.
Usage: %prog [-a] <ring.gz> <account> [<container>] [<object>]
Or: %prog [-a] <ring.gz> -p partition
Or: %prog [-a] -P policy_name <account> <container> <object>
Note: account, container, object can also be a single arg separated by /
Example:
$ %prog -a /etc/swift/account.ring.gz MyAccount
Partition 5743883
Hash 96ae332a60b58910784e4417a03e1ad0
10.1.1.7:8000 sdd1
10.1.9.2:8000 sdb1
10.1.5.5:8000 sdf1
10.1.5.9:8000 sdt1 # [Handoff]
'''
parser = OptionParser(usage)
parser.add_option('-a', '--all', action='store_true',
help='Show all handoff nodes')
parser.add_option('-p', '--partition', metavar='PARTITION',
help='Show nodes for a given partition')
parser.add_option('-P', '--policy-name', dest='policy_name',
help='Specify which policy to use')
parser.add_option('-d', '--swift-dir', default='/etc/swift',
dest='swift_dir', help='Path to swift directory')
options, args = parser.parse_args()

if len(args) == 2 and '/' in args[1]:
# Parse single path arg, as noted in above help text.
path = args[1].lstrip('/')
args = [args[0]] + [p for p in path.split('/', 2) if p]

ringloc = None
account = None
container = None
obj = None
# swift-get-nodes -P nada -p 1
if len(args) == 0:
if not options.policy_name or not options.partition:
sys.exit(parser.print_help())
elif len(args) > 4 or len(args) < 1:
sys.exit(parser.print_help())

if len(args) == 4:
# Account, Container and Object
ring_file, account, container, obj = args
ring = Ring(ring_file)
hash_str = hash_path(account, container, obj)
part, nodes = ring.get_nodes(account, container, obj)
target = "%s/%s/%s" % (account, container, obj)
loc = 'objects'
elif len(args) == 3:
# Account, Container
ring_file, account, container = args
ring = Ring(ring_file)
hash_str = hash_path(account, container)
part, nodes = ring.get_nodes(account, container)
target = "%s/%s" % (account, container)
loc = 'containers'
elif len(args) == 2:
# Account
ring_file, account = args
ring = Ring(ring_file)
hash_str = hash_path(account)
part, nodes = ring.get_nodes(account)
target = "%s" % (account)
loc = 'accounts'
elif len(args) == 1:
# Partition
ring_file = args[0]
ring = Ring(ring_file)
hash_str = None
part = int(options.partition)
nodes = ring.get_part_nodes(part)
target = ''
loc = ring_file.rsplit('/', 1)[-1].split('.', 1)[0]
if loc in ('account', 'container', 'object'):
loc += 's'
else:
loc = '<type>'
# Parse single path arg, as noted in above help text.
if len(args) == 1 and options.policy_name and '/' in args[0]:
path = args[0].lstrip('/')
args = [p for p in path.split('/', 2) if p]
if len(args) == 2 and '/' in args[1]:
path = args[1].lstrip('/')
args = [args[0]] + [p for p in path.split('/', 2) if p]

more_nodes = []
for more_node in ring.get_more_nodes(part):
more_nodes.append(more_node)
if not options.all and len(more_nodes) >= len(nodes):
break
ring = None
ring_name = None

print '\nAccount \t%s' % account
print 'Container\t%s' % container
print 'Object \t%s\n' % obj
print '\nPartition\t%s' % part
print 'Hash \t%s\n' % hash_str
if len(args) >= 1 and args[0].endswith('ring.gz'):
if os.path.exists(args[0]):
ring_name = args[0].rsplit('/', 1)[-1].split('.', 1)[0]
ring = Ring(args[0])
else:
print 'Ring file does not exist'
args.pop(0)

for node in nodes:
print 'Server:Port Device\t%s:%s %s' % (node['ip'], node['port'],
node['device'])
for mnode in more_nodes:
print 'Server:Port Device\t%s:%s %s\t [Handoff]' \
% (mnode['ip'], mnode['port'], mnode['device'])
print "\n"
for node in nodes:
print 'curl -I -XHEAD "http://%s:%s/%s/%s/%s"' \
% (node['ip'], node['port'], node['device'], part,
urllib.quote(target))
for mnode in more_nodes:
print 'curl -I -XHEAD "http://%s:%s/%s/%s/%s" # [Handoff]' \
% (mnode['ip'], mnode['port'], mnode['device'], part,
urllib.quote(target))
print "\n"
print 'Use your own device location of servers:'
print 'such as "export DEVICE=/srv/node"'
for node in nodes:
if hash_str:
print 'ssh %s "ls -lah ${DEVICE:-/srv/node}/%s/%s/"' % (
node['ip'], node['device'], storage_directory(loc, part, hash_str))
else:
print 'ssh %s "ls -lah ${DEVICE:-/srv/node}/%s/%s/%s/"' % (
node['ip'], node['device'], loc, part)
for mnode in more_nodes:
if hash_str:
print 'ssh %s "ls -lah ${DEVICE:-/srv/node}/%s/%s/" '\
'# [Handoff]' % (mnode['ip'], mnode['device'],
storage_directory(loc, part, hash_str))
else:
print 'ssh %s "ls -lah ${DEVICE:-/srv/node}/%s/%s/%s/" # [Handoff]' % (
mnode['ip'], mnode['device'], loc, part)
try:
print_item_locations(ring, ring_name, *args, **vars(options))
except InfoSystemExit:
sys.exit(1)
107 changes: 13 additions & 94 deletions bin/swift-object-info
Expand Up @@ -14,112 +14,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
from datetime import datetime
from hashlib import md5
from optparse import OptionParser

from swift.common.ring import Ring
from swift.obj.diskfile import read_metadata
from swift.common.utils import hash_path, storage_directory


def print_object_info(datafile, check_etag=True, swift_dir='/etc/swift'):
if not os.path.exists(datafile) or not datafile.endswith('.data'):
print "Data file doesn't exist"
sys.exit(1)
try:
ring = Ring(swift_dir, ring_name='object')
except Exception:
ring = None
fp = open(datafile, 'rb')
metadata = read_metadata(fp)
path = metadata.pop('name', '')
content_type = metadata.pop('Content-Type', '')
ts = metadata.pop('X-Timestamp', '')
etag = metadata.pop('ETag', '')
length = metadata.pop('Content-Length', '')
if path:
print 'Path: %s' % path
account, container, obj = path.split('/', 3)[1:]
print ' Account: %s' % account
print ' Container: %s' % container
print ' Object: %s' % obj
obj_hash = hash_path(account, container, obj)
print ' Object hash: %s' % obj_hash
else:
print 'Path: Not found in metadata'
if content_type:
print 'Content-Type: %s' % content_type
else:
print 'Content-Type: Not found in metadata'
if ts:
print 'Timestamp: %s (%s)' % (datetime.fromtimestamp(float(ts)), ts)
else:
print 'Timestamp: Not found in metadata'

file_len = None
if check_etag:
h = md5()
file_len = 0
while True:
data = fp.read(64 * 1024)
if not data:
break
h.update(data)
file_len += len(data)
h = h.hexdigest()
if etag:
if h == etag:
print 'ETag: %s (valid)' % etag
else:
print "Etag: %s doesn't match file hash of %s!" % (etag, h)
else:
print 'ETag: Not found in metadata'
else:
print 'ETag: %s (not checked)' % etag
file_len = os.fstat(fp.fileno()).st_size

if length:
if file_len == int(length):
print 'Content-Length: %s (valid)' % length
else:
print "Content-Length: %s doesn't match file length of %s" % (
length, file_len)
else:
print 'Content-Length: Not found in metadata'
print 'User Metadata: %s' % metadata
if ring is not None:
print 'Ring locations:'
part, nodes = ring.get_nodes(account, container, obj)
for node in nodes:
print (' %s:%s - /srv/node/%s/%s/%s.data' %
(node['ip'], node['port'], node['device'],
storage_directory('objects', part, obj_hash), ts))
print
print 'note: /srv/node is used as default value of `devices`, '\
'the real value is set in object-server.conf '\
'on each storage node.'
fp.close()
from swift.cli.info import print_obj, InfoSystemExit


if __name__ == '__main__':
parser = OptionParser()
parser.set_defaults(check_etag=True, swift_dir='/etc/swift')
parser = OptionParser('%prog [options] OBJECT_FILE')
parser.add_option(
'-n', '--no-check-etag',
'-n', '--no-check-etag', default=True,
action="store_false", dest="check_etag",
help="Don't verify file contents against stored etag")
parser.add_option(
'-d', '--swift-dir',
'-d', '--swift-dir', default='/etc/swift', dest='swift_dir',
help="Pass location of swift directory")
parser.add_option(
'-P', '--policy-name', dest='policy_name',
help="Specify storage policy name")

options, args = parser.parse_args()

if len(args) < 1:
print "Usage: %s [-n] [-d] OBJECT_FILE" % sys.argv[0]
sys.exit(1)
if len(args) != 1:
sys.exit(parser.print_help())

print_object_info(args[0], check_etag=options.check_etag,
swift_dir=options.swift_dir)
try:
print_obj(*args, **vars(options))
except InfoSystemExit:
sys.exit(1)