2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00

ovsdb-server: Database config isolation.

Add a new structure 'db_config' that holds the user-provided
configuration of the database.  And attach this configuration
to each of the databases on the server.

Each database has a service model: standalone, clustered, relay
or active-backup.  Relays and A-B databases have a source, each
source has its own set of JSON-RPC session options.  A-B also
have an indicator of it being active or backup and an optional
list of tables to exclude from replication.

All of that should be stored per database in the temporary
configuration file that is used in order to restore the config
after the OVSDB crash.  For that, the save/load functions are
also updates.

This change is written in generic way assuming all the databases
can have different configuration including service model.
The only user-visible change here is a slight modification of
the ovsdb-server/sync-status appctl, since it now needs to
skip databases that are not active-backup and also should report
active-backup databases that are currently active, i.e. not
added to the replication module.

If the service model is not defined in the configuration, it
is assumed to be standalone or clustered, and determined from
the storage type while opening the database.  If the service
model is defined, but doesn't match the actual storage type
in the database file, ovsdb-server will fail to open the
database.  This should never happen with internally generated
config file, but may happen in the future with user-provided
configuration files.  In this case the service model is used
for verification purposes only, if administrator wants to
assert a particular model.

Since the database 'source' connections can't use 'role' or
'read-only' options, a new flag added to corresponding JSON
parsing functions to skip these fields.

Acked-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Ilya Maximets 2024-01-09 23:49:07 +01:00
parent c8c0e570dc
commit e76f847209
5 changed files with 636 additions and 203 deletions

View File

@ -230,8 +230,18 @@ ovsdb_jsonrpc_options_clone(const struct ovsdb_jsonrpc_options *options)
return clone;
}
void
ovsdb_jsonrpc_options_free(struct ovsdb_jsonrpc_options *options)
{
if (options) {
free(options->role);
free(options);
}
}
struct json *
ovsdb_jsonrpc_options_to_json(const struct ovsdb_jsonrpc_options *options)
ovsdb_jsonrpc_options_to_json(const struct ovsdb_jsonrpc_options *options,
bool jsonrpc_session_only)
{
struct json *json = json_object_create();
@ -239,9 +249,15 @@ ovsdb_jsonrpc_options_to_json(const struct ovsdb_jsonrpc_options *options)
json_integer_create(options->max_backoff));
json_object_put(json, "inactivity-probe",
json_integer_create(options->probe_interval));
json_object_put(json, "dscp", json_integer_create(options->dscp));
if (jsonrpc_session_only) {
/* Caller is not interested in OVSDB-specific options. */
return json;
}
json_object_put(json, "read-only",
json_boolean_create(options->read_only));
json_object_put(json, "dscp", json_integer_create(options->dscp));
if (options->role) {
json_object_put(json, "role", json_string_create(options->role));
}
@ -251,7 +267,8 @@ ovsdb_jsonrpc_options_to_json(const struct ovsdb_jsonrpc_options *options)
void
ovsdb_jsonrpc_options_update_from_json(struct ovsdb_jsonrpc_options *options,
const struct json *json)
const struct json *json,
bool jsonrpc_session_only)
{
const struct json *max_backoff, *probe_interval, *read_only, *dscp, *role;
struct ovsdb_parser parser;
@ -271,23 +288,29 @@ ovsdb_jsonrpc_options_update_from_json(struct ovsdb_jsonrpc_options *options,
options->probe_interval = json_integer(probe_interval);
}
dscp = ovsdb_parser_member(&parser, "dscp", OP_INTEGER | OP_OPTIONAL);
if (dscp) {
options->dscp = json_integer(dscp);
}
if (jsonrpc_session_only) {
/* Caller is not interested in OVSDB-specific options. */
goto exit;
}
read_only = ovsdb_parser_member(&parser, "read-only",
OP_BOOLEAN | OP_OPTIONAL);
if (read_only) {
options->read_only = json_boolean(read_only);
}
dscp = ovsdb_parser_member(&parser, "dscp", OP_INTEGER | OP_OPTIONAL);
if (dscp) {
options->dscp = json_integer(dscp);
}
role = ovsdb_parser_member(&parser, "role", OP_STRING | OP_OPTIONAL);
if (role) {
free(options->role);
options->role = nullable_xstrdup(json_string(role));
}
exit:
error = ovsdb_parser_finish(&parser);
if (error) {
char *s = ovsdb_error_to_string_free(error);

View File

@ -43,12 +43,14 @@ struct ovsdb_jsonrpc_options *ovsdb_jsonrpc_default_options(
const char *target);
struct ovsdb_jsonrpc_options *ovsdb_jsonrpc_options_clone(
const struct ovsdb_jsonrpc_options *);
void ovsdb_jsonrpc_options_free(struct ovsdb_jsonrpc_options *);
struct json *ovsdb_jsonrpc_options_to_json(
const struct ovsdb_jsonrpc_options *)
const struct ovsdb_jsonrpc_options *, bool jsonrpc_session_only)
OVS_WARN_UNUSED_RESULT;
void ovsdb_jsonrpc_options_update_from_json(struct ovsdb_jsonrpc_options *,
const struct json *);
const struct json *,
bool jsonrpc_session_only);
void ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *,
const struct shash *);

File diff suppressed because it is too large Load Diff

View File

@ -779,7 +779,6 @@ replication_status(const struct ovsdb *db)
bool alive = rdb->session && jsonrpc_session_is_alive(rdb->session);
struct ds ds = DS_EMPTY_INITIALIZER;
ds_put_format(&ds, "database: %s\n", db->name);
if (alive) {
switch (rdb->state) {
case RPL_S_INIT:

View File

@ -1988,7 +1988,9 @@ OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status |grep re
dnl Switch the 'db1' to active
AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/disconnect-active-ovsdb-server])
AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status], [0], [state: active
AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status], [0], [dnl
database: mydb
state: active
])
dnl Issue a transaction to 'db1'
@ -2007,7 +2009,9 @@ AT_CHECK([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/connect-active-ovsdb-server
dnl Verify the change happend
OVS_WAIT_UNTIL([ovs-appctl -t "`pwd`"/unixctl ovsdb-server/sync-status |grep replicating])
AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status], [0], [state: active
AT_CHECK([ovs-appctl -t "`pwd`"/unixctl2 ovsdb-server/sync-status], [0], [dnl
database: mydb
state: active
])
dnl Issue an transaction to 'db2' which is now active.