2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-01 14:55:18 +00:00

ovsdb-cs: Avoid unnecessary re-connections when updating remotes.

If a new database server added to the cluster, or if one of the
database servers changed its IP address or port, then you need to
update the list of remotes for the client.  For example, if a new
OVN_Southbound database server is added, you need to update the
ovn-remote for the ovn-controller.

However, in the current implementation, the ovsdb-cs module always
closes the current connection and creates a new one.  This can lead
to a storm of re-connections if all ovn-controllers will be updated
simultaneously.  They can also start re-dowloading the database
content, creating even more load on the database servers.

Correct this by saving an existing connection if it is still in the
list of remotes after the update.

'reconnect' module will report connection state updates, but that
is OK since no real re-connection happened and we only updated the
state of a new 'reconnect' instance.

If required, re-connection can be forced after the update of remotes
with ovsdb_cs_force_reconnect().

Acked-by: Dumitru Ceara <dceara@redhat.com>
Acked-by: Han Zhou <hzhou@ovn.org>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Ilya Maximets
2021-06-29 12:56:18 +02:00
parent 73259ea703
commit 00dda78ed4
7 changed files with 78 additions and 5 deletions

View File

@@ -660,7 +660,8 @@ ovsdb_cs_wait(struct ovsdb_cs *cs)
/* Network connection. */
/* Changes the remote and creates a new session.
/* Changes the remote and creates a new session. Keeps existing connection
* if current remote is still valid.
*
* If 'retry' is true, the connection to the remote will automatically retry
* when it fails. If 'retry' is false, the connection is one-time. */
@@ -670,9 +671,12 @@ ovsdb_cs_set_remote(struct ovsdb_cs *cs, const char *remote, bool retry)
if (cs
&& ((remote != NULL) != (cs->remote != NULL)
|| (remote && cs->remote && strcmp(remote, cs->remote)))) {
struct jsonrpc *rpc = NULL;
/* Close the old session, if any. */
if (cs->session) {
jsonrpc_session_close(cs->session);
/* Save the current open connection and close the session. */
rpc = jsonrpc_session_steal(cs->session);
cs->session = NULL;
free(cs->remote);
@@ -682,17 +686,30 @@ ovsdb_cs_set_remote(struct ovsdb_cs *cs, const char *remote, bool retry)
/* Open new session, if any. */
if (remote) {
struct svec remotes = SVEC_EMPTY_INITIALIZER;
struct uuid old_cid = cs->cid;
ovsdb_session_parse_remote(remote, &remotes, &cs->cid);
if (cs->shuffle_remotes) {
svec_shuffle(&remotes);
}
cs->session = jsonrpc_session_open_multiple(&remotes, retry);
/* Use old connection, if cluster id didn't change and the remote
* is still on the list, to avoid unnecessary re-connection. */
if (rpc && uuid_equals(&old_cid, &cs->cid)
&& svec_contains_unsorted(&remotes, jsonrpc_get_name(rpc))) {
jsonrpc_session_replace(cs->session, rpc);
cs->state_seqno = jsonrpc_session_get_seqno(cs->session);
rpc = NULL;
} else {
cs->state_seqno = UINT_MAX;
}
svec_destroy(&remotes);
cs->state_seqno = UINT_MAX;
cs->remote = xstrdup(remote);
}
jsonrpc_close(rpc);
}
}