diff mbox series

[ovs-dev] ovsdb-server:Add parameter "relay-leader-only-mode"

Message ID ADkAmQAHIGvApstIWf9y9aou.1.1641527281999.Hmail.wentao.jia@easystack.cn
State New
Headers show
Series [ovs-dev] ovsdb-server:Add parameter "relay-leader-only-mode" | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Wentao Jia Jan. 7, 2022, 3:48 a.m. UTC
a lot of transactions maybe fail in cluster ovsdb because of
prerequisite check mechanism, relay server connect to leader can
avoid this issue


Signed-off-by: Wentao Jia <wentao.jia@easystack.cn>
---
 ovsdb/ovsdb-server.c | 21 +++++++++++++++++----
 ovsdb/relay.c        |  4 ++--
 ovsdb/relay.h        |  2 +-
 3 files changed, 20 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 9fe90592e..32d51bc72 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -107,6 +107,7 @@  struct server_config {
     bool *is_backup;
     int *replication_probe_interval;
     struct ovsdb_jsonrpc_server *jsonrpc;
+    bool *relay_leader_only_mode;
 };
 static unixctl_cb_func ovsdb_server_add_remote;
 static unixctl_cb_func ovsdb_server_remove_remote;
@@ -128,7 +129,7 @@  static void parse_options(int argc, char *argvp[],
                           struct sset *db_filenames, struct sset *remotes,
                           char **unixctl_pathp, char **run_command,
                           char **sync_from, char **sync_exclude,
-                          bool *is_backup);
+                          bool *is_backup, bool *relay_leader_only_mode);
 OVS_NO_RETURN static void usage(void);
 
 static char *reconfigure_remotes(struct ovsdb_jsonrpc_server *,
@@ -331,8 +332,10 @@  main(int argc, char *argv[])
     process_init();
 
     bool active = false;
+    bool relay_leader_only_mode = false;
     parse_options(argc, argv, &db_filenames, &remotes, &unixctl_path,
-                  &run_command, &sync_from, &sync_exclude, &active);
+                  &run_command, &sync_from, &sync_exclude, &active,
+                  &relay_leader_only_mode);
     is_backup = sync_from && !active;
 
     daemon_become_new_user(false);
@@ -371,6 +374,7 @@  main(int argc, char *argv[])
     server_config.sync_exclude = &sync_exclude;
     server_config.is_backup = &is_backup;
     server_config.replication_probe_interval = &replication_probe_interval;
+    server_config.relay_leader_only_mode = &relay_leader_only_mode;
 
     perf_counters_init();
 
@@ -753,7 +757,8 @@  open_db(struct server_config *config, const char *filename)
     add_db(config, db);
 
     if (is_relay) {
-        ovsdb_relay_add_db(db->db, relay_remotes, update_schema, config);
+        ovsdb_relay_add_db(db->db, relay_remotes, update_schema, config,
+                           *config->relay_leader_only_mode);
     }
     return NULL;
 }
@@ -1827,7 +1832,8 @@  static void
 parse_options(int argc, char *argv[],
               struct sset *db_filenames, struct sset *remotes,
               char **unixctl_pathp, char **run_command,
-              char **sync_from, char **sync_exclude, bool *active)
+              char **sync_from, char **sync_exclude,
+              bool *active, bool *relay_leader_only_mode)
 {
     enum {
         OPT_REMOTE = UCHAR_MAX + 1,
@@ -1840,6 +1846,7 @@  parse_options(int argc, char *argv[],
         OPT_ACTIVE,
         OPT_NO_DBS,
         OPT_FILE_COLUMN_DIFF,
+        OPT_RELAY_LEADER_ONLY_MODE,
         VLOG_OPTION_ENUMS,
         DAEMON_OPTION_ENUMS,
         SSL_OPTION_ENUMS,
@@ -1865,6 +1872,8 @@  parse_options(int argc, char *argv[],
         {"active", no_argument, NULL, OPT_ACTIVE},
         {"no-dbs", no_argument, NULL, OPT_NO_DBS},
         {"disable-file-column-diff", no_argument, NULL, OPT_FILE_COLUMN_DIFF},
+        {"relay-leader-only-mode", no_argument, NULL,
+          OPT_RELAY_LEADER_ONLY_MODE},
         {NULL, 0, NULL, 0},
     };
     char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
@@ -1961,6 +1970,10 @@  parse_options(int argc, char *argv[],
             ovsdb_file_column_diff_disable();
             break;
 
+        case OPT_RELAY_LEADER_ONLY_MODE:
+            *relay_leader_only_mode = true;
+            break;
+
         case '?':
             exit(EXIT_FAILURE);
 
diff --git a/ovsdb/relay.c b/ovsdb/relay.c
index ef0e44d34..1aff38cfd 100644
--- a/ovsdb/relay.c
+++ b/ovsdb/relay.c
@@ -127,7 +127,7 @@  static struct ovsdb_cs_ops relay_cs_ops = {
 void
 ovsdb_relay_add_db(struct ovsdb *db, const char *remote,
                    schema_change_callback schema_change_cb,
-                   void *schema_change_aux)
+                   void *schema_change_aux, bool relay_leader_only_mode)
 {
     struct relay_ctx *ctx;
 
@@ -150,7 +150,7 @@  ovsdb_relay_add_db(struct ovsdb *db, const char *remote,
     ctx->cs = ovsdb_cs_create(db->name, 3, &relay_cs_ops, ctx);
     ctx->last_connected = 0;
     shash_add(&relay_dbs, db->name, ctx);
-    ovsdb_cs_set_leader_only(ctx->cs, false);
+    ovsdb_cs_set_leader_only(ctx->cs, relay_leader_only_mode);
     ovsdb_cs_set_remote(ctx->cs, remote, true);
 
     VLOG_DBG("added database: %s, %s", db->name, remote);
diff --git a/ovsdb/relay.h b/ovsdb/relay.h
index 390ea70c8..f1372d92a 100644
--- a/ovsdb/relay.h
+++ b/ovsdb/relay.h
@@ -28,7 +28,7 @@  typedef void (*schema_change_callback)(struct ovsdb *,
 
 void ovsdb_relay_add_db(struct ovsdb *, const char *remote,
                         schema_change_callback schema_change_cb,
-                        void *schema_change_aux);
+                        void *schema_change_aux, bool relay_leader_only_mode);
 void ovsdb_relay_del_db(struct ovsdb *);
 void ovsdb_relay_run(void);
 void ovsdb_relay_wait(void);