Skip to content

Commit

Permalink
ovsdb: Introduce OVSDB replication feature
Browse files Browse the repository at this point in the history
Replication is enabled by using the following option when starting the
database server:

--sync-from=server

Where 'server' can take any form described in the ovsdb-client(1)
manpage as an active connection. If this option is specified, the
replication process is immediately started.

Signed-off-by: Mario Cabrera <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
Mario Cabrera authored and blp committed Jun 25, 2016
1 parent 55460ac commit ae671c5
Show file tree
Hide file tree
Showing 9 changed files with 730 additions and 28 deletions.
6 changes: 5 additions & 1 deletion manpages.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ ovsdb/ovsdb-server.1: \
lib/vlog-unixctl.man \
lib/vlog.man \
ovsdb/remote-active.man \
ovsdb/remote-passive.man
ovsdb/remote-passive.man \
ovsdb/replication-syn.man \
ovsdb/replication.man
ovsdb/ovsdb-server.1.in:
lib/common-syn.man:
lib/common.man:
Expand All @@ -87,6 +89,8 @@ lib/vlog-unixctl.man:
lib/vlog.man:
ovsdb/remote-active.man:
ovsdb/remote-passive.man:
ovsdb/replication-syn.man:
ovsdb/replication.man:

ovsdb/ovsdb-tool.1: \
ovsdb/ovsdb-tool.1.in \
Expand Down
6 changes: 5 additions & 1 deletion ovsdb/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ovsdb_libovsdb_la_SOURCES = \
ovsdb/monitor.h \
ovsdb/query.c \
ovsdb/query.h \
ovsdb/replication.c \
ovsdb/replication.h \
ovsdb/row.c \
ovsdb/row.h \
ovsdb/server.c \
Expand All @@ -42,7 +44,9 @@ pkgconfig_DATA += \

MAN_FRAGMENTS += \
ovsdb/remote-active.man \
ovsdb/remote-passive.man
ovsdb/remote-passive.man \
ovsdb/replication.man \
ovsdb/replication-syn.man

# ovsdb-tool
bin_PROGRAMS += ovsdb/ovsdb-tool
Expand Down
3 changes: 3 additions & 0 deletions ovsdb/ovsdb-server.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ovsdb\-server \- Open vSwitch database server
.so lib/daemon-syn.man
.so lib/service-syn.man
.so lib/vlog-syn.man
.so ovsdb/replication-syn.man
.so lib/ssl-syn.man
.so lib/ssl-bootstrap-syn.man
.so lib/ssl-peer-ca-cert-syn.man
Expand Down Expand Up @@ -100,6 +101,8 @@ configured remotes.
.so lib/service.man
.SS "Logging Options"
.so lib/vlog.man
.SS "Syncing Options"
.so ovsdb/replication.man
.SS "Public Key Infrastructure Options"
The options described below for configuring the SSL public key
infrastructure accept a special syntax for obtaining their
Expand Down
46 changes: 20 additions & 26 deletions ovsdb/ovsdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "ovsdb-error.h"
#include "poll-loop.h"
#include "process.h"
#include "replication.h"
#include "row.h"
#include "simap.h"
#include "shash.h"
Expand All @@ -59,22 +60,17 @@

VLOG_DEFINE_THIS_MODULE(ovsdb_server);

struct db {
/* Initialized in main(). */
char *filename;
struct ovsdb_file *file;
struct ovsdb *db;

/* Only used by update_remote_status(). */
struct ovsdb_txn *txn;
};
struct db;

/* SSL configuration. */
static char *private_key_file;
static char *certificate_file;
static char *ca_cert_file;
static bool bootstrap_ca_cert;

/* Replication configuration. */
static bool connect_to_remote_server;

static unixctl_cb_func ovsdb_server_exit;
static unixctl_cb_func ovsdb_server_compact;
static unixctl_cb_func ovsdb_server_reconnect;
Expand Down Expand Up @@ -159,6 +155,10 @@ main_loop(struct ovsdb_jsonrpc_server *jsonrpc, struct shash *all_dbs,
report_error_if_changed(reconfigure_ssl(all_dbs), &ssl_error);
ovsdb_jsonrpc_server_run(jsonrpc);

if (connect_to_remote_server) {
replication_run(all_dbs);
}

SHASH_FOR_EACH(node, all_dbs) {
struct db *db = node->data;
ovsdb_trigger_run(db->db, time_msec());
Expand All @@ -170,9 +170,9 @@ main_loop(struct ovsdb_jsonrpc_server *jsonrpc, struct shash *all_dbs,
}
}

/* update Manager status(es) every 5 seconds */
/* update Manager status(es) every 2.5 seconds */
if (time_msec() >= status_timer) {
status_timer = time_msec() + 5000;
status_timer = time_msec() + 2500;
update_remote_status(jsonrpc, remotes, all_dbs);
}

Expand Down Expand Up @@ -351,6 +351,7 @@ main(int argc, char *argv[])
sset_destroy(&remotes);
sset_destroy(&db_filenames);
unixctl_server_destroy(unixctl);
disconnect_remote_server();

if (run_process && process_exited(run_process)) {
int status = process_status(run_process);
Expand Down Expand Up @@ -434,21 +435,6 @@ open_db(struct server_config *config, const char *filename)
return error;
}

static const struct db *
find_db(const struct shash *all_dbs, const char *db_name)
{
struct shash_node *node;

SHASH_FOR_EACH(node, all_dbs) {
struct db *db = node->data;
if (!strcmp(db->db->schema->name, db_name)) {
return db;
}
}

return NULL;
}

static char * OVS_WARN_UNUSED_RESULT
parse_db_column__(const struct shash *all_dbs,
const char *name_, char *name,
Expand Down Expand Up @@ -1279,6 +1265,7 @@ parse_options(int *argcp, char **argvp[],
OPT_RUN,
OPT_BOOTSTRAP_CA_CERT,
OPT_PEER_CA_CERT,
OPT_SYNC_FROM,
VLOG_OPTION_ENUMS,
DAEMON_OPTION_ENUMS
};
Expand All @@ -1297,6 +1284,7 @@ parse_options(int *argcp, char **argvp[],
{"private-key", required_argument, NULL, 'p'},
{"certificate", required_argument, NULL, 'c'},
{"ca-cert", required_argument, NULL, 'C'},
{"sync-from", required_argument, NULL, OPT_SYNC_FROM},
{NULL, 0, NULL, 0},
};
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
Expand Down Expand Up @@ -1357,6 +1345,11 @@ parse_options(int *argcp, char **argvp[],
stream_ssl_set_peer_ca_cert_file(optarg);
break;

case OPT_SYNC_FROM:
set_remote_ovsdb_server(optarg);
connect_to_remote_server = true;
break;

case '?':
exit(EXIT_FAILURE);

Expand All @@ -1383,6 +1376,7 @@ usage(void)
stream_usage("JSON-RPC", true, true, true);
daemon_usage();
vlog_usage();
replication_usage();
printf("\nOther options:\n"
" --run COMMAND run COMMAND as subprocess then exit\n"
" --unixctl=SOCKET override default control socket name\n"
Expand Down
2 changes: 2 additions & 0 deletions ovsdb/replication-syn.man
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.IP "Syncing options:"
[\fB\-\-sync\-from=\fIserver\fR]
Loading

0 comments on commit ae671c5

Please sign in to comment.