}
}
-/* Processes a batch of messages from the database server on 'idl'. Returns
- * true if the database as seen through 'idl' changed, false if it did not
- * change. The initial fetch of the entire contents of the remote database is
- * considered to be one kind of change. If 'idl' has been configured to
- * acquire a database lock (with ovsdb_idl_set_lock()), then successfully
- * acquiring the lock is also considered to be a change.
- *
- * When this function returns false, the client may continue to use any data
- * structures it obtained from 'idl' in the past. But when it returns true,
- * the client must not access any of these data structures again, because they
- * could have freed or reused for other purposes.
- *
- * This function can return occasional false positives, that is, report that
- * the database changed even though it didn't. This happens if the connection
- * to the database drops and reconnects, which causes the database contents to
- * be reloaded even if they didn't change. (It could also happen if the
- * database server sends out a "change" that reflects what we already thought
- * was in the database, but the database server is not supposed to do that.)
- *
- * As an alternative to checking the return value, the client may check for
- * changes in the value returned by ovsdb_idl_get_seqno().
- */
-bool
+/* Processes a batch of messages from the database server on 'idl'. This may
+ * cause the IDL's contents to change. The client may check for that with
+ * ovsdb_idl_get_seqno(). */
+void
ovsdb_idl_run(struct ovsdb_idl *idl)
{
- unsigned int initial_change_seqno = idl->change_seqno;
int i;
assert(!idl->txn);
}
jsonrpc_msg_destroy(msg);
}
-
- return initial_change_seqno != idl->change_seqno;
}
/* Arranges for poll_block() to wake up when ovsdb_idl_run() has something to
return "aborted";
case TXN_SUCCESS:
return "success";
- case TXN_AGAIN_WAIT:
- return "wait then try again";
- case TXN_AGAIN_NOW:
- return "try again now";
+ case TXN_TRY_AGAIN:
+ return "try again";
case TXN_NOT_LOCKED:
return "not locked";
case TXN_ERROR:
json_hash(txn->request_id, 0));
txn->status = TXN_INCOMPLETE;
} else {
- txn->status = TXN_AGAIN_WAIT;
+ txn->status = TXN_TRY_AGAIN;
}
ovsdb_idl_txn_disassemble(txn);
struct ovsdb_idl_txn *txn;
HMAP_FOR_EACH (txn, hmap_node, &idl->outstanding_txns) {
- ovsdb_idl_txn_complete(txn, TXN_AGAIN_WAIT);
+ ovsdb_idl_txn_complete(txn, TXN_TRY_AGAIN);
}
}
status = (hard_errors ? TXN_ERROR
: lock_errors ? TXN_NOT_LOCKED
- : soft_errors ? (txn->commit_seqno == idl->change_seqno
- ? TXN_AGAIN_WAIT
- : TXN_AGAIN_NOW)
+ : soft_errors ? TXN_TRY_AGAIN
: TXN_SUCCESS);
}
-/* Copyright (c) 2009, 2010, 2011 Nicira Networks.
+/* Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
bool monitor_everything_by_default);
void ovsdb_idl_destroy(struct ovsdb_idl *);
-bool ovsdb_idl_run(struct ovsdb_idl *);
+void ovsdb_idl_run(struct ovsdb_idl *);
void ovsdb_idl_wait(struct ovsdb_idl *);
void ovsdb_idl_set_lock(struct ovsdb_idl *, const char *lock_name);
* always appear to the client to be the default value for its type.
*
* If OVSDB_IDL_MONITOR is set, then the column is replicated. Its value will
- * reflect the value in the database. If OVSDB_IDL_ALERT is also set, then
- * ovsdb_idl_run() will return "true", and the value returned by
- * ovsdb_idl_get_seqno() will change, when the column's value changes.
+ * reflect the value in the database. If OVSDB_IDL_ALERT is also set, then the
+ * value returned by ovsdb_idl_get_seqno() will change when the column's value
+ * changes.
*
* The possible mode combinations are:
*
TXN_INCOMPLETE, /* Commit in progress, please wait. */
TXN_ABORTED, /* ovsdb_idl_txn_abort() called. */
TXN_SUCCESS, /* Commit successful. */
- TXN_AGAIN_WAIT, /* Commit failed because a "verify" operation
+ TXN_TRY_AGAIN, /* Commit failed because a "verify" operation
* reported an inconsistency, due to a network
* problem, or other transient failure. Wait
* for a change, then try again. */
- TXN_AGAIN_NOW, /* Same as above but try again immediately. */
TXN_NOT_LOCKED, /* Server hasn't given us the lock yet. */
TXN_ERROR /* Commit failed due to a hard error. */
};
def __txn_abort_all(self):
while self._outstanding_txns:
txn = self._outstanding_txns.popitem()[1]
- txn._status = Transaction.AGAIN_WAIT
+ txn._status = Transaction.TRY_AGAIN
def __txn_process_reply(self, msg):
txn = self._outstanding_txns.pop(msg.id, None)
if 'column_name' changed in this row (or if this row was deleted)
between the time that the IDL originally read its contents and the time
that the transaction commits, then the transaction aborts and
- Transaction.commit() returns Transaction.AGAIN_WAIT or
- Transaction.AGAIN_NOW (depending on whether the database change has
- already been received).
+ Transaction.commit() returns Transaction.TRY_AGAIN.
The intention is that, to ensure that no transaction commits based on
dirty reads, an application should call Row.verify() on each data item
INCOMPLETE = "incomplete" # Commit in progress, please wait.
ABORTED = "aborted" # ovsdb_idl_txn_abort() called.
SUCCESS = "success" # Commit successful.
- AGAIN_WAIT = "wait then try again"
- # Commit failed because a "verify" operation
+ TRY_AGAIN = "try again" # Commit failed because a "verify" operation
# reported an inconsistency, due to a network
# problem, or other transient failure. Wait
# for a change, then try again.
- AGAIN_NOW = "try again now" # Same as AGAIN_WAIT but try again right away.
NOT_LOCKED = "not locked" # Server hasn't given us the lock yet.
ERROR = "error" # Commit failed due to a hard error.
self.idl._outstanding_txns[self._request_id] = self
self._status = Transaction.INCOMPLETE
else:
- self._status = Transaction.AGAIN_WAIT
+ self._status = Transaction.TRY_AGAIN
self.__disassemble()
return self._status
elif lock_errors:
self._status = Transaction.NOT_LOCKED
elif soft_errors:
- if self._commit_seqno == self.idl.change_seqno:
- self._status = Transaction.AGAIN_WAIT
- else:
- self._status = Transaction.AGAIN_NOW
+ self._status = Transaction.TRY_AGAIN
else:
self._status = Transaction.SUCCESS
/*
- * Copyright (c) 2009, 2010, 2011 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
arg++;
} else {
/* Wait for update. */
- while (ovsdb_idl_get_seqno(idl) == seqno && !ovsdb_idl_run(idl)) {
+ for (;;) {
+ ovsdb_idl_run(idl);
+ if (ovsdb_idl_get_seqno(idl) != seqno) {
+ break;
+ }
jsonrpc_run(rpc);
ovsdb_idl_wait(idl);
if (rpc) {
jsonrpc_close(rpc);
}
- while (ovsdb_idl_get_seqno(idl) == seqno && !ovsdb_idl_run(idl)) {
+ for (;;) {
+ ovsdb_idl_run(idl);
+ if (ovsdb_idl_get_seqno(idl) != seqno) {
+ break;
+ }
ovsdb_idl_wait(idl);
poll_block();
}
static const struct vsctl_command_syntax *find_command(const char *name);
static void run_prerequisites(struct vsctl_command[], size_t n_commands,
struct ovsdb_idl *);
-static enum ovsdb_idl_txn_status do_vsctl(const char *args,
- struct vsctl_command *, size_t n,
- struct ovsdb_idl *);
+static void do_vsctl(const char *args, struct vsctl_command *, size_t n,
+ struct ovsdb_idl *);
static const struct vsctl_table_class *get_table(const char *table_name);
static void set_column(const struct vsctl_table_class *,
main(int argc, char *argv[])
{
extern struct vlog_module VLM_reconnect;
- enum ovsdb_idl_txn_status status;
struct ovsdb_idl *idl;
struct vsctl_command *commands;
+ unsigned int seqno;
size_t n_commands;
char *args;
idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class, false);
run_prerequisites(commands, n_commands, idl);
- /* Now execute the commands. */
- status = TXN_AGAIN_WAIT;
+ /* Execute the commands.
+ *
+ * 'seqno' is the database sequence number for which we last tried to
+ * execute our transaction. There's no point in trying to commit more than
+ * once for any given sequence number, because if the transaction fails
+ * it's because the database changed and we need to obtain an up-to-date
+ * view of the database before we try the transaction again. */
+ seqno = ovsdb_idl_get_seqno(idl);
for (;;) {
- if (ovsdb_idl_run(idl) || status == TXN_AGAIN_NOW) {
- status = do_vsctl(args, commands, n_commands, idl);
+ ovsdb_idl_run(idl);
+
+ if (seqno != ovsdb_idl_get_seqno(idl)) {
+ seqno = ovsdb_idl_get_seqno(idl);
+ do_vsctl(args, commands, n_commands, idl);
}
- if (status != TXN_AGAIN_NOW) {
+ if (seqno == ovsdb_idl_get_seqno(idl)) {
ovsdb_idl_wait(idl);
poll_block();
}
}
}
-static enum ovsdb_idl_txn_status
+static void
do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
struct ovsdb_idl *idl)
{
vsctl_context_done(&ctx, c);
if (ctx.try_again) {
- status = TXN_AGAIN_WAIT;
+ status = TXN_TRY_AGAIN;
goto try_again;
}
}
case TXN_SUCCESS:
break;
- case TXN_AGAIN_WAIT:
- case TXN_AGAIN_NOW:
+ case TXN_TRY_AGAIN:
goto try_again;
case TXN_ERROR:
free(c->table);
}
free(error);
-
- return status;
}
static const struct vsctl_command_syntax all_commands[] = {
/* OVSDB IDL used to obtain configuration. */
static struct ovsdb_idl *idl;
+/* Most recently processed IDL sequence number. */
+static unsigned int idl_seqno;
+
/* Each time this timer expires, the bridge fetches systems and interface
* statistics and pushes them into the database. */
#define STATS_INTERVAL (5 * 1000) /* In milliseconds. */
{
/* Create connection to database. */
idl = ovsdb_idl_create(remote, &ovsrec_idl_class, true);
+ idl_seqno = ovsdb_idl_get_seqno(idl);
ovsdb_idl_set_lock(idl, "ovs_vswitchd");
ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_cur_cfg);
const struct ovsrec_open_vswitch *cfg;
bool vlan_splinters_changed;
- bool database_changed;
struct bridge *br;
/* (Re)configure if necessary. */
- database_changed = ovsdb_idl_run(idl);
+ ovsdb_idl_run(idl);
if (ovsdb_idl_is_lock_contended(idl)) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
struct bridge *br, *next_br;
}
}
- if (database_changed || vlan_splinters_changed) {
+ if (ovsdb_idl_get_seqno(idl) != idl_seqno || vlan_splinters_changed) {
+ idl_seqno = ovsdb_idl_get_seqno(idl);
if (cfg) {
struct ovsdb_idl_txn *txn = ovsdb_idl_txn_create(idl);