2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-01 14:55:18 +00:00

ovsdb-idl: Change interface to conditional monitoring.

Most users of OVSDB react to whatever is currently in their view of the
database, as opposed to keeping track of changes and reacting to those
changes individually.  The interface to conditional monitoring was
different, in that it expected the client to say what to add or remove from
monitoring instead of what to monitor.  This seemed reasonable at the time,
but in practice it turns out that the usual approach actually works better,
because the condition is generally a function of the data visible in the
database.  This commit changes the approach.

This commit also changes the meaning of an empty condition for a table.
Previously, an empty condition meant to replicate every row.  Now, an empty
condition means to replicate no rows.  This is more convenient for code
that gradually constructs conditions, because it does not need special
cases for replicating nothing.

This commit also changes the internal implementation of conditions from
linked lists to arrays.  I just couldn't see an advantage to using linked
lists.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Liran Schour <lirans@il.ibm.com>
This commit is contained in:
Ben Pfaff
2016-12-19 20:55:35 -08:00
parent 3a60b7cd5f
commit 0164e367f5
9 changed files with 309 additions and 501 deletions

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
# Copyright (c) 2009, 2010, 2011, 2012, 2013, 2016 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -144,7 +144,7 @@ class Idl(object):
table.need_table = False
table.rows = {}
table.idl = self
table.condition = []
table.condition = [True]
table.cond_changed = False
def close(self):
@@ -265,23 +265,23 @@ class Idl(object):
self.__send_cond_change(table, table.condition)
table.cond_changed = False
def cond_change(self, table_name, add_cmd, cond):
"""Change conditions for this IDL session. If session is not already
connected, add condtion to table and submit it on send_monitor_request.
Otherwise send monitor_cond_change method with the requested
changes."""
def cond_change(self, table_name, cond):
"""Sets the condition for 'table_name' to 'cond', which should be a
conditional expression suitable for use directly in the OVSDB
protocol, with the exception that the empty condition []
matches no rows (instead of matching every row). That is, []
is equivalent to [False], not to [True].
"""
table = self.tables.get(table_name)
if not table:
raise error.Error('Unknown table "%s"' % table_name)
if add_cmd:
table.condition += cond
else:
for c in cond:
table.condition.remove(c)
table.cond_changed = True
if cond == []:
cond = [False]
if table.condition != cond:
table.condition = cond
table.cond_changed = True
def wait(self, poller):
"""Arranges for poller.block() to wake up when self.run() has something
@@ -420,8 +420,7 @@ class Idl(object):
(column not in self.readonly[table.name])):
columns.append(column)
monitor_requests[table.name] = {"columns": columns}
if method == "monitor_cond" and table.cond_changed and \
table.condition:
if method == "monitor_cond" and table.condition != [True]:
monitor_requests[table.name]["where"] = table.condition
table.cond_change = False