diff mbox

[ovs-dev,v2,2/2] ovsdb-idl: Enhance conditional monitoring API

Message ID 1483742326-19379-2-git-send-email-azhou@ovn.org
State Accepted
Headers show

Commit Message

Andy Zhou Jan. 6, 2017, 10:38 p.m. UTC
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    | 44 +++++++++++++++++++++++++++++++++++++++++---
 lib/ovsdb-idl.h    |  7 ++++---
 tests/test-ovsdb.c |  9 +++++++--
 3 files changed, 52 insertions(+), 8 deletions(-)

Comments

Ben Pfaff Jan. 7, 2017, 12:17 a.m. UTC | #1
On Fri, Jan 06, 2017 at 02:38:46PM -0800, Andy Zhou wrote:
> 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>

Acked-by: Ben Pfaff <blp@ovn.org>
Andy Zhou Jan. 9, 2017, 8:57 p.m. UTC | #2
On Fri, Jan 6, 2017 at 4:17 PM, Ben Pfaff <blp@ovn.org> wrote:

> On Fri, Jan 06, 2017 at 02:38:46PM -0800, Andy Zhou wrote:
> > 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>
>
> Acked-by: Ben Pfaff <blp@ovn.org>
>
Thanks. Pushed.
diff mbox

Patch

diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 0292724..ab1ff01 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -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) {
@@ -460,6 +468,7 @@  ovsdb_idl_run(struct ovsdb_idl *idl)
                 /* 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:
@@ -567,6 +576,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
@@ -1047,20 +1076,29 @@  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.
+ *
+ * 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 *
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index f0326b4..743961b 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -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 */
diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c
index e297f9f..09e4f0d 100644
--- a/tests/test-ovsdb.c
+++ b/tests/test-ovsdb.c
@@ -1,5 +1,5 @@ 
 /*
- * 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.
@@ -2294,7 +2294,12 @@  update_conditions(struct ovsdb_idl *idl, char *commands)
                 }
             }
         }
-        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);
     }