[ovs-dev,4/7] ovn-nbctl: Support --no-shuffle-remotes.
diff mbox series

Message ID 1554859282-15144-4-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>

Support --no-shuffle-remotes option for ovn-nbctl, which is mainly for testing
purpose, so that we can specify the order that client will failover when the
connected node is down, to have more predictability in the test cases.

Signed-off-by: Han Zhou <hzhou8@ebay.com>
---
 ovn/utilities/ovn-nbctl.8.xml | 17 +++++++++++++++++
 ovn/utilities/ovn-nbctl.c     | 26 ++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 2 deletions(-)

Comments

0-day Robot April 10, 2019, 3:23 a.m. UTC | #1
Bleep bloop.  Greetings Han Zhou, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line lacks whitespace around operator
#110 FILE: ovn/utilities/ovn-nbctl.c:727:
  --no-shuffle-remotes        do not shuffle the order of remotes\n\

Lines checked: 126, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@bytheb.org

Thanks,
0-day Robot
Ben Pfaff April 12, 2019, 4:41 p.m. UTC | #2
On Tue, Apr 09, 2019 at 06:21:19PM -0700, Han Zhou wrote:
> From: Han Zhou <hzhou8@ebay.com>
> 
> Support --no-shuffle-remotes option for ovn-nbctl, which is mainly for testing
> purpose, so that we can specify the order that client will failover when the
> connected node is down, to have more predictability in the test cases.
> 
> Signed-off-by: Han Zhou <hzhou8@ebay.com>

Looks good, thanks.

Patch
diff mbox series

diff --git a/ovn/utilities/ovn-nbctl.8.xml b/ovn/utilities/ovn-nbctl.8.xml
index a7a9c27..55c92f7 100644
--- a/ovn/utilities/ovn-nbctl.8.xml
+++ b/ovn/utilities/ovn-nbctl.8.xml
@@ -1142,6 +1142,23 @@ 
       <code>Understanding Cluster Consistency</code> in <code>ovsdb</code>(7)
       for more information.
     </dd>
+
+    <dt><code>--shuffle-remotes</code></dt>
+    <dt><code>--no-shuffle-remotes</code></dt>
+    <dd>
+      By default, or with <code>--shuffle-remotes</code>, when there are
+      multiple remotes specified in the OVSDB connection string specified by
+      <code>--db</code> or the <env>OVN_NB_DB</env> environment variable,
+      the order of the remotes will be shuffled before the client tries to
+      connect.  The remotes will be shuffled only once to a new order before
+      the first connection attempt.  The following retries, if any, will
+      follow the same new order.  The default behavior is to make sure
+      clients of a clustered database can distribute evenly to all memembers
+      of the cluster.  With <code>--no-shuffle-remotes</code>,
+      <code>ovn-nbctl</code> will use the original order specified in the
+      connection string to connect.  This allows user to specify the
+      preferred order, which is particularly useful for testing.
+    </dd>
     </dl>
 
     <h2>Daemon Options</h2>
diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 2727b41..e185b9d 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -83,6 +83,10 @@  OVS_NO_RETURN static void nbctl_exit(int status);
 /* --leader-only, --no-leader-only: Only accept the leader in a cluster. */
 static int leader_only = true;
 
+/* --shuffle-remotes, --no-shuffle-remotes: Shuffle the order of remotes that
+ * are specified in the connetion method string. */
+static int shuffle_remotes = true;
+
 /* --unixctl-path: Path to use for unixctl server, for "monitor" and "snoop"
      commands. */
 static char *unixctl_path;
@@ -182,8 +186,11 @@  main(int argc, char *argv[])
         }
         daemon_mode = true;
     }
-    /* Initialize IDL. "retry" is true iff in daemon mode. */
-    idl = the_idl = ovsdb_idl_create(db, &nbrec_idl_class, true, daemon_mode);
+    /* Initialize IDL. */
+    idl = the_idl = ovsdb_idl_create_unconnected(&nbrec_idl_class, true);
+    ovsdb_idl_set_shuffle_remotes(idl, shuffle_remotes);
+    /* "retry" is true iff in daemon mode. */
+    ovsdb_idl_set_remote(idl, db, daemon_mode);
     ovsdb_idl_set_leader_only(idl, leader_only);
 
     if (daemon_mode) {
@@ -304,6 +311,8 @@  enum {
     OPT_OPTIONS,
     OPT_LEADER_ONLY,
     OPT_NO_LEADER_ONLY,
+    OPT_SHUFFLE_REMOTES,
+    OPT_NO_SHUFFLE_REMOTES,
     OPT_BOOTSTRAP_CA_CERT,
     MAIN_LOOP_OPTION_ENUMS,
     DAEMON_OPTION_ENUMS,
@@ -405,6 +414,8 @@  get_all_options(void)
         {"options", no_argument, NULL, OPT_OPTIONS},
         {"leader-only", no_argument, NULL, OPT_LEADER_ONLY},
         {"no-leader-only", no_argument, NULL, OPT_NO_LEADER_ONLY},
+        {"shuffle-remotes", no_argument, NULL, OPT_SHUFFLE_REMOTES},
+        {"no-shuffle-remotes", no_argument, NULL, OPT_NO_SHUFFLE_REMOTES},
         {"version", no_argument, NULL, 'V'},
         MAIN_LOOP_LONG_OPTIONS,
         DAEMON_LONG_OPTIONS,
@@ -509,6 +520,14 @@  apply_options_direct(const struct ovs_cmdl_parsed_option *parsed_options,
             leader_only = false;
             break;
 
+        case OPT_SHUFFLE_REMOTES:
+            shuffle_remotes = true;
+            break;
+
+        case OPT_NO_SHUFFLE_REMOTES:
+            shuffle_remotes = false;
+            break;
+
         case 'V':
             ovs_print_version(0, 0);
             printf("DB Schema %s\n", nbrec_get_db_version());
@@ -705,6 +724,7 @@  Options:\n\
                               (default: %s)\n\
   --no-wait, --wait=none      do not wait for OVN reconfiguration (default)\n\
   --no-leader-only            accept any cluster member, not just the leader\n\
+  --no-shuffle-remotes        do not shuffle the order of remotes\n\
   --wait=sb                   wait for southbound database update\n\
   --wait=hv                   wait for all chassis to catch up\n\
   -t, --timeout=SECS          wait at most SECS seconds\n\
@@ -5532,6 +5552,8 @@  nbctl_client(const char *socket_name,
 
         case OPT_LEADER_ONLY:
         case OPT_NO_LEADER_ONLY:
+        case OPT_SHUFFLE_REMOTES:
+        case OPT_NO_SHUFFLE_REMOTES:
         case OPT_BOOTSTRAP_CA_CERT:
         STREAM_SSL_CASES
         DAEMON_OPTION_CASES