Commit bced2e7b authored by Julien Muchembled's avatar Julien Muchembled

storage: revert "remake _getPartition lazy, similarly to fallback decorator"

_getPartition optimization can't be done at class level and properties hide
instance attribute so implement laziness in __getattr__
parent ea5cdd0b
......@@ -30,8 +30,6 @@ def lazymethod(func):
def fallback(func):
def warn(self):
cls = self.__class__
name = func.__name__
logging.info("Fallback to generic/slow implementation of %s."
" It should be overridden by backend storage (%s).",
func.__name__, self.__class__.__name__)
......@@ -51,6 +49,15 @@ class DatabaseManager(object):
self._wait = wait
self._parse(database)
def __getattr__(self, attr):
if attr == "_getPartition":
np = self.getNumPartitions()
value = lambda x: x % np
else:
return self.__getattribute__(attr)
setattr(self, attr, value)
return value
def _parse(self, database):
"""Called during instanciation, to process database parameter."""
pass
......@@ -77,11 +84,6 @@ class DatabaseManager(object):
def commit(self):
pass
@lazymethod
def _getPartition(self):
np = self.getNumPartitions()
return staticmethod(lambda x: x % np)
def getConfiguration(self, key):
"""
Return a configuration value, returns None if not found or not set
......@@ -125,10 +127,8 @@ class DatabaseManager(object):
Store the number of partitions into a database.
"""
self.setConfiguration('partitions', num_partitions)
cls = self.__class__
assert cls is not DatabaseManager
try:
del cls._getPartition
del self._getPartition
except AttributeError:
pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment