/* Transaction support. */
struct ovsdb_idl_txn *txn;
struct hmap outstanding_txns;
+
+ /* Conditional monitoring. */
bool cond_changed;
+ unsigned int cond_seqno; /* Keep track of condition clauses changes
+ over a single conditional monitoring session.
+ Reverts to zero when idl session
+ reconnects. */
};
struct ovsdb_idl_txn {
}
idl->cond_changed = false;
+ idl->cond_seqno = 0;
idl->state_seqno = UINT_MAX;
idl->request_id = NULL;
idl->schema = NULL;
}
idl->cond_changed = false;
+ idl->cond_seqno = 0;
ovsdb_idl_track_clear(idl);
if (changed) {
/* Conditional monitor clauses were updated. Send out
* the next condition changes, in any, immediately. */
ovsdb_idl_send_cond_change(idl);
+ idl->cond_seqno++;
break;
case IDL_S_MONITORING:
return idl->change_seqno;
}
+/* Returns a "sequence number" that represents the number of conditional
+ * monitoring updates successfully received by the OVSDB server of an IDL
+ * connection.
+ *
+ * ovsdb_idl_set_condition() sets a new condition that is different from
+ * the current condtion, the next expected "sequence number" is returned.
+ *
+ * Whenever ovsdb_idl_get_cond_seqno() returns a value that matches
+ * the return value of ovsdb_idl_set_condition(), The client is
+ * assured that:
+ * - The ovsdb_idl_set_condition() changes has been acknowledged by
+ * the OVSDB sever.
+ *
+ * - 'idl' now contains the content matches the new conditions. */
+unsigned int
+ovsdb_idl_get_condition_seqno(const struct ovsdb_idl *idl)
+{
+ return idl->cond_seqno;
+}
+
/* Returns true if 'idl' successfully connected to the remote database and
* retrieved its contents (even if the connection subsequently dropped and is
* in the process of reconnecting). If so, then 'idl' contains an atomic
}
}
-/* Sets the replication condition for 'tc' in 'idl' to 'condition' and arranges
- * to send the new condition to the database server. */
-void
+/* Sets the replication condition for 'tc' in 'idl' to 'condition' and
+ * arranges to send the new condition to the database server.
+ *
+ * Return the next conditional update sequence number. When this
+ * value and ovsdb_idl_get_condition_seqno() matchs, the 'idl'
+ * contains rows that match the 'condition'.
+ */
+unsigned int
ovsdb_idl_set_condition(struct ovsdb_idl *idl,
const struct ovsdb_idl_table_class *tc,
const struct ovsdb_idl_condition *condition)
{
struct ovsdb_idl_table *table = ovsdb_idl_table_from_class(idl, tc);
+ unsigned int seqno = idl->cond_seqno;
if (!ovsdb_idl_condition_equals(condition, &table->condition)) {
ovsdb_idl_condition_destroy(&table->condition);
ovsdb_idl_condition_clone(&table->condition, condition);
idl->cond_changed = table->cond_changed = true;
poll_immediate_wake();
+ return seqno + 1;
}
+
+ return seqno;
}
static struct json *
void ovsdb_idl_condition_add_clause_true(struct ovsdb_idl_condition *);
bool ovsdb_idl_condition_is_true(const struct ovsdb_idl_condition *);
-void ovsdb_idl_set_condition(struct ovsdb_idl *,
- const struct ovsdb_idl_table_class *,
- const struct ovsdb_idl_condition *);
+unsigned int ovsdb_idl_set_condition(struct ovsdb_idl *,
+ const struct ovsdb_idl_table_class *,
+ const struct ovsdb_idl_condition *);
+unsigned int ovsdb_idl_get_condition_seqno(const struct ovsdb_idl *);
#endif /* ovsdb-idl.h */
/*
- * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2015, 2016 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
}
}
- ovsdb_idl_set_condition(idl, tc, &cond);
+
+ unsigned int seqno = ovsdb_idl_get_condition_seqno(idl);
+ unsigned int next_seqno = ovsdb_idl_set_condition(idl, tc, &cond);
+ if (seqno == next_seqno ) {
+ ovs_fatal(0, "condition unchanged");
+ }
ovsdb_idl_condition_destroy(&cond);
json_destroy(json);
}