@@ -109,7 +109,13 @@ struct ovsdb_idl {
/* 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 {
@@ -284,6 +290,7 @@ ovsdb_idl_create(const char *remote, const struct ovsdb_idl_class *class,
}
idl->cond_changed = false;
+ idl->cond_seqno = 0;
idl->state_seqno = UINT_MAX;
idl->request_id = NULL;
idl->schema = NULL;
@@ -372,6 +379,7 @@ ovsdb_idl_clear(struct ovsdb_idl *idl)
}
idl->cond_changed = false;
+ idl->cond_seqno = 0;
ovsdb_idl_track_clear(idl);
if (changed) {
@@ -458,6 +466,7 @@ ovsdb_idl_run(struct ovsdb_idl *idl)
case IDL_S_MONITORING_COND:
/* Conditional monitor clauses were updated. */
+ idl->cond_seqno++;
break;
case IDL_S_MONITORING:
@@ -565,6 +574,26 @@ ovsdb_idl_get_seqno(const struct ovsdb_idl *idl)
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
+ * theOVSDB 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
@@ -1045,9 +1074,20 @@ ovsdb_idl_condition_clone(struct ovsdb_idl_condition *dst,
}
}
-/* 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.
+ *
+ * Returns:
+ *
+ * - UINT_MAX: The new condition is the same as current condition.
+ * No updates will be sent to the ovsdb-server.
+ *
+ * - >0: The next conditional update sequence number.
+ * When this return value and ovsdb_idl_get_condition_seqno()
+ * matchs, the 'idl' only contains rows that matches 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)
@@ -1058,7 +1098,10 @@ ovsdb_idl_set_condition(struct ovsdb_idl *idl,
ovsdb_idl_condition_clone(&table->condition, condition);
idl->cond_changed = table->cond_changed = true;
poll_immediate_wake();
+ return idl->cond_seqno + 1;
}
+
+ return UINT_MAX;
}
static struct json *
@@ -349,8 +349,9 @@ void ovsdb_idl_condition_add_clause(struct ovsdb_idl_condition *,
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 */
@@ -2282,7 +2282,12 @@ update_conditions(struct ovsdb_idl *idl, char *commands)
}
}
}
- ovsdb_idl_set_condition(idl, tc, &cond);
+
+ uint64_t seqno;
+ seqno = ovsdb_idl_set_condition(idl, tc, &cond);
+ if (seqno == UINT_MAX) {
+ ovs_fatal(0, "condition unchanged");
+ }
ovsdb_idl_condition_destroy(&cond);
json_destroy(json);
}
To allow client to know when the conditional monitoring changes has been accepted by the OVSDB server and the 'idl' contents has been updated to match the new conditions. Signed-off-by: Andy Zhou <azhou@ovn.org> --- lib/ovsdb-idl.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- lib/ovsdb-idl.h | 7 ++++--- tests/test-ovsdb.c | 7 ++++++- 3 files changed, 56 insertions(+), 7 deletions(-)