Skip to content

Commit

Permalink
Merge pull request #898 from man-group/arctic_fixes
Browse files Browse the repository at this point in the history
Handle uninitialized cache object
  • Loading branch information
shashank88 authored Apr 9, 2021
2 parents 6472d8c + 654f4db commit 7a1374c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions arctic/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ def get(self, key, newer_than_secs=None):
if cached_data and self._is_not_expired(cached_data, newer_than_secs):
return cached_data['data']
except OperationFailure as op:
logging.warning("Could not read from cache due to: %s. Ask your admin to give read permissions on %s:%s",
op, CACHE_DB, CACHE_COLL)
# Fallback to uncached version without spamming.
logging.debug("Could not read from cache due to: %s. Ask your admin to give read permissions on %s:%s",
op, CACHE_DB, CACHE_COLL)

return None

Expand Down
4 changes: 3 additions & 1 deletion arctic/arctic.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ def list_libraries(self, newer_than_secs=None):
-------
list of Arctic library names
"""
return self._list_libraries_cached(newer_than_secs) if self.is_caching_enabled() else self._list_libraries()
if self._cache and self.is_caching_enabled():
return self._list_libraries_cached(newer_than_secs)
return self._list_libraries()

@mongo_retry
def _list_libraries(self):
Expand Down
6 changes: 5 additions & 1 deletion arctic/store/_pickle_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def write(self, arctic_lib, version, symbol, item, _previous_version):
collection = arctic_lib.get_top_level_collection()
# Try to pickle it. This is best effort
version['blob'] = _MAGIC_CHUNKEDV2
pickled = cPickle.dumps(item, protocol=cPickle.HIGHEST_PROTOCOL)
# Python 3.8 onwards uses protocol 5 which cannot be unpickled in Python versions below that, so limiting
# it to use a maximum of protocol 4 in Python which is understood by 3.4 onwards and is still fairly efficient.
# The min() allows lower versions to be used in py2 (which supports a max of 2)
pickle_protocol = min(cPickle.HIGHEST_PROTOCOL, 4)
pickled = cPickle.dumps(item, protocol=pickle_protocol)

data = compress_array([pickled[i * _CHUNK_SIZE: (i + 1) * _CHUNK_SIZE] for i in xrange(int(len(pickled) / _CHUNK_SIZE + 1))])

Expand Down

0 comments on commit 7a1374c

Please sign in to comment.