[ovs-dev] [PATCH v2 8/9] ovsdb: Make clients aware of relay service model.

Ilya Maximets i.maximets at ovn.org
Sat Jun 12 02:00:07 UTC 2021


Clients needs to re-connect from the relay that has no connection
with the database source.  Also, relay acts similarly to the follower
from a clustered model from the consistency point of view, so it's not
suitable for leader-only connections.

Signed-off-by: Ilya Maximets <i.maximets at ovn.org>
---
 lib/ovsdb-cs.c       | 15 ++++++++++++++-
 ovsdb/ovsdb-client.c |  2 +-
 python/ovs/db/idl.py | 16 ++++++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/lib/ovsdb-cs.c b/lib/ovsdb-cs.c
index 911b71dd4..fb3fdd006 100644
--- a/lib/ovsdb-cs.c
+++ b/lib/ovsdb-cs.c
@@ -1897,8 +1897,8 @@ ovsdb_cs_check_server_db__(struct ovsdb_cs *cs)
     bool ok = false;
     const char *model = server_column_get_string(db_row, COL_MODEL, "");
     const char *schema = server_column_get_string(db_row, COL_SCHEMA, NULL);
+    bool connected = server_column_get_bool(db_row, COL_CONNECTED, false);
     if (!strcmp(model, "clustered")) {
-        bool connected = server_column_get_bool(db_row, COL_CONNECTED, false);
         bool leader = server_column_get_bool(db_row, COL_LEADER, false);
         uint64_t index = server_column_get_int(db_row, COL_INDEX, 0);
 
@@ -1918,6 +1918,19 @@ ovsdb_cs_check_server_db__(struct ovsdb_cs *cs)
             cs->min_index = index;
             ok = true;
         }
+    } else if (!strcmp(model, "relay")) {
+        if (!schema) {
+            VLOG_INFO("%s: relay database server has not yet connected to the "
+                      "relay source; trying another server", server_name);
+        } else if (!connected) {
+            VLOG_INFO("%s: relay database server is disconnected from the "
+                      "relay source; trying another server", server_name);
+        } else if (cs->leader_only) {
+            VLOG_INFO("%s: relay database server cannot be a leader; "
+                      "trying another server", server_name);
+        } else {
+            ok = true;
+        }
     } else {
         if (!schema) {
             VLOG_INFO("%s: missing database schema", server_name);
diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c
index ffa8f8df2..f1b8d6491 100644
--- a/ovsdb/ovsdb-client.c
+++ b/ovsdb/ovsdb-client.c
@@ -716,7 +716,7 @@ should_stay_connected(const char *server, const char *database,
         return false;
     }
 
-    if (strcmp(parse_string_column(row, "model"), "clustered")) {
+    if (!strcmp(parse_string_column(row, "model"), "standalone")) {
         /* Always accept standalone databases. */
         return true;
     }
diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index 889cf3431..94bf13b1c 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -38,6 +38,7 @@ OVSDB_UPDATE = 0
 OVSDB_UPDATE2 = 1
 
 CLUSTERED = "clustered"
+RELAY = "relay"
 
 
 Notice = collections.namedtuple('Notice', ('event', 'row', 'updates'))
@@ -797,6 +798,21 @@ class Idl(object):
                               'trying another server' % session_name)
                     return False
                 self._min_index = database.index[0]
+        elif database.model == RELAY:
+            if not database.schema:
+                vlog.info('%s: relay database server has not yet connected '
+                          'to the relay source; trying another server'
+                          % session_name)
+                return False
+            if not database.connected:
+                vlog.info('%s: relay database server is disconnected '
+                          'from the relay source; trying another server'
+                          % session_name)
+                return False
+            if self.leader_only:
+                vlog.info('%s: relay database server cannot be a leader; '
+                          'trying another server' % session_name)
+                return False
 
         return True
 
-- 
2.26.3



More information about the dev mailing list