Skip to content

Commit

Permalink
ovsdb-idl: improve error handling when schema is not available
Browse files Browse the repository at this point in the history
A common error scenario with OVN is to attempt to use ovn-nbctl when
the OVN databases have not been created in ovsdb-server:
   1. ovn-nbctl sends a "get_schema" request for the OVN db to ovsdb-server.
   2. ovsdb-server fails to find requested db, sends error response
      to ovn-nbctl.
   3. ovn-nbctl receives the error response in ovsdb_idl_run(), but
      takes no specific action.
   4. ovn-nbctl hangs forever in IDL_S_SCHEMA_REQUESTED state (assuming
      a timeout wasn't requested on the command line).

This commit adds a new IDL state, IDL_S_NO_SCHEMA, which is entered
when a negative response to a schema request is received. When in
this state, ovsdb_idl_is_alive() now returns 'false', allowing clients
(currently ovn-nbctl, ovn-sbctl, vtep-ctl, and ovs-vsctl) to detect this
condition and exit with an appropriate error message.

Signed-off-by: Lance Richardson <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
hlrichardson authored and blp committed Mar 14, 2016
1 parent 3cdc569 commit 6d88221
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/ovsdb-idl.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ enum ovsdb_idl_state {
IDL_S_MONITOR_REQUESTED,
IDL_S_MONITORING,
IDL_S_MONITOR2_REQUESTED,
IDL_S_MONITORING2
IDL_S_MONITORING2,
IDL_S_NO_SCHEMA
};

struct ovsdb_idl {
Expand Down Expand Up @@ -417,6 +418,7 @@ ovsdb_idl_run(struct ovsdb_idl *idl)

case IDL_S_MONITORING:
case IDL_S_MONITORING2:
case IDL_S_NO_SCHEMA:
default:
OVS_NOT_REACHED();
}
Expand Down Expand Up @@ -461,6 +463,7 @@ ovsdb_idl_run(struct ovsdb_idl *idl)
idl->request_id = NULL;
VLOG_ERR("%s: requested schema not found",
jsonrpc_session_get_name(idl->session));
idl->state = IDL_S_NO_SCHEMA;
} else if ((msg->type == JSONRPC_ERROR
|| msg->type == JSONRPC_REPLY)
&& ovsdb_idl_txn_process_reply(idl, msg)) {
Expand Down Expand Up @@ -550,20 +553,34 @@ ovsdb_idl_verify_write_only(struct ovsdb_idl *idl)
idl->verify_write_only = true;
}

/* Returns true if 'idl' is currently connected or trying to connect. */
/* Returns true if 'idl' is currently connected or trying to connect
* and a negative response to a schema request has not been received */
bool
ovsdb_idl_is_alive(const struct ovsdb_idl *idl)
{
return jsonrpc_session_is_alive(idl->session);
return jsonrpc_session_is_alive(idl->session) &&
idl->state != IDL_S_NO_SCHEMA;
}

/* Returns the last error reported on a connection by 'idl'. The return value
* is 0 only if no connection made by 'idl' has ever encountered an error. See
* jsonrpc_get_status() for return value interpretation. */
* is 0 only if no connection made by 'idl' has ever encountered an error and
* a negative response to a schema request has never been received. See
* jsonrpc_get_status() for jsonrpc_session_get_last_error() return value
* interpretation. */
int
ovsdb_idl_get_last_error(const struct ovsdb_idl *idl)
{
return jsonrpc_session_get_last_error(idl->session);
int err;

err = jsonrpc_session_get_last_error(idl->session);

if (err) {
return err;
} else if (idl->state == IDL_S_NO_SCHEMA) {
return ENOENT;
} else {
return 0;
}
}

static unsigned char *
Expand Down

0 comments on commit 6d88221

Please sign in to comment.