[ovs-dev] [PATCH 2/3] raft: Save and read new election timer in header snapshot.

Han Zhou zhouhan at gmail.com
Thu Aug 22 21:08:22 UTC 2019


From: Han Zhou <hzhou8 at ebay.com>

This patch store the latest election timer in snapshot during log
compression, and when server restarts it reads the value from the log.
Without this, any previous changes to election timer will be lost
in the log, and if server restarts, it will use the default value
instead of the changed value.

Fixes: commit 8e35461 ("ovsdb raft: Support leader election time change online.")
Signed-off-by: Han Zhou <hzhou8 at ebay.com>
---
 Documentation/ref/ovsdb.5.rst | 6 +++++-
 ovsdb/raft-private.c          | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Documentation/ref/ovsdb.5.rst b/Documentation/ref/ovsdb.5.rst
index a6da65d..bb35eee 100644
--- a/Documentation/ref/ovsdb.5.rst
+++ b/Documentation/ref/ovsdb.5.rst
@@ -164,7 +164,7 @@ The clustered format has the following additional notation:
     This allows readers to be ignorant of the full semantics of schema change.
 
 The first record in a clustered database contains the following members,
-all of which are required:
+all of which are required, except ``prev_election_timer``:
 
 ``"server_id": <raw-uuid>``
     The server's own UUID, which must be unique within the cluster.
@@ -190,6 +190,10 @@ all of which are required:
     term "prev_term".  It might not include this server, if it was not the
     initial server in the cluster.
 
+``"prev_election_timer": <uint64>``
+    The election base time before the beginning of the log.  If not exist,
+    the default value 1000 ms is used as if it exists this record.
+
 ``"prev_data": <json-value>`` and ``"prev_eid": <raw-uuid>``
     A snapshot of the data in the database at index "prev_index" and term
     "prev_term", and the entry ID for that data.  The snapshot must contain a
diff --git a/ovsdb/raft-private.c b/ovsdb/raft-private.c
index 98c68a9..26d39a0 100644
--- a/ovsdb/raft-private.c
+++ b/ovsdb/raft-private.c
@@ -284,6 +284,7 @@ raft_entry_clone(struct raft_entry *dst, const struct raft_entry *src)
     dst->data = json_nullable_clone(src->data);
     dst->eid = src->eid;
     dst->servers = json_nullable_clone(src->servers);
+    dst->election_timer = src->election_timer;
 }
 
 void
@@ -405,6 +406,8 @@ raft_header_from_json__(struct raft_header *h, struct ovsdb_parser *p)
                 ovsdb_parser_member(p, "prev_data", OP_ANY));
             h->snap.eid = raft_parse_required_uuid(p, "prev_eid");
             h->snap.term = raft_parse_required_uint64(p, "prev_term");
+            h->snap.election_timer = raft_parse_optional_uint64(
+                p, "prev_election_timer");
         }
     }
 
@@ -457,6 +460,10 @@ raft_header_to_json(const struct raft_header *h)
         }
         json_object_put_format(json, "prev_eid",
                                UUID_FMT, UUID_ARGS(&h->snap.eid));
+        if (h->snap.election_timer) {
+            raft_put_uint64(json, "prev_election_timer",
+                            h->snap.election_timer);
+        }
     }
 
     return json;
-- 
2.1.0



More information about the dev mailing list