[ovs-dev] [PATCH v2 5/9] ovsdb-idl: Support optionally not shuffling multiple remotes.

Han Zhou zhouhan at gmail.com
Fri Apr 12 23:26:24 UTC 2019


From: Han Zhou <hzhou8 at ebay.com>

This patch allows remotes not being shuffled if desired (mostly for
testing purpose, when we need the order of remotes during retrying
be predictable). By default it still shuffles as how it behaves today.

Signed-off-by: Han Zhou <hzhou8 at ebay.com>
---
v1->v2: updated comments after Ben's review.

 lib/jsonrpc.c   |  3 +--
 lib/ovsdb-idl.c | 14 ++++++++++++++
 lib/ovsdb-idl.h |  1 +
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index 4c2c1ba..b9619b8 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -824,10 +824,9 @@ jsonrpc_session_open_multiple(const struct svec *remotes, bool retry)
 
     s = xmalloc(sizeof *s);
 
-    /* Set 'n' remotes from 'names', shuffling them into random order. */
+    /* Set 'n' remotes from 'names'. */
     ovs_assert(remotes->n > 0);
     svec_clone(&s->remotes, remotes);
-    svec_shuffle(&s->remotes);
     s->next_remote = 0;
 
     s->reconnect = reconnect_create(time_msec());
diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 5ae86f7..370781b 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -260,6 +260,7 @@ struct ovsdb_idl {
 
     uint64_t min_index;
     bool leader_only;
+    bool shuffle_remotes;
 };
 
 static void ovsdb_idl_transition_at(struct ovsdb_idl *, enum ovsdb_idl_state,
@@ -485,6 +486,7 @@ ovsdb_idl_create_unconnected(const struct ovsdb_idl_class *class,
     idl->state_seqno = UINT_MAX;
     idl->request_id = NULL;
     idl->leader_only = true;
+    idl->shuffle_remotes = true;
 
     /* Monitor the Database table in the _Server database.
      *
@@ -528,6 +530,9 @@ ovsdb_idl_set_remote(struct ovsdb_idl *idl, const char *remote, bool retry)
         if (remote) {
             struct svec remotes = SVEC_EMPTY_INITIALIZER;
             ovsdb_session_parse_remote(remote, &remotes, &idl->cid);
+            if (idl->shuffle_remotes) {
+                svec_shuffle(&remotes);
+            }
             idl->session = jsonrpc_session_open_multiple(&remotes, retry);
             svec_destroy(&remotes);
 
@@ -538,6 +543,15 @@ ovsdb_idl_set_remote(struct ovsdb_idl *idl, const char *remote, bool retry)
     }
 }
 
+/* Set whether the order of remotes should be shuffled, when there
+ * are more than one remotes.  The setting doesn't take effect
+ * until the next time when ovsdb_idl_set_remote() is called. */
+void
+ovsdb_idl_set_shuffle_remotes(struct ovsdb_idl *idl, bool shuffle)
+{
+    idl->shuffle_remotes = shuffle;
+}
+
 static void
 ovsdb_idl_db_destroy(struct ovsdb_idl_db *db)
 {
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index 8a168eb..0f5a6d0 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -63,6 +63,7 @@ struct ovsdb_idl *ovsdb_idl_create(const char *remote,
 struct ovsdb_idl *ovsdb_idl_create_unconnected(
     const struct ovsdb_idl_class *, bool monitor_everything_by_default);
 void ovsdb_idl_set_remote(struct ovsdb_idl *, const char *, bool);
+void ovsdb_idl_set_shuffle_remotes(struct ovsdb_idl *, bool);
 void ovsdb_idl_destroy(struct ovsdb_idl *);
 
 void ovsdb_idl_set_leader_only(struct ovsdb_idl *, bool leader_only);
-- 
2.1.0



More information about the dev mailing list