[ovs-dev,v3] ovsdb-tool: Convert clustered db to standalone db.
diff mbox series

Message ID 20190826210152.11417-1-amginwal@gmail.com
State New
Headers show
Series
  • [ovs-dev,v3] ovsdb-tool: Convert clustered db to standalone db.
Related show

Commit Message

aginwala aginwala Aug. 26, 2019, 9:01 p.m. UTC
From: Aliasgar Ginwala <aginwala@ebay.com>

Add support in ovsdb-tool for migrating clustered dbs to standalone dbs.
E.g. usage to migrate nb/sb db to standalone db from raft:
ovsdb-tool cluster-to-standalone ovnnb_db.db ovnnb_db_cluster.db

Signed-off-by: Aliasgar Ginwala <aginwala@ebay.com>
---
 Documentation/ref/ovsdb.7.rst |   3 +
 ovsdb/ovsdb-tool.c            | 112 +++++++++++++++++++++++++++++++++-
 2 files changed, 114 insertions(+), 1 deletion(-)

Comments

0-day Robot Aug. 26, 2019, 9:59 p.m. UTC | #1
Bleep bloop.  Greetings aginwala aginwala, 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.


build:
/bin/sh ./libtool  --tag=CC   --mode=link gcc -std=gnu99 -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wshadow -Werror -Werror   -g -O2     -o utilities/ovs-dpctl utilities/ovs-dpctl.o lib/libopenvswitch.la -lpthread -lrt -lm  -lunbound
libtool: link: gcc -std=gnu99 -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wshadow -Werror -Werror -g -O2 -o utilities/ovs-dpctl utilities/ovs-dpctl.o  lib/.libs/libopenvswitch.a -lssl -lcrypto -lcap-ng -lpthread -lrt -lm -lunbound
depbase=`echo utilities/ovs-ofctl.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -I ./include -I ./include -I ./lib -I ./lib    -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wshadow -Werror -Werror   -g -O2 -MT utilities/ovs-ofctl.o -MD -MP -MF $depbase.Tpo -c -o utilities/ovs-ofctl.o utilities/ovs-ofctl.c &&\
mv -f $depbase.Tpo $depbase.Po
/bin/sh ./libtool  --tag=CC   --mode=link gcc -std=gnu99 -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wshadow -Werror -Werror   -g -O2     -o utilities/ovs-ofctl utilities/ovs-ofctl.o ofproto/libofproto.la lib/libopenvswitch.la -lpthread -lrt -lm  -lunbound
libtool: link: gcc -std=gnu99 -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wshadow -Werror -Werror -g -O2 -o utilities/ovs-ofctl utilities/ovs-ofctl.o  ofproto/.libs/libofproto.a /var/lib/jenkins/jobs/upstream_build_from_pw/workspace/lib/.libs/libsflow.a lib/.libs/libopenvswitch.a -lssl -lcrypto -lcap-ng -lpthread -lrt -lm -lunbound
depbase=`echo utilities/ovs-vsctl.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -I ./include -I ./include -I ./lib -I ./lib    -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wshadow -Werror -Werror   -g -O2 -MT utilities/ovs-vsctl.o -MD -MP -MF $depbase.Tpo -c -o utilities/ovs-vsctl.o utilities/ovs-vsctl.c &&\
mv -f $depbase.Tpo $depbase.Po
/bin/sh ./libtool  --tag=CC   --mode=link gcc -std=gnu99 -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wshadow -Werror -Werror   -g -O2     -o utilities/ovs-vsctl utilities/ovs-vsctl.o lib/libopenvswitch.la -lpthread -lrt -lm  -lunbound
libtool: link: gcc -std=gnu99 -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wshadow -Werror -Werror -g -O2 -o utilities/ovs-vsctl utilities/ovs-vsctl.o  lib/.libs/libopenvswitch.a -lssl -lcrypto -lcap-ng -lpthread -lrt -lm -lunbound
depbase=`echo ovsdb/ovsdb-tool.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -I ./include -I ./include -I ./lib -I ./lib    -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wshadow -Werror -Werror   -g -O2 -MT ovsdb/ovsdb-tool.o -MD -MP -MF $depbase.Tpo -c -o ovsdb/ovsdb-tool.o ovsdb/ovsdb-tool.c &&\
mv -f $depbase.Tpo $depbase.Po
ovsdb/ovsdb-tool.c: In function ‘do_convert_to_standalone’:
ovsdb/ovsdb-tool.c:1584:29: error: unused variable ‘error’ [-Werror=unused-variable]
         struct ovsdb_error *error;
                             ^
cc1: all warnings being treated as errors
make[2]: *** [ovsdb/ovsdb-tool.o] Error 1
make[2]: Leaving directory `/var/lib/jenkins/jobs/upstream_build_from_pw/workspace'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/var/lib/jenkins/jobs/upstream_build_from_pw/workspace'
make: *** [all] Error 2


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

