[ovs-dev,3/7] ovsdb-idl: Support optionally not shuffling multiple remotes.
diff mbox series

Message ID 1554859282-15144-3-git-send-email-hzhou8@ebay.com
State New
Headers show
Series
  • [ovs-dev,1/7] ovsdb raft: Sync commit index to followers without delay.
Related show

Commit Message

Han Zhou April 10, 2019, 1:21 a.m. UTC
From: Han Zhou <hzhou8@ebay.com>

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

Signed-off-by: Han Zhou <hzhou8@ebay.com>
---
 lib/jsonrpc.c   |  1 -
 lib/ovsdb-idl.c | 14 ++++++++++++++
 lib/ovsdb-idl.h |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)

Comments

Ben Pfaff April 12, 2019, 4:40 p.m. UTC | #1
On Tue, Apr 09, 2019 at 06:21:18PM -0700, Han Zhou wrote:
> From: Han Zhou <hzhou8@ebay.com>
> 
> This patch allows remotes not being shuffled if desired. By default
> it still shuffles as how it behaves today.
> 
> Signed-off-by: Han Zhou <hzhou8@ebay.com>

This comment in jsonrpc_session_open_multiple() should be updated:
    /* Set 'n' remotes from 'names', shuffling them into random order. */

I'd add some rationale to the commit message explaining why the change
is useful.  Maybe it's for testing?
Han Zhou April 12, 2019, 5:03 p.m. UTC | #2
On Fri, Apr 12, 2019 at 9:40 AM Ben Pfaff <blp@ovn.org> wrote:
>
> On Tue, Apr 09, 2019 at 06:21:18PM -0700, Han Zhou wrote:
> > From: Han Zhou <hzhou8@ebay.com>
> >
> > This patch allows remotes not being shuffled if desired. By default
> > it still shuffles as how it behaves today.
> >
> > Signed-off-by: Han Zhou <hzhou8@ebay.com>
>
> This comment in jsonrpc_session_open_multiple() should be updated:
>     /* Set 'n' remotes from 'names', shuffling them into random order. */

OK.

>
> I'd add some rationale to the commit message explaining why the change
> is useful.  Maybe it's for testing?

OK.

Patch
diff mbox series

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);