The OVSDB server is mostly synchronous and single threaded.  The
OVSDB RAFT storage engine operate under strict deadlines with
operational impact should the deadline overrun.

Register for cooperative multitasking so that long running
processing elsewhere in the program may yield to allow stable
maintainenance of the cluster.

Signed-off-by: Frode Nordahl <[email protected]>
---
 ovsdb/raft.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/ovsdb/raft.c b/ovsdb/raft.c
index 8effd9ad1..19f31b65c 100644
--- a/ovsdb/raft.c
+++ b/ovsdb/raft.c
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <unistd.h>
 
+#include "cooperative-multitasking.h"
 #include "hash.h"
 #include "jsonrpc.h"
 #include "lockfile.h"
@@ -423,6 +424,8 @@ raft_make_address_passive(const char *address_)
     }
 }
 
+#define RAFT_HEARTBEAT_THRESHOLD raft->election_timer / 3
+
 static struct raft *
 raft_alloc(void)
 {
@@ -446,6 +449,9 @@ raft_alloc(void)
     raft->conn_backlog_max_n_msgs = DEFAULT_MAX_BACKLOG_N_MSGS;
     raft->conn_backlog_max_n_bytes = DEFAULT_MAX_BACKLOG_N_BYTES;
 
+    COOPERATIVE_MULTITASKING_REGISTER(
+        &raft_run, raft, RAFT_HEARTBEAT_THRESHOLD);
+
     return raft;
 }
 
@@ -996,7 +1002,11 @@ raft_reset_election_timer(struct raft *raft)
 static void
 raft_reset_ping_timer(struct raft *raft)
 {
-    raft->ping_timeout = time_msec() + raft->election_timer / 3;
+    long long int now = time_msec();
+
+    raft->ping_timeout = now + RAFT_HEARTBEAT_THRESHOLD;
+    COOPERATIVE_MULTITASKING_UPDATE(
+        &raft_run, raft, now, RAFT_HEARTBEAT_THRESHOLD);
 }
 
 static void
-- 
2.34.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to