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:
parent
7736bac7dc
commit
0320e78c2c
|
@ -30,7 +30,10 @@ class Backend(object):
|
||||||
super(Backend, self).__init__(**kwargs)
|
super(Backend, self).__init__(**kwargs)
|
||||||
self.ovsdb_connection = connection
|
self.ovsdb_connection = connection
|
||||||
if auto_index:
|
if auto_index:
|
||||||
self.autocreate_indices()
|
if connection.is_running:
|
||||||
|
LOG.debug("Connection already started, not creating indices")
|
||||||
|
else:
|
||||||
|
self.autocreate_indices()
|
||||||
if start:
|
if start:
|
||||||
self.start_connection(connection)
|
self.start_connection(connection)
|
||||||
|
|
||||||
|
@ -75,11 +78,12 @@ class Backend(object):
|
||||||
try:
|
try:
|
||||||
idx = self.idl.tables[table].rows.index_create(index_name)
|
idx = self.idl.tables[table].rows.index_create(index_name)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# index already exists
|
LOG.debug("lookup_table index %s.%s already exists", table,
|
||||||
pass
|
index_name)
|
||||||
else:
|
else:
|
||||||
idx.add_column(col)
|
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)
|
tables.remove(table)
|
||||||
|
|
||||||
# Simple ovsdb-schema indices
|
# Simple ovsdb-schema indices
|
||||||
|
@ -93,10 +97,11 @@ class Backend(object):
|
||||||
try:
|
try:
|
||||||
idx = table.rows.index_create(index_name)
|
idx = table.rows.index_create(index_name)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass # index already exists
|
LOG.debug("schema index %s.%s already exists", table,
|
||||||
|
index_name)
|
||||||
else:
|
else:
|
||||||
idx.add_column(col)
|
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)
|
tables.remove(table.name)
|
||||||
|
|
||||||
def start_connection(self, connection):
|
def start_connection(self, connection):
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Connection(object):
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.idl = idl
|
self.idl = idl
|
||||||
self.thread = None
|
self.thread = None
|
||||||
self._is_running = None
|
self.is_running = None
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start the connection."""
|
"""Start the connection."""
|
||||||
|
@ -83,14 +83,14 @@ class Connection(object):
|
||||||
# An ovs.db.Idl class has no post_connect
|
# An ovs.db.Idl class has no post_connect
|
||||||
pass
|
pass
|
||||||
self.poller = poller.Poller()
|
self.poller = poller.Poller()
|
||||||
self._is_running = True
|
self.is_running = True
|
||||||
self.thread = threading.Thread(target=self.run)
|
self.thread = threading.Thread(target=self.run)
|
||||||
self.thread.setDaemon(True)
|
self.thread.setDaemon(True)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
errors = 0
|
errors = 0
|
||||||
while self._is_running:
|
while self.is_running:
|
||||||
# If we fail in an Idl call, we could have missed an update
|
# If we fail in an Idl call, we could have missed an update
|
||||||
# from the server, leaving us out of sync with ovsdb-server.
|
# from the server, leaving us out of sync with ovsdb-server.
|
||||||
# It is not safe to continue without restarting the connection,
|
# It is not safe to continue without restarting the connection,
|
||||||
|
@ -113,7 +113,7 @@ class Connection(object):
|
||||||
self.idl.force_reconnect()
|
self.idl.force_reconnect()
|
||||||
idlutils.wait_for_change(self.idl, self.timeout)
|
idlutils.wait_for_change(self.idl, self.timeout)
|
||||||
continue
|
continue
|
||||||
self._is_running = False
|
self.is_running = False
|
||||||
break
|
break
|
||||||
errors = 0
|
errors = 0
|
||||||
txn = self.txns.get_nowait()
|
txn = self.txns.get_nowait()
|
||||||
|
@ -127,9 +127,9 @@ class Connection(object):
|
||||||
self.txns.task_done()
|
self.txns.task_done()
|
||||||
|
|
||||||
def stop(self, timeout=None):
|
def stop(self, timeout=None):
|
||||||
if not self._is_running:
|
if not self.is_running:
|
||||||
return True
|
return True
|
||||||
self._is_running = False
|
self.is_running = False
|
||||||
self.txns.put(None)
|
self.txns.put(None)
|
||||||
self.thread.join(timeout)
|
self.thread.join(timeout)
|
||||||
if self.thread.is_alive():
|
if self.thread.is_alive():
|
||||||
|
|
|
@ -127,10 +127,10 @@ class TestOvsdbIdl(base.FunctionalTestCase):
|
||||||
self.assertEqual(result, [False])
|
self.assertEqual(result, [False])
|
||||||
|
|
||||||
def test_connection_disconnect_timeout(self):
|
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
|
connection = self.api.ovsdb_connection
|
||||||
type(connection)._is_running = _is_running_mock
|
type(connection).is_running = is_running_mock
|
||||||
self.addCleanup(delattr, type(connection), '_is_running')
|
self.addCleanup(delattr, type(connection), 'is_running')
|
||||||
self.assertFalse(connection.stop(1))
|
self.assertFalse(connection.stop(1))
|
||||||
|
|
||||||
def test_br_external_id(self):
|
def test_br_external_id(self):
|
||||||
|
|
Loading…
Reference in New Issue