[ARVADOS] updated: befbfe55b13686630fd6f841caaa8345d465fc44
Git user
git at public.curoverse.com
Wed Apr 20 17:28:55 EDT 2016
Summary of changes:
sdk/python/arvados/keep.py | 30 +++++++++++++-----------------
sdk/python/tests/test_keep_client.py | 8 ++++----
2 files changed, 17 insertions(+), 21 deletions(-)
via befbfe55b13686630fd6f841caaa8345d465fc44 (commit)
from 20fc2f783478fb438fb0a6eee193909f899f139b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit befbfe55b13686630fd6f841caaa8345d465fc44
Author: radhika <radhika at curoverse.com>
Date: Wed Apr 20 17:28:31 2016 -0400
8937: bypass cache for all head requests.
diff --git a/sdk/python/arvados/keep.py b/sdk/python/arvados/keep.py
index 4cd7dc3..135d985 100644
--- a/sdk/python/arvados/keep.py
+++ b/sdk/python/arvados/keep.py
@@ -199,20 +199,18 @@ class KeepBlockCache(object):
with self._cache_lock:
return self._get(locator)
- def reserve_cache(self, locator, reserve=True):
+ def reserve_cache(self, locator):
'''Reserve a cache slot for the specified locator,
or return the existing slot.'''
with self._cache_lock:
n = self._get(locator)
if n:
return n, False
- elif reserve == True:
+ else:
# Add a new cache slot for the locator
n = KeepBlockCache.CacheSlot(locator)
self._cache.insert(0, n)
return n, True
- else:
- return None, False
class Counter(object):
def __init__(self, v=0):
@@ -433,11 +431,8 @@ class KeepClient(object):
if method == "HEAD":
_logger.info("HEAD %s: %s bytes",
self._result['status_code'],
- self._headers.get('content-length'))
- content_len = self._headers.get('content-length')
- if content_len is None:
- content_len = self._result['body']
- return str(content_len)
+ self._result.get('content-length'))
+ return str(self._result.get('content-length'))
_logger.info("GET %s: %s bytes in %s msec (%.3f MiB/sec)",
self._result['status_code'],
@@ -919,13 +914,11 @@ class KeepClient(object):
self.get_counter.add(1)
locator = KeepLocator(loc_s)
- slot, first = self.block_cache.reserve_cache(locator.md5sum, True if method == "GET" else False)
- if not first and slot is not None:
- self.hits_counter.add(1)
- v = slot.get()
- if method == "HEAD":
- return str(len(v))
- else:
+ if method == "GET":
+ slot, first = self.block_cache.reserve_cache(locator.md5sum)
+ if not first:
+ self.hits_counter.add(1)
+ v = slot.get()
return v
self.misses_counter.add(1)
@@ -986,7 +979,10 @@ class KeepClient(object):
slot.set(blob)
self.block_cache.cap_cache()
if loop.success():
- return blob
+ if method == "HEAD":
+ return "true"
+ else:
+ return blob
# Q: Including 403 is necessary for the Keep tests to continue
# passing, but maybe they should expect KeepReadError instead?
diff --git a/sdk/python/tests/test_keep_client.py b/sdk/python/tests/test_keep_client.py
index 9e9b76b..fa82dcc 100644
--- a/sdk/python/tests/test_keep_client.py
+++ b/sdk/python/tests/test_keep_client.py
@@ -110,7 +110,7 @@ class KeepTestCase(run_test_server.TestCaseWithServers):
locator,
'^b9a772c7049325feb7130fff1f8333e9\+9',
'wrong md5 hash from Keep.put for "test_head": ' + locator)
- self.assertEqual('9', self.keep_client.head(locator))
+ self.assertEqual("true", self.keep_client.head(locator))
self.assertEqual(self.keep_client.get(locator),
'test_head',
'wrong content from Keep.get for "test_head"')
@@ -827,7 +827,7 @@ class KeepClientGatewayTestCase(unittest.TestCase, tutil.ApiClientMock):
self.assertEqual('foo', self.keepClient.get(locator))
self.assertEqual(self.gateway_roots[0]+locator,
MockCurl.return_value.getopt(pycurl.URL))
- self.assertEqual('3', self.keepClient.head(locator))
+ self.assertEqual("true", self.keepClient.head(locator))
@mock.patch('pycurl.Curl')
def test_get_with_gateway_hints_in_order(self, MockCurl):
@@ -893,7 +893,7 @@ class KeepClientGatewayTestCase(unittest.TestCase, tutil.ApiClientMock):
code=200, body='foo', headers={'Content-Length': 3})
self.mock_disks_and_gateways()
locator = 'acbd18db4cc2f85cedef654fccc4a4d8+3+K at xyzzy'
- self.assertEqual(3, int(self.keepClient.head(locator)))
+ self.assertEqual("true", self.keepClient.head(locator))
self.assertEqual('https://keep.xyzzy.arvadosapi.com/'+locator,
MockCurl.return_value.getopt(pycurl.URL))
@@ -1014,7 +1014,7 @@ class KeepClientRetryGetTestCase(KeepClientRetryTestMixin, unittest.TestCase):
@tutil.skip_sleep
class KeepClientRetryHeadTestCase(KeepClientRetryTestMixin, unittest.TestCase):
- DEFAULT_EXPECT = str(len(KeepClientRetryTestMixin.TEST_DATA))
+ DEFAULT_EXPECT = "true"
DEFAULT_EXCEPTION = arvados.errors.KeepReadError
HINTED_LOCATOR = KeepClientRetryTestMixin.TEST_LOCATOR + '+K at xyzzy'
TEST_PATCHER = staticmethod(tutil.mock_keep_responses)
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list