Re: [ovs-dev] [PATCH v10] ovsdb-tool: Convert clustered db to standalone db.

2019-09-23 Thread Ben Pfaff
Sorry about the delay.  I applied this to master.

On Thu, Sep 19, 2019 at 05:32:09PM -0700, aginwala wrote:
> Hi Ben:
> 
> Just a gentle reminder. Can you please help merge this patch if no
> additional comments? Got acked-by Han on the same already.
> 
> On Fri, Aug 30, 2019 at 8:30 AM  wrote:
> 
> > From: Aliasgar Ginwala 
> >
> > 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 
> > Acked-by: Han Zhou 
> > ---
> >  Documentation/ref/ovsdb.7.rst |   3 +
> >  NEWS  |   3 +
> >  ovsdb/ovsdb-tool.1.in |   8 +++
> >  ovsdb/ovsdb-tool.c| 101 +-
> >  tests/ovsdb-tool.at   |  38 +
> >  5 files changed, 152 insertions(+), 1 deletion(-)
> >
> > 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/NEWS b/NEWS
> > index c5caa13d6..a02f9f1a6 100644
> > --- a/NEWS
> > +++ b/NEWS
> > @@ -49,6 +49,9 @@ v2.12.0 - xx xxx 
> > quickly after a brief disconnection, saving bandwidth and CPU time.
> > See section 4.1.15 of ovsdb-server(7) for details of related OVSDB
> > protocol extension.
> > + * Support to convert from cluster database to standalone database is
> > now
> > +   available when clustered is down and cannot be revived using
> > ovsdb-tool
> > +   . Check "Database Migration Commands" in ovsdb-tool man section.
> > - OVN:
> >   * IPAM/MACAM:
> > - select IPAM mac_prefix in a random manner if not provided by the
> > user
> > diff --git a/ovsdb/ovsdb-tool.1.in b/ovsdb/ovsdb-tool.1.in
> > index ec85e14c4..31a918d90 100644
> > --- a/ovsdb/ovsdb-tool.1.in
> > +++ b/ovsdb/ovsdb-tool.1.in
> > @@ -147,6 +147,14 @@ avoid this possibility, specify
> > \fB\-\-cid=\fIuuid\fR, where
> >  \fIuuid\fR is the cluster ID of the cluster to join, as printed by
> >  \fBovsdb\-tool get\-cid\fR.
> >  .
> > +.SS "Database Migration Commands"
> > +This commands will convert cluster database to standalone database.
> > +.
> > +.IP "\fBcluster\-to\-standalone\fI db clusterdb"
> > +Use this command to convert to standalone database from clustered database
> > +when the cluster is down and cannot be revived. It creates new standalone
> > +\fIdb\fR file from the given cluster \fIdb\fR file.
> > +.
> >  .SS "Version Management Commands"
> >  .so ovsdb/ovsdb-schemas.man
> >  .PP
> > diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
> > index 438f97590..3bbf4c8bc 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 DBConvert 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,55 @@ print_raft_record(const struct raft_record *r,
> >  }
> >  }
> >
> > +static void
> > +raft_header_to_standalone_log(const struct raft_header *h,
> > +  struct ovsdb_log *db_log_data)
> > +{
> > +if (h->snap_index) {
> > +if (!h->snap.data || json_array(h->snap.data)->n != 2) {
> > +ovs_fatal(0, "Incorrect raft header data array length");
> > +}
> > +
> > +struct json *schema_json = json_array(h->snap.data)->elems[0];
> > +if (schema_json->type != JSON_NULL) {
> > +struct ovsdb_schema *schema;
> > +check_ovsdb_error(ovsdb_schema_from_json(schema_json,
> > ));
> > +ovsdb_schema_destroy(schema);
> > +check_ovsdb_error(ovsdb_log_write_and_free(db_log_data,
> > +   schema_json));
> > +}
> > +
> > +struct json *data_json = json_array(h->snap.data)->elems[1];
> > +if (!data_json || data_json->type != JSON_OBJECT) {
> > +

Re: [ovs-dev] [PATCH v10] ovsdb-tool: Convert clustered db to standalone db.

2019-09-19 Thread aginwala
Hi Ben:

Just a gentle reminder. Can you please help merge this patch if no
additional comments? Got acked-by Han on the same already.

On Fri, Aug 30, 2019 at 8:30 AM  wrote:

> From: Aliasgar Ginwala 
>
> 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 
> Acked-by: Han Zhou 
> ---
>  Documentation/ref/ovsdb.7.rst |   3 +
>  NEWS  |   3 +
>  ovsdb/ovsdb-tool.1.in |   8 +++
>  ovsdb/ovsdb-tool.c| 101 +-
>  tests/ovsdb-tool.at   |  38 +
>  5 files changed, 152 insertions(+), 1 deletion(-)
>
> 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/NEWS b/NEWS
> index c5caa13d6..a02f9f1a6 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -49,6 +49,9 @@ v2.12.0 - xx xxx 
> quickly after a brief disconnection, saving bandwidth and CPU time.
> See section 4.1.15 of ovsdb-server(7) for details of related OVSDB
> protocol extension.
> + * Support to convert from cluster database to standalone database is
> now
> +   available when clustered is down and cannot be revived using
> ovsdb-tool
> +   . Check "Database Migration Commands" in ovsdb-tool man section.
> - OVN:
>   * IPAM/MACAM:
> - select IPAM mac_prefix in a random manner if not provided by the
> user
> diff --git a/ovsdb/ovsdb-tool.1.in b/ovsdb/ovsdb-tool.1.in
> index ec85e14c4..31a918d90 100644
> --- a/ovsdb/ovsdb-tool.1.in
> +++ b/ovsdb/ovsdb-tool.1.in
> @@ -147,6 +147,14 @@ avoid this possibility, specify
> \fB\-\-cid=\fIuuid\fR, where
>  \fIuuid\fR is the cluster ID of the cluster to join, as printed by
>  \fBovsdb\-tool get\-cid\fR.
>  .
> +.SS "Database Migration Commands"
> +This commands will convert cluster database to standalone database.
> +.
> +.IP "\fBcluster\-to\-standalone\fI db clusterdb"
> +Use this command to convert to standalone database from clustered database
> +when the cluster is down and cannot be revived. It creates new standalone
> +\fIdb\fR file from the given cluster \fIdb\fR file.
> +.
>  .SS "Version Management Commands"
>  .so ovsdb/ovsdb-schemas.man
>  .PP
> diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
> index 438f97590..3bbf4c8bc 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 DBConvert 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,55 @@ print_raft_record(const struct raft_record *r,
>  }
>  }
>
> +static void
> +raft_header_to_standalone_log(const struct raft_header *h,
> +  struct ovsdb_log *db_log_data)
> +{
> +if (h->snap_index) {
> +if (!h->snap.data || json_array(h->snap.data)->n != 2) {
> +ovs_fatal(0, "Incorrect raft header data array length");
> +}
> +
> +struct json *schema_json = json_array(h->snap.data)->elems[0];
> +if (schema_json->type != JSON_NULL) {
> +struct ovsdb_schema *schema;
> +check_ovsdb_error(ovsdb_schema_from_json(schema_json,
> ));
> +ovsdb_schema_destroy(schema);
> +check_ovsdb_error(ovsdb_log_write_and_free(db_log_data,
> +   schema_json));
> +}
> +
> +struct json *data_json = json_array(h->snap.data)->elems[1];
> +if (!data_json || data_json->type != JSON_OBJECT) {
> +ovs_fatal(0, "Invalid raft header data");
> +}
> +if (data_json->type != JSON_NULL) {
> +check_ovsdb_error(ovsdb_log_write_and_free(db_log_data,
> +   data_json));
> +}
> +}
> +}
> +
> +static void
> +raft_record_to_standalone_log(const struct raft_record *r,

[ovs-dev] [PATCH v10] ovsdb-tool: Convert clustered db to standalone db.

2019-08-30 Thread amginwal
From: Aliasgar Ginwala 

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 
Acked-by: Han Zhou 
---
 Documentation/ref/ovsdb.7.rst |   3 +
 NEWS  |   3 +
 ovsdb/ovsdb-tool.1.in |   8 +++
 ovsdb/ovsdb-tool.c| 101 +-
 tests/ovsdb-tool.at   |  38 +
 5 files changed, 152 insertions(+), 1 deletion(-)

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/NEWS b/NEWS
index c5caa13d6..a02f9f1a6 100644
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,9 @@ v2.12.0 - xx xxx 
quickly after a brief disconnection, saving bandwidth and CPU time.
See section 4.1.15 of ovsdb-server(7) for details of related OVSDB
protocol extension.
+ * Support to convert from cluster database to standalone database is now
+   available when clustered is down and cannot be revived using ovsdb-tool
+   . Check "Database Migration Commands" in ovsdb-tool man section.
- OVN:
  * IPAM/MACAM:
- select IPAM mac_prefix in a random manner if not provided by the user
diff --git a/ovsdb/ovsdb-tool.1.in b/ovsdb/ovsdb-tool.1.in
index ec85e14c4..31a918d90 100644
--- a/ovsdb/ovsdb-tool.1.in
+++ b/ovsdb/ovsdb-tool.1.in
@@ -147,6 +147,14 @@ avoid this possibility, specify \fB\-\-cid=\fIuuid\fR, 
where
 \fIuuid\fR is the cluster ID of the cluster to join, as printed by
 \fBovsdb\-tool get\-cid\fR.
 .
+.SS "Database Migration Commands"
+This commands will convert cluster database to standalone database.
+.
+.IP "\fBcluster\-to\-standalone\fI db clusterdb"
+Use this command to convert to standalone database from clustered database
+when the cluster is down and cannot be revived. It creates new standalone
+\fIdb\fR file from the given cluster \fIdb\fR file.
+.
 .SS "Version Management Commands"
 .so ovsdb/ovsdb-schemas.man
 .PP
diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index 438f97590..3bbf4c8bc 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 DBConvert 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,55 @@ print_raft_record(const struct raft_record *r,
 }
 }
 
+static void
+raft_header_to_standalone_log(const struct raft_header *h,
+  struct ovsdb_log *db_log_data)
+{
+if (h->snap_index) {
+if (!h->snap.data || json_array(h->snap.data)->n != 2) {
+ovs_fatal(0, "Incorrect raft header data array length");
+}
+
+struct json *schema_json = json_array(h->snap.data)->elems[0];
+if (schema_json->type != JSON_NULL) {
+struct ovsdb_schema *schema;
+check_ovsdb_error(ovsdb_schema_from_json(schema_json, ));
+ovsdb_schema_destroy(schema);
+check_ovsdb_error(ovsdb_log_write_and_free(db_log_data,
+   schema_json));
+}
+
+struct json *data_json = json_array(h->snap.data)->elems[1];
+if (!data_json || data_json->type != JSON_OBJECT) {
+ovs_fatal(0, "Invalid raft header data");
+}
+if (data_json->type != JSON_NULL) {
+check_ovsdb_error(ovsdb_log_write_and_free(db_log_data,
+   data_json));
+}
+}
+}
+
+static void
+raft_record_to_standalone_log(const struct raft_record *r,
+  struct ovsdb_log *db_log_data)
+{
+if (r->type == RAFT_REC_ENTRY) {
+if (!r->entry.data) {
+return;
+}
+if (json_array(r->entry.data)->n != 2) {
+ovs_fatal(0, "Incorrect raft record array length");
+}
+
+struct json *data_json = json_array(r->entry.data)->elems[1];
+if (data_json->type != JSON_NULL) {