revert x-cf-trans-id rename

This commit is contained in:
Clay Gerrard
2011-01-05 13:52:33 -06:00
parent 9786ab6687
commit 30fd2dd0f2
7 changed files with 27 additions and 55 deletions

View File

@@ -29,7 +29,7 @@ import simplejson
from swift.common.db import AccountBroker
from swift.common.utils import get_logger, get_param, hash_path, \
normalize_timestamp, split_path, storage_directory, get_txn_id
normalize_timestamp, split_path, storage_directory
from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \
check_mount, check_float, check_utf8
from swift.common.db_replicator import ReplicatorRpc
@@ -86,7 +86,7 @@ class AccountController(object):
return Response(status='507 %s is not mounted' % drive)
broker = self._get_account_broker(drive, part, account)
if container: # put account container
if get_txn_id(req, None) is None:
if 'x-cf-trans-id' in req.headers:
broker.pending_timeout = 3
if req.headers.get('x-account-override-deleted', 'no').lower() != \
'yes' and broker.is_deleted():
@@ -296,7 +296,7 @@ class AccountController(object):
def __call__(self, env, start_response):
start_time = time.time()
req = Request(env)
self.logger.txn_id = get_txn_id(req, None)
self.logger.txn_id = req.headers.get('x-cf-trans-id', None)
if not check_utf8(req.path_info):
res = HTTPPreconditionFailed(body='Invalid UTF8')
else:
@@ -319,7 +319,7 @@ class AccountController(object):
time.strftime('%d/%b/%Y:%H:%M:%S +0000', time.gmtime()),
req.method, req.path,
res.status.split()[0], res.content_length or '-',
get_txn_id(req, '-'),
req.headers.get('x-cf-trans-id', '-'),
req.referer or '-', req.user_agent or '-',
trans_time,
additional_info)

View File

