Skip to content

Commit

Permalink
ovs-vsctl: reconnect to the database if connection was dropped
Browse files Browse the repository at this point in the history
If ovs-vsctl has to wait for ovs-vswitchd to reconfigure itself
according to the new database, then sometimes ovs-vsctl could
end up stuck in the event loop if OVSDB connection was dropped
while ovs-vsctl was still running.

This patch fixes this problem by letting ovs-vsctl to reconnect
to the OVSDB, if it has to wait cur_cfg field to be updated.

Issue: 1191997
Reported-by: Spiro Kourtessis <[email protected]>
Signed-Off-By: Ansis Atteka <[email protected]>
  • Loading branch information
Ansis Atteka committed Feb 19, 2014
1 parent d709419 commit 705d7a3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,14 @@ jsonrpc_session_get_reconnect_stats(const struct jsonrpc_session *s,
reconnect_get_stats(s->reconnect, time_msec(), stats);
}

void
jsonrpc_session_enable_reconnect(struct jsonrpc_session *s)
{
reconnect_set_max_tries(s->reconnect, UINT_MAX);
reconnect_set_backoff(s->reconnect, RECONNECT_DEFAULT_MIN_BACKOFF,
RECONNECT_DEFAULT_MAX_BACKOFF);
}

void
jsonrpc_session_force_reconnect(struct jsonrpc_session *s)
{
Expand Down
1 change: 1 addition & 0 deletions lib/jsonrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ int jsonrpc_session_get_last_error(const struct jsonrpc_session *);
void jsonrpc_session_get_reconnect_stats(const struct jsonrpc_session *,
struct reconnect_stats *);

void jsonrpc_session_enable_reconnect(struct jsonrpc_session *);
void jsonrpc_session_force_reconnect(struct jsonrpc_session *);

void jsonrpc_session_set_max_backoff(struct jsonrpc_session *,
Expand Down
8 changes: 8 additions & 0 deletions lib/ovsdb-idl.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,14 @@ ovsdb_idl_has_ever_connected(const struct ovsdb_idl *idl)
return ovsdb_idl_get_seqno(idl) != 0;
}

/* Reconfigures 'idl' so that it would reconnect to the database, if
* connection was dropped. */
void
ovsdb_idl_enable_reconnect(struct ovsdb_idl *idl)
{
jsonrpc_session_enable_reconnect(idl->session);
}

/* Forces 'idl' to drop its connection to the database and reconnect. In the
* meantime, the contents of 'idl' will not change. */
void
Expand Down
1 change: 1 addition & 0 deletions lib/ovsdb-idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ bool ovsdb_idl_is_lock_contended(const struct ovsdb_idl *);

unsigned int ovsdb_idl_get_seqno(const struct ovsdb_idl *);
bool ovsdb_idl_has_ever_connected(const struct ovsdb_idl *);
void ovsdb_idl_enable_reconnect(struct ovsdb_idl *);
void ovsdb_idl_force_reconnect(struct ovsdb_idl *);
void ovsdb_idl_verify_write_only(struct ovsdb_idl *);

Expand Down
5 changes: 5 additions & 0 deletions utilities/ovs-vsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4123,6 +4123,11 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
free(commands);

if (wait_for_reload && status != TXN_UNCHANGED) {
/* Even, if --retry flag was not specified, ovs-vsctl still
* has to retry to establish OVSDB connection, if wait_for_reload
* was set. Otherwise, ovs-vsctl would end up waiting forever
* until cur_cfg would be updated. */
ovsdb_idl_enable_reconnect(idl);
for (;;) {
ovsdb_idl_run(idl);
OVSREC_OPEN_VSWITCH_FOR_EACH (ovs, idl) {
Expand Down

0 comments on commit 705d7a3

Please sign in to comment.