diff mbox series

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

Message ID 20210612020008.3944088-9-i.maximets@ovn.org
State Superseded
Headers show
Series OVSDB Relay Service Model. (Was: OVSDB 2-Tier deployment) | expand

Commit Message

Ilya Maximets June 12, 2021, 2 a.m. UTC
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@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(-)

Comments

Dumitru Ceara June 25, 2021, 1:34 p.m. UTC | #1
On 6/12/21 4:00 AM, Ilya Maximets wrote:
> 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@ovn.org>
> ---

Acked-by: Dumitru Ceara <dceara@redhat.com>

Thanks!
Mark Gray July 2, 2021, 10:51 a.m. UTC | #2
On 12/06/2021 03:00, Ilya Maximets wrote:
> 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@ovn.org>
> ---

Acked-by: Mark D. Gray <mark.d.gray@redhat.com>
diff mbox series

Patch

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