@@ -107,16 +107,6 @@ def get_param(req, name, default=None):
value.decode('utf8') # Ensure UTF8ness
return value
def get_txn_id(req, default=None):
"""
Get the transaction id from a request
:param req: Webob request object
:param default: value to return if no transaction id is found
"""
return req.headers.get('x-swift-txn-id',
req.headers.get('x-cf-trans-id', default))
def fallocate(fd, size):
"""

View File

@@ -31,7 +31,7 @@ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
from swift.common.db import ContainerBroker
from swift.common.utils import get_logger, get_param, hash_path, \
normalize_timestamp, storage_directory, split_path, get_txn_id
normalize_timestamp, storage_directory, split_path
from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
check_mount, check_float, check_utf8
from swift.common.bufferedhttp import http_connect
@@ -95,7 +95,7 @@ class ContainerController(object):
'x-delete-timestamp': info['delete_timestamp'],
'x-object-count': info['object_count'],
'x-bytes-used': info['bytes_used'],
'x-swift-txn-id': get_txn_id(req, '-')}
'x-cf-trans-id': req.headers.get('X-Cf-Trans-Id', '-')}
if req.headers.get('x-account-override-deleted', 'no').lower() == \
'yes':
account_headers['x-account-override-deleted'] = 'yes'
@@ -384,7 +384,7 @@ class ContainerController(object):
def __call__(self, env, start_response):
start_time = time.time()
req = Request(env)
self.logger.txn_id = get_txn_id(req, None)
self.logger.txn_id = req.headers.get('x-cf-trans-id', None)
if not check_utf8(req.path_info):
res = HTTPPreconditionFailed(body='Invalid UTF8')
else:
@@ -404,7 +404,7 @@ class ContainerController(object):
time.gmtime()),
req.method, req.path,
res.status.split()[0], res.content_length or '-',
get_txn_id(req, '-'),
req.headers.get('x-cf-trans-id', '-'),
req.referer or '-', req.user_agent or '-',
trans_time)
if req.method.upper() == 'REPLICATE':

View File

@@ -37,7 +37,7 @@ from eventlet import sleep, Timeout
from swift.common.utils import mkdirs, normalize_timestamp, \
storage_directory, hash_path, renamer, fallocate, \
split_path, drop_buffer_cache, get_logger, write_pickle, get_txn_id
split_path, drop_buffer_cache, get_logger, write_pickle
from swift.common.bufferedhttp import http_connect
from swift.common.constraints import check_object_creation, check_mount, \
check_float, check_utf8
@@ -409,7 +409,7 @@ class ObjectController(object):
'x-content-type': file.metadata['Content-Type'],
'x-timestamp': file.metadata['X-Timestamp'],
'x-etag': file.metadata['ETag'],
'x-swift-txn-id': get_txn_id(request, '-')},
'x-cf-trans-id': request.headers.get('x-cf-trans-id', '-')},
device)
resp = HTTPCreated(request=request, etag=etag)
return resp
@@ -531,7 +531,7 @@ class ObjectController(object):
file.unlinkold(metadata['X-Timestamp'])
self.container_update('DELETE', account, container, obj,
request.headers, {'x-timestamp': metadata['X-Timestamp'],
'x-swift-txn-id': get_txn_id(request, '-')},
'x-cf-trans-id': request.headers.get('x-cf-trans-id', '-')},
device)
resp = response_class(request=request)
return resp
@@ -562,7 +562,7 @@ class ObjectController(object):
"""WSGI Application entry point for the Swift Object Server."""
start_time = time.time()
req = Request(env)
self.logger.txn_id = get_txn_id(req, None)
self.logger.txn_id = req.headers.get('x-cf-trans-id', None)
if not check_utf8(req.path_info):
res = HTTPPreconditionFailed(body='Invalid UTF8')
else:
@@ -583,7 +583,7 @@ class ObjectController(object):
time.gmtime()),
req.method, req.path, res.status.split()[0],
res.content_length or '-', req.referer or '-',
get_txn_id(req, '-'),
req.headers.get('x-cf-trans-id', '-'),
req.user_agent or '-',
trans_time)
if req.method == 'REPLICATE':

View File

@@ -41,7 +41,7 @@ from webob import Request, Response
from swift.common.ring import Ring
from swift.common.utils import get_logger, normalize_timestamp, split_path, \
cache_from_env, get_txn_id
cache_from_env
from swift.common.bufferedhttp import http_connect
from swift.common.constraints import check_metadata, check_object_creation, \
check_utf8, CONTAINER_LISTING_LIMIT, MAX_ACCOUNT_NAME_LENGTH, \
@@ -356,7 +356,7 @@ class Controller(object):
result_code = 0
attempts_left = self.app.account_ring.replica_count
path = '/%s' % account
headers = {'x-swift-txn-id': self.trans_id}
headers = {'x-cf-trans-id': self.trans_id}
for node in self.iter_nodes(partition, nodes, self.app.account_ring):
if self.error_limited(node):
continue
@@ -430,7 +430,7 @@ class Controller(object):
write_acl = None
container_size = None
attempts_left = self.app.container_ring.replica_count
headers = {'x-swift-txn-id': self.trans_id}
headers = {'x-cf-trans-id': self.trans_id}
for node in self.iter_nodes(partition, nodes, self.app.container_ring):
if self.error_limited(node):
continue
@@ -1247,7 +1247,7 @@ class ContainerController(Controller):
container_partition, containers = self.app.container_ring.get_nodes(
self.account_name, self.container_name)
headers = {'X-Timestamp': normalize_timestamp(time.time()),
'x-swift-txn-id': self.trans_id}
'x-cf-trans-id': self.trans_id}
headers.update(value for value in req.headers.iteritems()
if value[0].lower() in self.pass_through_headers or
value[0].lower().startswith('x-container-meta-'))
@@ -1309,7 +1309,7 @@ class ContainerController(Controller):
container_partition, containers = self.app.container_ring.get_nodes(
self.account_name, self.container_name)
headers = {'X-Timestamp': normalize_timestamp(time.time()),
'x-swift-txn-id': self.trans_id}
'x-cf-trans-id': self.trans_id}
headers.update(value for value in req.headers.iteritems()
if value[0].lower() in self.pass_through_headers or
value[0].lower().startswith('x-container-meta-'))
@@ -1362,7 +1362,7 @@ class ContainerController(Controller):
container_partition, containers = self.app.container_ring.get_nodes(
self.account_name, self.container_name)
headers = {'X-Timestamp': normalize_timestamp(time.time()),
'x-swift-txn-id': self.trans_id}
'x-cf-trans-id': self.trans_id}
statuses = []
reasons = []
bodies = []
@@ -1450,7 +1450,7 @@ class AccountController(Controller):
account_partition, accounts = \
self.app.account_ring.get_nodes(self.account_name)
headers = {'X-Timestamp': normalize_timestamp(time.time()),
'x-swift-txn-id': self.trans_id}
'x-cf-trans-id': self.trans_id}
headers.update(value for value in req.headers.iteritems()
if value[0].lower().startswith('x-account-meta-'))
statuses = []
@@ -1499,7 +1499,7 @@ class AccountController(Controller):
account_partition, accounts = \
self.app.account_ring.get_nodes(self.account_name)
headers = {'X-Timestamp': normalize_timestamp(time.time()),
'x-swift-txn-id': self.trans_id}
'X-CF-Trans-Id': self.trans_id}
headers.update(value for value in req.headers.iteritems()
if value[0].lower().startswith('x-account-meta-'))
statuses = []
@@ -1546,7 +1546,7 @@ class AccountController(Controller):
account_partition, accounts = \
self.app.account_ring.get_nodes(self.account_name)
headers = {'X-Timestamp': normalize_timestamp(time.time()),
'x-swift-txn-id': self.trans_id}
'X-CF-Trans-Id': self.trans_id}
statuses = []
reasons = []
bodies = []
@@ -1683,7 +1683,7 @@ class BaseApplication(object):
def update_request(self, req):
req.bytes_transferred = '-'
req.client_disconnect = False
req.headers['x-swift-txn-id'] = 'tx' + str(uuid.uuid4())
req.headers['x-cf-trans-id'] = 'tx' + str(uuid.uuid4())
if 'x-storage-token' in req.headers and \
'x-auth-token' not in req.headers:
req.headers['x-auth-token'] = req.headers['x-storage-token']
@@ -1707,9 +1707,8 @@ class BaseApplication(object):
return HTTPPreconditionFailed(request=req, body='Bad URL')
controller = controller(self, **path_parts)
txn_id = get_txn_id(req, None)
controller.trans_id = txn_id or '-'
self.logger.txn_id = txn_id
controller.trans_id = req.headers.get('x-cf-trans-id', '-')
self.logger.txn_id = req.headers.get('x-cf-trans-id', None)
try:
handler = getattr(controller, req.method)
if not getattr(handler, 'publicly_accessible'):
@@ -1787,7 +1786,7 @@ class Application(BaseApplication):
getattr(req, 'bytes_transferred', 0) or '-',
getattr(response, 'bytes_transferred', 0) or '-',
req.headers.get('etag', '-'),
get_txn_id(req, '-'),
req.headers.get('x-cf-trans-id', '-'),
logged_headers or '-',
trans_time,
)))

View File

@@ -28,7 +28,6 @@ from StringIO import StringIO
from functools import partial
from tempfile import NamedTemporaryFile
from webob import Request
from eventlet import sleep
from swift.common import utils
@@ -81,19 +80,6 @@ class TestUtils(unittest.TestCase):
def setUp(self):
utils.HASH_PATH_SUFFIX = 'endcap'
def test_get_txn_id(self):
req = Request.blank('')
req.headers['X-Swift-Txn-Id'] = 'tx12345'
self.assertEquals(utils.get_txn_id(req), 'tx12345')
environ = {'HTTP_X_CF_TRANS_ID': 'tx67890'}
req = Request.blank('', environ=environ)
self.assertEquals(utils.get_txn_id(req), 'tx67890')
req = Request.blank('')
self.assertEquals(utils.get_txn_id(req), None)
self.assertEquals(utils.get_txn_id(req, '-'), '-')
req.headers['X-Cf-Trans-Id'] = 'tx13579'
self.assertEquals(utils.get_txn_id(req, default='test'), 'tx13579')
def test_normalize_timestamp(self):
""" Test swift.common.utils.normalize_timestamp """
self.assertEquals(utils.normalize_timestamp('1253327593.48174'),

View File

@@ -218,7 +218,6 @@ def save_globals():
# tests
class TestController(unittest.TestCase):
def setUp(self):
@@ -373,7 +372,6 @@ class TestController(unittest.TestCase):
test(404, 507, 503)
test(503, 503, 503)
class TestProxyServer(unittest.TestCase):
def test_unhandled_exception(self):
@@ -470,7 +468,6 @@ class TestObjectController(unittest.TestCase):
'text/html', 'text/html']))
test_content_type('test.css', iter(['', '', '', 'text/css',
'text/css', 'text/css']))
def test_custom_mime_types_files(self):
swift_dir = mkdtemp()
try:
@@ -1718,7 +1715,7 @@ class TestObjectController(unittest.TestCase):
for node in nodes:
conn = proxy_server.http_connect(node['ip'], node['port'],
node['device'], partition, 'PUT', '/a',
{'X-Timestamp': ts, 'x-swift-txn-id': 'test'})
{'X-Timestamp': ts, 'X-CF-Trans-Id': 'test'})
resp = conn.getresponse()
self.assertEquals(resp.status, 201)
# Head account, just a double check and really is here to test