Only create indices if connection is not running

Also adds some better debug logs when creating indexes

Related-Bug: #1881424
Change-Id: I094dd475bb6956a3c029075ad85dbc15cf59a16c
This commit is contained in:
Terry Wilson 2020-05-31 21:19:06 -05:00
parent 7736bac7dc
commit 0320e78c2c
3 changed files with 20 additions and 15 deletions

View File

@ -30,7 +30,10 @@ class Backend(object):
super(Backend, self).__init__(**kwargs)
self.ovsdb_connection = connection
if auto_index:
self.autocreate_indices()
if connection.is_running:
LOG.debug("Connection already started, not creating indices")
else:
self.autocreate_indices()
if start:
self.start_connection(connection)
@ -75,11 +78,12 @@ class Backend(object):
try:
idx = self.idl.tables[table].rows.index_create(index_name)
except ValueError:
# index already exists
pass
LOG.debug("lookup_table index %s.%s already exists", table,
index_name)
else:
idx.add_column(col)
LOG.debug("Created index %s", index_name)
LOG.debug("Created lookup_table index %s.%s", table,
index_name)
tables.remove(table)
# Simple ovsdb-schema indices
@ -93,10 +97,11 @@ class Backend(object):
try:
idx = table.rows.index_create(index_name)
except ValueError:
pass # index already exists
LOG.debug("schema index %s.%s already exists", table,
index_name)
else:
idx.add_column(col)
LOG.debug("Created index %s", index_name)
LOG.debug("Created schema index %s.%s", table.name, index_name)
tables.remove(table.name)
def start_connection(self, connection):

View File

@ -68,7 +68,7 @@ class Connection(object):
self.lock = threading.Lock()
self.idl = idl
self.thread = None
self._is_running = None
self.is_running = None
def start(self):
"""Start the connection."""
@ -83,14 +83,14 @@ class Connection(object):
# An ovs.db.Idl class has no post_connect
pass
self.poller = poller.Poller()
self._is_running = True
self.is_running = True
self.thread = threading.Thread(target=self.run)
self.thread.setDaemon(True)
self.thread.start()
def run(self):
errors = 0
while self._is_running:
while self.is_running:
# If we fail in an Idl call, we could have missed an update
# from the server, leaving us out of sync with ovsdb-server.
# It is not safe to continue without restarting the connection,
@ -113,7 +113,7 @@ class Connection(object):
self.idl.force_reconnect()
idlutils.wait_for_change(self.idl, self.timeout)
continue
self._is_running = False
self.is_running = False
break
errors = 0
txn = self.txns.get_nowait()
@ -127,9 +127,9 @@ class Connection(object):
self.txns.task_done()
def stop(self, timeout=None):
if not self._is_running:
if not self.is_running:
return True
self._is_running = False
self.is_running = False
self.txns.put(None)
self.thread.join(timeout)
if self.thread.is_alive():

View File

@ -127,10 +127,10 @@ class TestOvsdbIdl(base.FunctionalTestCase):
self.assertEqual(result, [False])
def test_connection_disconnect_timeout(self):
_is_running_mock = mock.PropertyMock(return_value=True)
is_running_mock = mock.PropertyMock(return_value=True)
connection = self.api.ovsdb_connection
type(connection)._is_running = _is_running_mock
self.addCleanup(delattr, type(connection), '_is_running')
type(connection).is_running = is_running_mock
self.addCleanup(delattr, type(connection), 'is_running')
self.assertFalse(connection.stop(1))
def test_br_external_id(self):