Fixied unique generators for not using "lock tables" (towards full use of galer mariadb cluster)

This commit is contained in:
Adolfo Gómez García 2018-01-31 08:09:04 +01:00
parent a4288b991d
commit bce764f0d3
4 changed files with 9 additions and 6 deletions

View File

@ -40,13 +40,14 @@ logger = logging.getLogger(__name__)
class UniqueGIDGenerator(UniqueIDGenerator):
def __init__(self, owner):
super(UniqueGIDGenerator, self).__init__('id', owner,)
def __init__(self, owner, baseName=None):
super(UniqueGIDGenerator, self).__init__('id', owner, baseName)
def __toName(self, seq):
if seq == -1:
raise KeyError('No more GIDS available.')
return "%s%0*d" % (self._baseName, 8, seq)
return '{:s}{:08d}'.format(self._baseName, seq)
# return "%s%0*d" % (self._baseName, 8, seq)
def get(self, rangeStart=0, rangeEnd=MAX_SEQ):
return self.__toName(super(UniqueGIDGenerator, self).get())

View File

@ -50,9 +50,9 @@ class CreateNewIdException(Exception):
class UniqueIDGenerator(object):
def __init__(self, typeName, owner, baseName='uds'):
def __init__(self, typeName, owner, baseName=None):
self._owner = owner + typeName
self._baseName = baseName
self._baseName = 'uds' if baseName is None else baseName
def setBaseName(self, newBaseName):
self._baseName = newBaseName

View File

@ -48,6 +48,8 @@ class UniqueMacGenerator(UniqueIDGenerator):
return int(mac.replace(':', ''), 16)
def __toMac(self, seq):
if seq == -1: # No mor macs available
return '00:00:00:00:00:00'
return re.sub(r"(..)", r"\1:", "%0*X" % (12, seq))[:-1]
# noinspection PyMethodOverriding

View File

@ -42,7 +42,7 @@ logger = logging.getLogger(__name__)
class UniqueNameGenerator(UniqueIDGenerator):
def __init__(self, owner):
super(UniqueNameGenerator, self).__init__('name', owner,)
super(UniqueNameGenerator, self).__init__('name', owner)
def __toName(self, seq, length):
if seq == -1: