ovsdb-server: Implement unixctl command to reconnect JSON-RPC connections.
authorBen Pfaff <blp@nicira.com>
Thu, 24 Jun 2010 19:56:30 +0000 (12:56 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 24 Jun 2010 19:56:30 +0000 (12:56 -0700)
This feature may be useful for debugging.

Feature #2222.

ovsdb/jsonrpc-server.c
ovsdb/jsonrpc-server.h
ovsdb/ovsdb-server.1.in
ovsdb/ovsdb-server.c

index 84243d58ec4911dc7ad58d77072e04ab5a5c4b2a..18f59c50233458386e087abd4094f42c49388275 100644 (file)
@@ -50,6 +50,7 @@ static struct ovsdb_jsonrpc_session *ovsdb_jsonrpc_session_create(
 static void ovsdb_jsonrpc_session_run_all(struct ovsdb_jsonrpc_remote *);
 static void ovsdb_jsonrpc_session_wait_all(struct ovsdb_jsonrpc_remote *);
 static void ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *);
+static void ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *);
 
 /* Triggers. */
 static void ovsdb_jsonrpc_trigger_create(struct ovsdb_jsonrpc_session *,
@@ -172,6 +173,20 @@ ovsdb_jsonrpc_server_del_remote(struct shash_node *node)
     free(remote);
 }
 
+/* Forces all of the JSON-RPC sessions managed by 'svr' to disconnect and
+ * reconnect. */
+void
+ovsdb_jsonrpc_server_reconnect(struct ovsdb_jsonrpc_server *svr)
+{
+    struct shash_node *node;
+
+    SHASH_FOR_EACH (node, &svr->remotes) {
+        struct ovsdb_jsonrpc_remote *remote = node->data;
+
+        ovsdb_jsonrpc_session_reconnect_all(remote);
+    }
+}
+
 void
 ovsdb_jsonrpc_server_run(struct ovsdb_jsonrpc_server *svr)
 {
@@ -347,6 +362,22 @@ ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *remote)
     }
 }
 
+/* Forces all of the JSON-RPC sessions managed by 'remote' to disconnect and
+ * reconnect. */
+static void
+ovsdb_jsonrpc_session_reconnect_all(struct ovsdb_jsonrpc_remote *remote)
+{
+    struct ovsdb_jsonrpc_session *s, *next;
+
+    LIST_FOR_EACH_SAFE (s, next, struct ovsdb_jsonrpc_session, node,
+                        &remote->sessions) {
+        jsonrpc_session_force_reconnect(s->js);
+        if (!jsonrpc_session_is_alive(s->js)) {
+            ovsdb_jsonrpc_session_close(s);
+        }
+    }
+}
+
 static const char *
 get_db_name(const struct ovsdb_jsonrpc_session *s)
 {
index 6c4acd7f349db7060d9766c94fbb5f60bfa68af4..66dfa975e4fe076fc5a677108899d374a061930b 100644 (file)
@@ -25,6 +25,8 @@ void ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *);
 void ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *,
                                       const struct shash *);
 
+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 *);
 
index 7909b9ea6288e9bac48480ef711d7c6e8237aa9f..b36c61d209a9ca6bc84d991b70222ad1eaac9ba2 100644 (file)
@@ -85,6 +85,14 @@ Causes \fBovsdb\-server\fR to gracefully terminate.
 .IP "\fBovsdb-server/compact\fR"
 Compacts the database in-place.  The database is also automatically
 compacted occasionally.
+.
+.IP "\fBovsdb\-server/reconnect\fR"
+Makes \fBovsdb\-server\fR drop all of the JSON\-RPC
+connections to database clients and reconnect.
+.IP
+This command might be useful for debugging issues with database
+clients.
+.
 .so lib/vlog-unixctl.man
 .SH "SEE ALSO"
 .
index 0d95cb2e67fcfb4cfd12e855aa1a937132319dba..3b71442dab0ff6e6da059d768ace7fc98c47a695 100644 (file)
@@ -59,6 +59,7 @@ static bool bootstrap_ca_cert;
 
 static unixctl_cb_func ovsdb_server_exit;
 static unixctl_cb_func ovsdb_server_compact;
+static unixctl_cb_func ovsdb_server_reconnect;
 
 static void parse_options(int argc, char *argv[], char **file_namep,
                           struct shash *remotes, char **unixctl_pathp,
@@ -131,6 +132,8 @@ main(int argc, char *argv[])
     unixctl_command_register("exit", ovsdb_server_exit, &exiting);
     unixctl_command_register("ovsdb-server/compact", ovsdb_server_compact,
                              file);
+    unixctl_command_register("ovsdb-server/reconnect", ovsdb_server_reconnect,
+                             jsonrpc);
 
     exiting = false;
     while (!exiting) {
@@ -317,6 +320,18 @@ ovsdb_server_compact(struct unixctl_conn *conn, const char *args OVS_UNUSED,
     }
 }
 
+/* "ovsdb-server/reconnect": makes ovsdb-server drop all of its JSON-RPC
+ * connections and reconnect. */
+static void
+ovsdb_server_reconnect(struct unixctl_conn *conn, const char *args OVS_UNUSED,
+                       void *jsonrpc_)
+{
+    struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_;
+
+    ovsdb_jsonrpc_server_reconnect(jsonrpc);
+    unixctl_command_reply(conn, 200, NULL);
+}
+
 static void
 parse_options(int argc, char *argv[], char **file_namep,
               struct shash *remotes, char **unixctl_pathp,