summaryrefslogtreecommitdiffstats
path: root/test/unit/common/test_diskdir.py
diff options
context:
space:
mode:
authorPrashanth Pai <ppai@redhat.com>2016-02-23 14:58:06 +0530
committerThiago da Silva <thiago@redhat.com>2016-04-04 09:24:42 -0700
commitc73037e90c3f551caf18df41efd7fa9750454a10 (patch)
tree4d9120b70d2e83d7240130522893986aaf9c0118 /test/unit/common/test_diskdir.py
parent539d20e3b13096cfa9107fc2b619943c494c4ab3 (diff)
Don't fetch metadata for plain container listing
Fetch metadata (xattr) for containers in an account ONLY when the client asks for it (using content-type indicating JSON or XML response). This avoids a lot of unnecessarry stat() and getxattr() calls whose results would anyways be unused. The performance gain is obvious in this case. This change is restricted to container listing. The same can be extended to object listing as well (will be sent as a separate change) Change-Id: Ibff1c5a90519f11053c0b651d8ea3385dda43a2f Signed-off-by: Prashanth Pai <ppai@redhat.com> Reviewed-on: http://review.gluster.org/13497 Reviewed-by: Thiago da Silva <thiago@redhat.com> Tested-by: Thiago da Silva <thiago@redhat.com>
Diffstat (limited to 'test/unit/common/test_diskdir.py')
-rw-r--r--test/unit/common/test_diskdir.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/unit/common/test_diskdir.py b/test/unit/common/test_diskdir.py
index 3b95de8..0ad607b 100644
--- a/test/unit/common/test_diskdir.py
+++ b/test/unit/common/test_diskdir.py
@@ -22,6 +22,7 @@ import unittest
import shutil
import tarfile
import hashlib
+from mock import Mock, patch
from time import time
from swift.common.utils import normalize_timestamp
from gluster.swift.common import utils
@@ -1179,6 +1180,48 @@ class TestAccountBroker(unittest.TestCase):
self.assertEquals([row[0] for row in listing],
['3-0049-', '3-0049-0049'])
+ def test_list_containers_iter_plain_listing(self):
+ broker = self._get_broker(account='a')
+ broker.initialize(self.initial_ts)
+ for cont in xrange(10):
+ # Create 10 containers - lci0 to lci9
+ self._create_container('lci%d' % cont)
+
+ # Check and assert that only name is fetched.
+ listing = broker.list_containers_iter(100, '', None, None,
+ '', 'text/plain')
+ self.assertEquals(len(listing), 10)
+ for i, (name, o_count, bytes_used, j) in enumerate(listing):
+ self.assertEqual(name, 'lci%d' % i)
+ self.assertEqual(o_count, 0)
+ self.assertEqual(bytes_used, 0)
+ self.assertEqual(j, 0)
+
+ # Check that limit is still honored.
+ listing = broker.list_containers_iter(5, '', None, None,
+ '', 'text/plain')
+ self.assertEquals(len(listing), 5)
+
+ # Confirm that metadata of containers (xattrs) are not fetched when
+ # response_content_type is text/plain
+ _m_r_md = Mock(return_value={})
+ with patch('gluster.swift.common.DiskDir._read_metadata', _m_r_md):
+ listing = broker.list_containers_iter(100, '', None, None,
+ '', 'text/plain')
+ self.assertEquals(len(listing), 10)
+ self.assertFalse(_m_r_md.called)
+
+ # Confirm that metadata of containers (xattrs) are still fetched when
+ # response_content_type is NOT text/plain
+ _m_r_md.reset_mock()
+ with patch('gluster.swift.common.DiskDir._read_metadata', _m_r_md):
+ listing = broker.list_containers_iter(100, '', None, None,
+ '', 'application/json')
+ self.assertEquals(len(listing), 10)
+ self.assertTrue(_m_r_md.called)
+ self.assertEqual(_m_r_md.call_count, 10)
+
+
def test_double_check_trailing_delimiter(self):
# Test swift.common.db.AccountBroker.list_containers_iter for an
# account that has an odd container with a trailing delimiter