[ovs-dev,06/15] jsonrpc-server: Separate changing read_only status from reconnecting.

Message ID 20180101051640.13043-6-blp@ovn.org
State New
Headers show
Series
  • [ovs-dev,01/15] log: Add async commit support.
Related show

Commit Message

Ben Pfaff Jan. 1, 2018, 5:16 a.m.
The code in jsonrpc-server conflated two different kinds of functionality.
It makes sense for the client to be able to change whether a particular
server is read-only.  It also makes sense for the client to tell a server
to reconnect.  The code in jsonrpc-server only provided a single function
that does both, which is weird.  This commit breaks these apart.

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 ovsdb/jsonrpc-server.c | 19 ++++++++++++++-----
 ovsdb/jsonrpc-server.h |  7 +++++--
 ovsdb/ovsdb-server.c   | 15 +++------------
 3 files changed, 22 insertions(+), 19 deletions(-)

Comments

Justin Pettit Jan. 13, 2018, 2:36 a.m. | #1
> On Dec 31, 2017, at 9:16 PM, Ben Pfaff <blp@ovn.org> wrote:

> diff --git a/ovsdb/jsonrpc-server.h b/ovsdb/jsonrpc-server.h
> index 1add3276d3b6..a3acc75f8d4f 100644
> --- a/ovsdb/jsonrpc-server.h
> +++ b/ovsdb/jsonrpc-server.h
> @@ -64,11 +64,14 @@ bool ovsdb_jsonrpc_server_get_remote_status(
> 
> void ovsdb_jsonrpc_server_run(struct ovsdb_jsonrpc_server *);
> void ovsdb_jsonrpc_server_wait(struct ovsdb_jsonrpc_server *);
> +
> +bool ovsdb_jsonrpc_server_is_read_only(const struct ovsdb_jsonrpc_server *);

I don't think there are any callers to this, I don't think they're introduced later either.

Acked-by: Justin Pettit <jpettit@ovn.org>

--Justin

Patch

diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 05e0d73ae0be..27586cddd8b3 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -165,7 +165,7 @@  ovsdb_jsonrpc_server_add_db(struct ovsdb_jsonrpc_server *svr, struct ovsdb *db)
      * If this is too big of a hammer in practice, we could be more selective,
      * e.g. disconnect only connections that actually tried to use a database
      * with 'db''s name. */
-    ovsdb_jsonrpc_server_reconnect(svr, svr->read_only);
+    ovsdb_jsonrpc_server_reconnect(svr);
 
     return ovsdb_server_add_db(&svr->up, db);
 }
@@ -182,7 +182,7 @@  ovsdb_jsonrpc_server_remove_db(struct ovsdb_jsonrpc_server *svr,
      *
      * If this is too big of a hammer in practice, we could be more selective,
      * e.g. disconnect only connections that actually reference 'db'. */
-    ovsdb_jsonrpc_server_reconnect(svr, svr->read_only);
+    ovsdb_jsonrpc_server_reconnect(svr);
 
     return ovsdb_server_remove_db(&svr->up, db);
 }
@@ -336,11 +336,10 @@  ovsdb_jsonrpc_server_free_remote_status(
 /* Forces all of the JSON-RPC sessions managed by 'svr' to disconnect and
  * reconnect. */
 void
-ovsdb_jsonrpc_server_reconnect(struct ovsdb_jsonrpc_server *svr, bool read_only)
+ovsdb_jsonrpc_server_reconnect(struct ovsdb_jsonrpc_server *svr)
 {
     struct shash_node *node;
 
-    svr->read_only = read_only;
     SHASH_FOR_EACH (node, &svr->remotes) {
         struct ovsdb_jsonrpc_remote *remote = node->data;
 
@@ -349,12 +348,22 @@  ovsdb_jsonrpc_server_reconnect(struct ovsdb_jsonrpc_server *svr, bool read_only)
 }
 
 bool
-ovsdb_jsonrpc_server_is_read_only(struct ovsdb_jsonrpc_server *svr)
+ovsdb_jsonrpc_server_is_read_only(const struct ovsdb_jsonrpc_server *svr)
 {
     return svr->read_only;
 }
 
 void
+ovsdb_jsonrpc_server_set_read_only(struct ovsdb_jsonrpc_server *svr,
+                                   bool read_only)
+{
+    if (svr->read_only != read_only) {
+        svr->read_only = read_only;
+        ovsdb_jsonrpc_server_reconnect(svr);
+    }
+}
+
+void
 ovsdb_jsonrpc_server_run(struct ovsdb_jsonrpc_server *svr)
 {
     struct shash_node *node;
diff --git a/ovsdb/jsonrpc-server.h b/ovsdb/jsonrpc-server.h
index 1add3276d3b6..a3acc75f8d4f 100644
--- a/ovsdb/jsonrpc-server.h
+++ b/ovsdb/jsonrpc-server.h
@@ -64,11 +64,14 @@  bool ovsdb_jsonrpc_server_get_remote_status(
 void ovsdb_jsonrpc_server_free_remote_status(
     struct ovsdb_jsonrpc_remote_status *);
 
-void ovsdb_jsonrpc_server_reconnect(struct ovsdb_jsonrpc_server *, bool read_only);
+void ovsdb_jsonrpc_server_reconnect(struct ovsdb_jsonrpc_server *);
 
 void ovsdb_jsonrpc_server_run(struct ovsdb_jsonrpc_server *);
 void ovsdb_jsonrpc_server_wait(struct ovsdb_jsonrpc_server *);
-bool ovsdb_jsonrpc_server_is_read_only(struct ovsdb_jsonrpc_server *);
+
+bool ovsdb_jsonrpc_server_is_read_only(const struct ovsdb_jsonrpc_server *);
+void ovsdb_jsonrpc_server_set_read_only(struct ovsdb_jsonrpc_server *,
+                                        bool read_only);
 
 void ovsdb_jsonrpc_server_get_memory_usage(const struct ovsdb_jsonrpc_server *,
                                            struct simap *usage);
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 7f2d19ef568b..1efb5552da5a 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -156,7 +156,6 @@  main_loop(struct ovsdb_jsonrpc_server *jsonrpc, struct shash *all_dbs,
     char *remotes_error, *ssl_error;
     struct shash_node *node;
     long long int status_timer = LLONG_MIN;
-    bool last_role = *is_backup;
 
     *exiting = false;
     ssl_error = NULL;
@@ -182,12 +181,7 @@  main_loop(struct ovsdb_jsonrpc_server *jsonrpc, struct shash *all_dbs,
          * the set of remotes that reconfigure_remotes() uses. */
         unixctl_server_run(unixctl);
 
-        /* In ovsdb-server's role (active or backup) has changed, restart
-         * the ovsdb jsonrpc server.  */
-        if (last_role != *is_backup) {
-            bool read_only = last_role = *is_backup;
-            ovsdb_jsonrpc_server_reconnect(jsonrpc, read_only);
-        }
+        ovsdb_jsonrpc_server_set_read_only(jsonrpc, *is_backup);
 
         report_error_if_changed(
             reconfigure_remotes(jsonrpc, all_dbs, remotes),
@@ -1125,10 +1119,9 @@  ovsdb_server_disable_monitor_cond(struct unixctl_conn *conn,
                                   void *jsonrpc_)
 {
     struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_;
-    bool read_only = ovsdb_jsonrpc_server_is_read_only(jsonrpc);
 
     ovsdb_jsonrpc_disable_monitor_cond();
-    ovsdb_jsonrpc_server_reconnect(jsonrpc, read_only);
+    ovsdb_jsonrpc_server_reconnect(jsonrpc);
     unixctl_command_reply(conn, NULL);
 }
 
@@ -1186,9 +1179,7 @@  ovsdb_server_reconnect(struct unixctl_conn *conn, int argc OVS_UNUSED,
                        const char *argv[] OVS_UNUSED, void *jsonrpc_)
 {
     struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_;
-    bool read_only = ovsdb_jsonrpc_server_is_read_only(jsonrpc);
-
-    ovsdb_jsonrpc_server_reconnect(jsonrpc, read_only);
+    ovsdb_jsonrpc_server_reconnect(jsonrpc);
     unixctl_command_reply(conn, NULL);
 }