summaryrefslogtreecommitdiff
path: root/ovsdb/ovsdb-server.c
diff options
context:
space:
mode:
authorAndy Zhou <azhou@ovn.org>2016-07-29 14:39:29 -0700
committerAndy Zhou <azhou@ovn.org>2016-08-14 23:32:47 -0700
commite51879e99b3ed11c6b7017a63bff1c5da9f21fda (patch)
treee8e32e013d1e0c3d54898ce08b82e2cbb357a2e2 /ovsdb/ovsdb-server.c
parent8fd2bca0270f4055bccca103c596949ab7591b4d (diff)
downloadopenvswitch-e51879e99b3ed11c6b7017a63bff1c5da9f21fda.tar.gz
ovsdb: Make OVSDB backup sever read only
When ovsdb-sever is running in the backup state, it would be nice to make sure there is no un-intended changes to the backup database. This patch makes the ovsdb server only accepts 'read' transactions as a backup server. When the server role is changed into an active server, all existing client connections will be reset. After reconnect, all clinet transactions will then be accepted. Signed-off-by: Andy Zhou <azhou@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'ovsdb/ovsdb-server.c')
-rw-r--r--ovsdb/ovsdb-server.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 257740116..e08c3418f 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -153,8 +153,15 @@ main_loop(struct ovsdb_jsonrpc_server *jsonrpc, struct shash *all_dbs,
/* Run unixctl_server_run() before reconfigure_remotes() because
* ovsdb-server/add-remote and ovsdb-server/remove-remote can change
* the set of remotes that reconfigure_remotes() uses. */
+ bool last_role = is_backup_server;
unixctl_server_run(unixctl);
+ /* In case unixctl commands change the role of ovsdb-server,
+ * from active to backup or vise versa, recoonect jsonrpc server. */
+ if (last_role != is_backup_server) {
+ ovsdb_jsonrpc_server_reconnect(jsonrpc, is_backup_server);
+ }
+
report_error_if_changed(
reconfigure_remotes(jsonrpc, all_dbs, remotes),
&remotes_error);
@@ -267,7 +274,7 @@ main(int argc, char *argv[])
/* Load the saved config. */
load_config(config_tmpfile, &remotes, &db_filenames);
- jsonrpc = ovsdb_jsonrpc_server_create();
+ jsonrpc = ovsdb_jsonrpc_server_create(is_backup_server);
shash_init(&all_dbs);
server_config.all_dbs = &all_dbs;
@@ -348,14 +355,18 @@ main(int argc, char *argv[])
ovsdb_server_set_active_ovsdb_server, NULL);
unixctl_command_register("ovsdb-server/get-active-ovsdb-server", "", 0, 0,
ovsdb_server_get_active_ovsdb_server, NULL);
- unixctl_command_register("ovsdb-server/connect-active-ovsdb-server", "", 0, 0,
- ovsdb_server_connect_active_ovsdb_server, NULL);
- unixctl_command_register("ovsdb-server/disconnect-active-ovsdb-server", "", 0, 0,
- ovsdb_server_disconnect_active_ovsdb_server, NULL);
- unixctl_command_register("ovsdb-server/set-sync-excluded-tables", "", 0, 1,
- ovsdb_server_set_sync_excluded_tables, NULL);
- unixctl_command_register("ovsdb-server/get-sync-excluded-tables", "", 0, 0,
- ovsdb_server_get_sync_excluded_tables, NULL);
+ unixctl_command_register("ovsdb-server/connect-active-ovsdb-server", "",
+ 0, 0, ovsdb_server_connect_active_ovsdb_server,
+ NULL);
+ unixctl_command_register("ovsdb-server/disconnect-active-ovsdb-server", "",
+ 0, 0, ovsdb_server_disconnect_active_ovsdb_server,
+ NULL);
+ unixctl_command_register("ovsdb-server/set-sync-excluded-tables", "",
+ 0, 1, ovsdb_server_set_sync_excluded_tables,
+ NULL);
+ unixctl_command_register("ovsdb-server/get-sync-excluded-tables", "",
+ 0, 0, ovsdb_server_get_sync_excluded_tables,
+ NULL);
/* Simulate the behavior of OVS release prior to version 2.5 that
* does not support the monitor_cond method. */
@@ -1048,6 +1059,7 @@ ovsdb_server_set_active_ovsdb_server(struct unixctl_conn *conn,
{
set_active_ovsdb_server(argv[1]);
is_backup_server = true;
+ VLOG_INFO("become a backup server");
unixctl_command_reply(conn, NULL);
}
@@ -1087,6 +1099,7 @@ ovsdb_server_disconnect_active_ovsdb_server(struct unixctl_conn *conn,
{
disconnect_active_server();
is_backup_server = false;
+ VLOG_INFO("become an active server");
unixctl_command_reply(conn, NULL);
}
@@ -1161,7 +1174,7 @@ ovsdb_server_disable_monitor_cond(struct unixctl_conn *conn,
struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_;
ovsdb_jsonrpc_disable_monitor_cond();
- ovsdb_jsonrpc_server_reconnect(jsonrpc);
+ ovsdb_jsonrpc_server_reconnect(jsonrpc, is_backup_server);
unixctl_command_reply(conn, NULL);
}
@@ -1217,7 +1230,7 @@ ovsdb_server_reconnect(struct unixctl_conn *conn, int argc OVS_UNUSED,
{
struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_;
- ovsdb_jsonrpc_server_reconnect(jsonrpc);
+ ovsdb_jsonrpc_server_reconnect(jsonrpc, is_backup_server);
unixctl_command_reply(conn, NULL);
}