From 97947b21a1eecc8e648c374cad7eace50f22ce04 Mon Sep 17 00:00:00 2001 From: duncan Date: Thu, 20 Jan 2022 15:03:00 +0000 Subject: [PATCH] VersionStore use named index (#941) --- arctic/store/version_store.py | 5 ++++- tests/integration/test_arctic.py | 2 +- tests/unit/store/test_version_store.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arctic/store/version_store.py b/arctic/store/version_store.py index 9dee1469..64fc19b6 100644 --- a/arctic/store/version_store.py +++ b/arctic/store/version_store.py @@ -70,6 +70,7 @@ def _last_version_seqnum(self, symbol): last_seq = self._version_nums.find_one({'symbol': symbol}) return last_seq['version'] if last_seq else 0 + # new index named because of 127 char restriction on fully qualified index names @mongo_retry def _ensure_index(self): collection = self._collection @@ -79,7 +80,9 @@ def _ensure_index(self): background=True) collection.versions.create_index([('symbol', pymongo.ASCENDING), ('version', pymongo.DESCENDING)], unique=True, background=True) - collection.versions.create_index([('symbol', pymongo.ASCENDING), ('version', pymongo.DESCENDING), ('metadata.deleted', pymongo.ASCENDING)], + collection.versions.create_index([('symbol', pymongo.ASCENDING), ('version', pymongo.DESCENDING), + ('metadata.deleted', pymongo.ASCENDING)], + name='versionstore_idx', background=True) collection.version_nums.create_index('symbol', unique=True, background=True) for th in _TYPE_HANDLERS: diff --git a/tests/integration/test_arctic.py b/tests/integration/test_arctic.py index 05c02b01..11987a16 100644 --- a/tests/integration/test_arctic.py +++ b/tests/integration/test_arctic.py @@ -122,7 +122,7 @@ def test_indexes(arctic): u'ns': u'arctic.library.versions', u'unique': True, u'v': index_version}, - u'symbol_1_version_-1_metadata.deleted_1': {u'background': True, + u'versionstore_idx': {u'background': True, u'key': [(u'symbol', 1), (u'version', -1), (u'metadata.deleted', 1)], u'ns': u'arctic.library.versions', u'v': index_version}} diff --git a/tests/unit/store/test_version_store.py b/tests/unit/store/test_version_store.py index 9d2f34fb..75092e9e 100644 --- a/tests/unit/store/test_version_store.py +++ b/tests/unit/store/test_version_store.py @@ -187,7 +187,7 @@ def test_ensure_index(): assert vs._collection.versions.create_index.call_args_list == [ call([('symbol', 1), ('_id', -1)], background=True), call([('symbol', 1), ('version', -1)], unique=True, background=True), - call([('symbol', 1), ('version', -1), ('metadata.deleted', 1)], background=True), + call([('symbol', 1), ('version', -1), ('metadata.deleted', 1)], background=True, name='versionstore_idx'), ] assert vs._collection.version_nums.create_index.call_args_list == [call('symbol', unique=True, background=True)] th._ensure_index.assert_called_once_with(vs._collection)