diff options
author | Mario Cabrera <mario.cabrera@hpe.com> | 2016-03-29 11:01:00 -0600 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2016-06-24 17:15:38 -0700 |
commit | 7a9d65d294c903ef77191cd143a467a5a1e8d3ac (patch) | |
tree | 3f62a2d8d21ae655a15c22e78804d101b4ea3320 /ovsdb | |
parent | ae671c5feb88db395304e452ab47c83b4ac84ee0 (diff) | |
download | openvswitch-7a9d65d294c903ef77191cd143a467a5a1e8d3ac.tar.gz |
ovsdb: Add table exclusion functionality to OVSDB replication
A blacklist of tables that will be excluded from replication can be
specified by the following option:
--sync-exclude-tables=db:table[,db:table]…
Where 'table' corresponds to a table name, and 'db' corresponds to the
database name where the table resides.
Signed-off-by: Mario Cabrera <mario.cabrera@hpe.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'ovsdb')
-rw-r--r-- | ovsdb/ovsdb-server.c | 6 | ||||
-rw-r--r-- | ovsdb/replication.c | 49 | ||||
-rw-r--r-- | ovsdb/replication.h | 1 |
3 files changed, 53 insertions, 3 deletions
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 650c164ac..1b9de19c9 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -1266,6 +1266,7 @@ parse_options(int *argcp, char **argvp[], OPT_BOOTSTRAP_CA_CERT, OPT_PEER_CA_CERT, OPT_SYNC_FROM, + OPT_SYNC_EXCLUDE, VLOG_OPTION_ENUMS, DAEMON_OPTION_ENUMS }; @@ -1285,6 +1286,7 @@ parse_options(int *argcp, char **argvp[], {"certificate", required_argument, NULL, 'c'}, {"ca-cert", required_argument, NULL, 'C'}, {"sync-from", required_argument, NULL, OPT_SYNC_FROM}, + {"sync-exclude-tables", required_argument, NULL, OPT_SYNC_EXCLUDE}, {NULL, 0, NULL, 0}, }; char *short_options = ovs_cmdl_long_options_to_short_options(long_options); @@ -1350,6 +1352,10 @@ parse_options(int *argcp, char **argvp[], connect_to_remote_server = true; break; + case OPT_SYNC_EXCLUDE: + set_tables_blacklist(optarg); + break; + case '?': exit(EXIT_FAILURE); diff --git a/ovsdb/replication.c b/ovsdb/replication.c index 669f4758c..1fa0f253a 100644 --- a/ovsdb/replication.c +++ b/ovsdb/replication.c @@ -35,8 +35,10 @@ static char *remote_ovsdb_server; static struct jsonrpc *rpc; static struct sset monitored_tables = SSET_INITIALIZER(&monitored_tables); +static struct sset tables_blacklist = SSET_INITIALIZER(&tables_blacklist); static bool reset_dbs = true; +void replication_init(void); static struct jsonrpc *open_jsonrpc(const char *server); static struct ovsdb_error *check_jsonrpc_error(int error, struct jsonrpc_msg **reply_); @@ -73,6 +75,14 @@ static struct ovsdb_error *execute_update(struct ovsdb_txn *txn, struct json *new); void +replication_init(void) +{ + sset_init(&monitored_tables); + sset_init(&tables_blacklist); + reset_dbs = true; +} + +void replication_run(struct shash *all_dbs) { if (sset_is_empty(&monitored_tables) && remote_ovsdb_server) { @@ -109,10 +119,30 @@ set_remote_ovsdb_server(const char *remote_server) } void +set_tables_blacklist(const char *blacklist) +{ + char *save_ptr = NULL; + char *blacklist_item; + + replication_init(); + + if (blacklist) { + char *t_blacklist = xstrdup(blacklist); + for (blacklist_item = strtok_r(t_blacklist, ",", &save_ptr); + blacklist_item != NULL; + blacklist_item = strtok_r(NULL, ",", &save_ptr)) { + sset_add(&tables_blacklist, blacklist_item); + } + free(t_blacklist); + } +} + +void disconnect_remote_server(void) { jsonrpc_close(rpc); sset_destroy(&monitored_tables); + sset_destroy(&tables_blacklist); if (remote_ovsdb_server) { free(remote_ovsdb_server); @@ -160,9 +190,15 @@ reset_database(struct ovsdb *db, struct ovsdb_txn *txn) struct ovsdb_table *table = table_node->data; struct ovsdb_row *row; - HMAP_FOR_EACH (row, hmap_node, &table->rows) { - ovsdb_txn_row_delete(txn, row); + /* Do not reset if table is blacklisted. */ + char *blacklist_item = xasprintf( + "%s%s%s", db->schema->name, ":", table_node->name); + if (!sset_contains(&tables_blacklist, blacklist_item)) { + HMAP_FOR_EACH (row, hmap_node, &table->rows) { + ovsdb_txn_row_delete(txn, row); + } } + free(blacklist_item); } } @@ -293,7 +329,14 @@ send_monitor_requests(struct shash *all_dbs) for (int j = 0; j < n; j++) { struct ovsdb_table_schema *table = nodes[j]->data; - add_monitored_table(table, monitor_request); + + /* Check if table is not blacklisted. */ + char *blacklist_item = xasprintf( + "%s%s%s", db_name, ":", table->name); + if (!sset_contains(&tables_blacklist, blacklist_item)) { + add_monitored_table(table, monitor_request); + } + free(blacklist_item); } free(nodes); diff --git a/ovsdb/replication.h b/ovsdb/replication.h index f9b7d6323..74acdbaa5 100644 --- a/ovsdb/replication.h +++ b/ovsdb/replication.h @@ -32,6 +32,7 @@ struct db { void replication_run(struct shash *dbs); void set_remote_ovsdb_server(const char *remote_server); +void set_tables_blacklist(const char *blacklist); void disconnect_remote_server(void); const struct db *find_db(const struct shash *all_dbs, const char *db_name); void replication_usage(void); |