Commit fe698b38 authored by Michael Hanselmann's avatar Michael Hanselmann

config: Wrap MatchNameComponent, reduce lock duration

- Remove duplication by merging two MatchNameComponent into a wrapper
- Reduce lock duration by getting list of names under lock and then
  matching names without the lock
- Also, ExpandNodeName's docstring is fixed.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 8e7078e0
...@@ -125,6 +125,13 @@ class TemporaryReservationManager: ...@@ -125,6 +125,13 @@ class TemporaryReservationManager:
return new_resource return new_resource
def _MatchNameComponentIgnoreCase(short_name, names):
"""Wrapper around L{utils.MatchNameComponent}.
"""
return utils.MatchNameComponent(short_name, names, case_sensitive=False)
class ConfigWriter: class ConfigWriter:
"""The interface to the cluster configuration. """The interface to the cluster configuration.
...@@ -1201,14 +1208,12 @@ class ConfigWriter: ...@@ -1201,14 +1208,12 @@ class ConfigWriter:
""" """
return self._UnlockedGetInstanceList() return self._UnlockedGetInstanceList()
@locking.ssynchronized(_config_lock, shared=1)
def ExpandInstanceName(self, short_name): def ExpandInstanceName(self, short_name):
"""Attempt to expand an incomplete instance name. """Attempt to expand an incomplete instance name.
""" """
return utils.MatchNameComponent(short_name, # Locking is done in L{ConfigWriter.GetInstanceList}
self._config_data.instances.keys(), return _MatchNameComponentIgnoreCase(short_name, self.GetInstanceList())
case_sensitive=False)
def _UnlockedGetInstanceInfo(self, instance_name): def _UnlockedGetInstanceInfo(self, instance_name):
"""Returns information about an instance. """Returns information about an instance.
...@@ -1284,14 +1289,12 @@ class ConfigWriter: ...@@ -1284,14 +1289,12 @@ class ConfigWriter:
self._config_data.cluster.serial_no += 1 self._config_data.cluster.serial_no += 1
self._WriteConfig() self._WriteConfig()
@locking.ssynchronized(_config_lock, shared=1)
def ExpandNodeName(self, short_name): def ExpandNodeName(self, short_name):
"""Attempt to expand an incomplete instance name. """Attempt to expand an incomplete node name.
""" """
return utils.MatchNameComponent(short_name, # Locking is done in L{ConfigWriter.GetNodeList}
self._config_data.nodes.keys(), return _MatchNameComponentIgnoreCase(short_name, self.GetNodeList())
case_sensitive=False)
def _UnlockedGetNodeInfo(self, node_name): def _UnlockedGetNodeInfo(self, node_name):
"""Get the configuration of a node, as stored in the config. """Get the configuration of a node, as stored in the config.
......
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