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

View File

@@ -107,16 +107,6 @@ def get_param(req, name, default=None):
value.decode('utf8') # Ensure UTF8ness value.decode('utf8') # Ensure UTF8ness
return value 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): 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.db import ContainerBroker
from swift.common.utils import get_logger, get_param, hash_path, \ 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, \ from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
check_mount, check_float, check_utf8 check_mount, check_float, check_utf8
from swift.common.bufferedhttp import http_connect from swift.common.bufferedhttp import http_connect
@@ -95,7 +95,7 @@ class ContainerController(object):
'x-delete-timestamp': info['delete_timestamp'], 'x-delete-timestamp': info['delete_timestamp'],
'x-object-count': info['object_count'], 'x-object-count': info['object_count'],
'x-bytes-used': info['bytes_used'], '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() == \ if req.headers.get('x-account-override-deleted', 'no').lower() == \
'yes': 'yes':
account_headers['x-account-override-deleted'] = 'yes' account_headers['x-account-override-deleted'] = 'yes'
@@ -384,7 +384,7 @@ class ContainerController(object):
def __call__(self, env, start_response): def __call__(self, env, start_response):
start_time = time.time() start_time = time.time()
req = Request(env) 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): if not check_utf8(req.path_info):
res = HTTPPreconditionFailed(body='Invalid UTF8') res = HTTPPreconditionFailed(body='Invalid UTF8')
else: else:
@@ -404,7 +404,7 @@ class ContainerController(object):
time.gmtime()), time.gmtime()),
req.method, req.path, req.method, req.path,
res.status.split()[0], res.content_length or '-', 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 '-', req.referer or '-', req.user_agent or '-',
trans_time) trans_time)
if req.method.upper() == 'REPLICATE': if req.method.upper() == 'REPLICATE':

View File

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

View File

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

View File

@@ -28,7 +28,6 @@ from StringIO import StringIO
from functools import partial from functools import partial
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from webob import Request
from eventlet import sleep from eventlet import sleep
from swift.common import utils from swift.common import utils
@@ -81,19 +80,6 @@ class TestUtils(unittest.TestCase):
def setUp(self): def setUp(self):
utils.HASH_PATH_SUFFIX = 'endcap' 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): def test_normalize_timestamp(self):
""" Test swift.common.utils.normalize_timestamp """ """ Test swift.common.utils.normalize_timestamp """
self.assertEquals(utils.normalize_timestamp('1253327593.48174'), self.assertEquals(utils.normalize_timestamp('1253327593.48174'),

View File

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