Thanks,
0-day Robot
aginwala Aug. 26, 2019, 11:04 p.m. UTC | #2
Seems some issue in my local env where  --enable-Werror --enable-sparse
didn't catch this warning. Addressed in v4.

On Mon, Aug 26, 2019 at 3:01 PM 0-day Robot <robot@bytheb.org> wrote:

> Bleep bloop.  Greetings aginwala aginwala, 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.
>
>
> build:
> /bin/sh ./libtool  --tag=CC   --mode=link gcc -std=gnu99
> -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith
> -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
> -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition
> -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing
> -Wshadow -Werror -Werror   -g -O2     -o utilities/ovs-dpctl
> utilities/ovs-dpctl.o lib/libopenvswitch.la -lpthread -lrt -lm  -lunbound
> libtool: link: gcc -std=gnu99 -Wstrict-prototypes -Wall -Wextra
> -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum
> -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes
> -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers
> -fno-strict-aliasing -Wshadow -Werror -Werror -g -O2 -o utilities/ovs-dpctl
> utilities/ovs-dpctl.o  lib/.libs/libopenvswitch.a -lssl -lcrypto -lcap-ng
> -lpthread -lrt -lm -lunbound
> depbase=`echo utilities/ovs-ofctl.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
> gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -I ./include -I ./include -I ./lib
> -I ./lib    -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare
> -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
> -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition
> -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing
> -Wshadow -Werror -Werror   -g -O2 -MT utilities/ovs-ofctl.o -MD -MP -MF
> $depbase.Tpo -c -o utilities/ovs-ofctl.o utilities/ovs-ofctl.c &&\
> mv -f $depbase.Tpo $depbase.Po
> /bin/sh ./libtool  --tag=CC   --mode=link gcc -std=gnu99
> -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith
> -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
> -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition
> -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing
> -Wshadow -Werror -Werror   -g -O2     -o utilities/ovs-ofctl
> utilities/ovs-ofctl.o ofproto/libofproto.la lib/libopenvswitch.la
> -lpthread -lrt -lm  -lunbound
> libtool: link: gcc -std=gnu99 -Wstrict-prototypes -Wall -Wextra
> -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum
> -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes
> -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers
> -fno-strict-aliasing -Wshadow -Werror -Werror -g -O2 -o utilities/ovs-ofctl
> utilities/ovs-ofctl.o  ofproto/.libs/libofproto.a
> /var/lib/jenkins/jobs/upstream_build_from_pw/workspace/lib/.libs/libsflow.a
> lib/.libs/libopenvswitch.a -lssl -lcrypto -lcap-ng -lpthread -lrt -lm
> -lunbound
> depbase=`echo utilities/ovs-vsctl.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
> gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -I ./include -I ./include -I ./lib
> -I ./lib    -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare
> -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
> -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition
> -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing
> -Wshadow -Werror -Werror   -g -O2 -MT utilities/ovs-vsctl.o -MD -MP -MF
> $depbase.Tpo -c -o utilities/ovs-vsctl.o utilities/ovs-vsctl.c &&\
> mv -f $depbase.Tpo $depbase.Po
> /bin/sh ./libtool  --tag=CC   --mode=link gcc -std=gnu99
> -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith
> -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
> -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition
> -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing
> -Wshadow -Werror -Werror   -g -O2     -o utilities/ovs-vsctl
> utilities/ovs-vsctl.o lib/libopenvswitch.la -lpthread -lrt -lm  -lunbound
> libtool: link: gcc -std=gnu99 -Wstrict-prototypes -Wall -Wextra
> -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum
> -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes
> -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers
> -fno-strict-aliasing -Wshadow -Werror -Werror -g -O2 -o utilities/ovs-vsctl
> utilities/ovs-vsctl.o  lib/.libs/libopenvswitch.a -lssl -lcrypto -lcap-ng
> -lpthread -lrt -lm -lunbound
> depbase=`echo ovsdb/ovsdb-tool.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
> gcc -std=gnu99 -DHAVE_CONFIG_H -I.    -I ./include -I ./include -I ./lib
> -I ./lib    -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare
> -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
> -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition
> -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing
> -Wshadow -Werror -Werror   -g -O2 -MT ovsdb/ovsdb-tool.o -MD -MP -MF
> $depbase.Tpo -c -o ovsdb/ovsdb-tool.o ovsdb/ovsdb-tool.c &&\
> mv -f $depbase.Tpo $depbase.Po
> ovsdb/ovsdb-tool.c: In function ‘do_convert_to_standalone’:
> ovsdb/ovsdb-tool.c:1584:29: error: unused variable ‘error’
> [-Werror=unused-variable]
>          struct ovsdb_error *error;
>                              ^
> cc1: all warnings being treated as errors
> make[2]: *** [ovsdb/ovsdb-tool.o] Error 1
> make[2]: Leaving directory
> `/var/lib/jenkins/jobs/upstream_build_from_pw/workspace'
> make[1]: *** [all-recursive] Error 1
> make[1]: Leaving directory
> `/var/lib/jenkins/jobs/upstream_build_from_pw/workspace'
> make: *** [all] Error 2
>
>
> Please check this out.  If you feel there has been an error, please email
> aconole@redhat.com
>
> Thanks,
> 0-day Robot
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>

Patch
diff mbox series

diff --git a/Documentation/ref/ovsdb.7.rst b/Documentation/ref/ovsdb.7.rst
index cd1c63d64..b12d8066c 100644
--- a/Documentation/ref/ovsdb.7.rst
+++ b/Documentation/ref/ovsdb.7.rst
@@ -514,6 +514,9 @@  standalone database from the contents of a running clustered database.
 When the cluster is down and cannot be revived, ``ovsdb-client backup`` will
 not work.
 
+Use ``ovsdb-tool cluster-to-standalone`` to convert clustered database to
+standalone database when the cluster is down and cannot be revived.
+
 Upgrading or Downgrading a Database
 -----------------------------------
 
diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index 438f97590..1956e5492 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -173,6 +173,9 @@  usage(void)
            "  compare-versions A OP B  compare OVSDB schema version numbers\n"
            "  query [DB] TRNS         execute read-only transaction on DB\n"
            "  transact [DB] TRNS      execute read/write transaction on DB\n"
+           "  cluster-to-standalone [DB [DB]]    Convert clustered DB to\n"
+                   "standalone DB when cluster is down and cannot be\n"
+                    "revived\n"
            "  [-m]... show-log [DB]   print DB's log entries\n"
            "The default DB is %s.\n"
            "The default SCHEMA is %s.\n",
@@ -942,6 +945,63 @@  print_raft_record(const struct raft_record *r,
     }
 }
 
+static void
+write_raft_header_to_file(const struct json *data,
+                          struct ovsdb_log *db_log_data)
+{
+    if (!data || json_array(data)->n != 2) {
+       ovs_fatal(0, "***Invalid data***\n");
+    }
+
+    struct json *schema_json = json_array(data)->elems[0];
+    if (schema_json->type != JSON_NULL) {
+        struct ovsdb_schema *schema;
+        check_ovsdb_error(ovsdb_schema_from_json(schema_json, &schema));
+        check_ovsdb_error(ovsdb_log_write_and_free(db_log_data, schema_json));
+    }
+
+    struct json *data_json = json_array(data)->elems[1];
+    if (!data_json || data_json->type != JSON_OBJECT) {
+        ovs_fatal(0, "***invalid data***\n");
+    }
+    if (data_json->type != JSON_NULL) {
+        check_ovsdb_error(ovsdb_log_write_and_free(db_log_data, data_json));
+    }
+}
+
+static void
+write_raft_header(const struct raft_header *h, struct ovsdb_log *db_log_data)
+{
+    if (h->snap_index) {
+        write_raft_header_to_file(h->snap.data, db_log_data);
+    }
+}
+
+static void
+write_raft_record_to_file(const struct json *data,
+                          struct ovsdb_log *db_log_data)
+{
+    if (json_array(data)->n != 2) {
+        ovs_fatal(0, "***invalid data***\n");
+    }
+
+    struct json *data_json = json_array(data)->elems[1];
+    if (data_json->type != JSON_NULL) {
+        check_ovsdb_error(ovsdb_log_write_and_free(db_log_data, data_json));
+    }
+}
+
+static void
+write_raft_record(const struct raft_record *r, struct ovsdb_log *db_log_data)
+{
+    if (r->type == RAFT_REC_ENTRY) {
+        if (!r->entry.data) {
+            return;
+        }
+        write_raft_record_to_file(r->entry.data, db_log_data);
+    }
+}
+
 static void
 do_show_log_cluster(struct ovsdb_log *log)
 {
@@ -1511,6 +1571,54 @@  do_compare_versions(struct ovs_cmdl_context *ctx)
     exit(result ? 0 : 2);
 }
 
+static void
+do_convert_to_standalone(struct ovsdb_log *log, struct ovsdb_log *db_log_data)
+{
+    for (unsigned int i = 0; ; i++) {
+        struct json *json;
+        check_ovsdb_error(ovsdb_log_read(log, &json));
+        if (!json) {
+            break;
+        }
+
+        struct ovsdb_error *error;
+        if (i == 0) {
+            struct raft_header h;
+            check_ovsdb_error(raft_header_from_json(&h, json));
+            write_raft_header(&h, db_log_data);
+            check_ovsdb_error(ovsdb_log_commit_block(db_log_data));
+            raft_header_uninit(&h);
+
+        } else {
+            struct raft_record r;
+            check_ovsdb_error(raft_record_from_json(&r, json));
+            write_raft_record(&r, db_log_data);
+            check_ovsdb_error(ovsdb_log_commit_block(db_log_data));
+            raft_record_uninit(&r);
+        }
+    }
+}
+
+static void
+do_cluster_standalone(struct ovs_cmdl_context *ctx)
+{
+    const char *db_file_name = ctx->argv[1];
+    const char *cluster_db_file_name = ctx->argv[2];
+    struct ovsdb_log *log;
+    struct ovsdb_log *db_log_data;
+
+    check_ovsdb_error(ovsdb_log_open(cluster_db_file_name,
+                                     OVSDB_MAGIC"|"RAFT_MAGIC,
+                                     OVSDB_LOG_READ_ONLY, -1, &log));
+    check_ovsdb_error(ovsdb_log_open(db_file_name, OVSDB_MAGIC,
+                                     OVSDB_LOG_CREATE_EXCL, -1, &db_log_data));
+    if (strcmp(ovsdb_log_get_magic(log), RAFT_MAGIC) != 0) {
+        ovs_fatal(0, "Database is not clustered db.\n");
+    }
+    do_convert_to_standalone(log, db_log_data);
+    ovsdb_log_close(db_log_data);
+    ovsdb_log_close(log);
+}
 
 static void
 do_help(struct ovs_cmdl_context *ctx OVS_UNUSED)
@@ -1550,7 +1658,9 @@  static const struct ovs_cmdl_command all_commands[] = {
     { "compare-versions", "a op b", 3, 3, do_compare_versions, OVS_RO },
     { "help", NULL, 0, INT_MAX, do_help, OVS_RO },
     { "list-commands", NULL, 0, INT_MAX, do_list_commands, OVS_RO },
-    { NULL, NULL, 0, 0, NULL, OVS_RO },
+    { "cluster-to-standalone", "[db [clusterdb]]", 2, 2,
+    do_cluster_standalone, OVS_RW },
+    { NULL, NULL, 2, 2, NULL, OVS_RO },
 };
 
 static const struct ovs_cmdl_command *get_all_commands(void)