Blob Blame History Raw
From 1de31c3a531f5db6793819fa18f6e69304db929c Mon Sep 17 00:00:00 2001
From: Mark Michelson <mmichels@redhat.com>
Date: Fri, 1 May 2020 15:13:08 -0400
Subject: [PATCH 4/4] ovsdb-idl: Add function to reset min_index.

If an administrator removes all of the databases in a cluster from
disk, then ovsdb IDL clients will have a problem. The databases will all
reset their stored indexes to 0, so The IDL client's min_index will be
higher than the indexes of all databases in the cluster. This results in
the client constantly connecting to databases, detecting the data as
"stale", and then attempting to connect to another.

This function provides a way to reset the IDL to an initial state with
min_index of 0. This way, the client will not wrongly detect the
database data as stale and will recover properly.

Notice that this function is not actually used anywhere in this patch.
This will be used by OVN, though, since OVN is the primary user of
clustered OVSDB.

Signed-off-by: Mark Michelson <mmichels@redhat.com>
Acked-by: Han Zhou <hzhou@ovn.org>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>

(cherry-picked from upstream ovs commit 89b522aee379f7ebd21ec67ffb622118af7e9db1)

Change-Id: I943ece9a07566a34b11248455cc1abbe7892d4e8
---
 openvswitch-2.13.0/lib/ovsdb-idl.c | 10 ++++++++++
 openvswitch-2.13.0/lib/ovsdb-idl.h |  1 +
 2 files changed, 11 insertions(+)

diff --git a/openvswitch-2.13.0/lib/ovsdb-idl.c b/openvswitch-2.13.0/lib/ovsdb-idl.c
index 8eb421366..648c227d6 100644
--- a/openvswitch-2.13.0/lib/ovsdb-idl.c
+++ b/openvswitch-2.13.0/lib/ovsdb-idl.c
@@ -561,6 +561,16 @@ ovsdb_idl_set_shuffle_remotes(struct ovsdb_idl *idl, bool shuffle)
     idl->shuffle_remotes = shuffle;
 }
 
+/* Reset min_index to 0. This prevents a situation where the client
+ * thinks all databases have stale data, when they actually have all
+ * been destroyed and rebuilt from scratch.
+ */
+void
+ovsdb_idl_reset_min_index(struct ovsdb_idl *idl)
+{
+    idl->min_index = 0;
+}
+
 static void
 ovsdb_idl_db_destroy(struct ovsdb_idl_db *db)
 {
diff --git a/openvswitch-2.13.0/lib/ovsdb-idl.h b/openvswitch-2.13.0/lib/ovsdb-idl.h
index 9f12ce320..c56cd19b1 100644
--- a/openvswitch-2.13.0/lib/ovsdb-idl.h
+++ b/openvswitch-2.13.0/lib/ovsdb-idl.h
@@ -64,6 +64,7 @@ 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_reset_min_index(struct ovsdb_idl *);
 void ovsdb_idl_destroy(struct ovsdb_idl *);
 
 void ovsdb_idl_set_leader_only(struct ovsdb_idl *, bool leader_only);
-- 
2.26.2