From: Han Zhou <[email protected]>

This patch allows remotes not being shuffled if desired. By default
it still shuffles as how it behaves today.

Signed-off-by: Han Zhou <[email protected]>
---
 lib/jsonrpc.c   |  1 -
 lib/ovsdb-idl.c | 14 ++++++++++++++
 lib/ovsdb-idl.h |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index 4c2c1ba..3c60cd8 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -827,7 +827,6 @@ jsonrpc_session_open_multiple(const struct svec *remotes, 
bool retry)
     /* Set 'n' remotes from 'names', shuffling them into random order. */
     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

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to