Since the previous commits significantly reduced the amount of main
thread blocking during compaction we can now again allow compaction
during leadership.

As leadership changes are quite costly (especially to other applications
needing to reconnect and find the new leader) the overhead of the
compaction is generally lower then that of a leadership switch.

Signed-off-by: Felix Huettner <felix.huettner@stackit.cloud>
---
 ovsdb/raft.c    | 23 +++++------------------
 ovsdb/raft.h    |  1 -
 ovsdb/storage.c |  4 +---
 3 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/ovsdb/raft.c b/ovsdb/raft.c
index 8d4cde695..6fdef9ea5 100644
--- a/ovsdb/raft.c
+++ b/ovsdb/raft.c
@@ -2044,9 +2044,11 @@ raft_run(struct raft *raft)
     }
 
     if (failure_test == FT_TRANSFER_LEADERSHIP) {
-        /* Using this function as it conveniently implements all we need and
-         * snapshotting is the main test scenario for leadership transfer. */
-        raft_notify_snapshot_recommended(raft);
+        if (raft->role == RAFT_LEADER) {
+            VLOG_INFO("Transferring leadership becaues of test.");
+            raft_transfer_leadership(raft, "preparing to write snapshot");
+            raft_become_follower(raft);
+        }
         failure_test = FT_NO_TEST;
     }
 
@@ -4555,24 +4557,9 @@ raft_may_snapshot(const struct raft *raft)
             && !raft->leaving
             && !raft->left
             && !raft->failed
-            && (raft->role == RAFT_FOLLOWER || hmap_count(&raft->servers) == 1)
             && raft->last_applied >= raft->log_start);
 }
 
-/* Prepares for soon snapshotting. */
-void
-raft_notify_snapshot_recommended(struct raft *raft)
-{
-    if (raft->role == RAFT_LEADER) {
-        /* Leader is about to write database snapshot to the disk and this
-         * might take significant amount of time.  Stepping back from the
-         * leadership to keep the cluster functional during this process.  */
-        VLOG_INFO("Transferring leadership to write a snapshot.");
-        raft_transfer_leadership(raft, "preparing to write snapshot");
-        raft_become_follower(raft);
-    }
-}
-
 /* Replaces the log for 'raft', up to the last log entry read, by
  * 'new_snapshot_data'.  Returns NULL if successful, otherwise an error that
  * the caller must eventually free.
diff --git a/ovsdb/raft.h b/ovsdb/raft.h
index a1251510e..1402ae7fa 100644
--- a/ovsdb/raft.h
+++ b/ovsdb/raft.h
@@ -179,7 +179,6 @@ void raft_command_wait(const struct raft_command *);
 bool raft_grew_lots(const struct raft *);
 uint64_t raft_get_log_length(const struct raft *);
 bool raft_may_snapshot(const struct raft *);
-void raft_notify_snapshot_recommended(struct raft *);
 struct ovsdb_error *raft_store_snapshot(struct raft *,
                                         const struct json *new_snapshot,
                                         uint64_t applied_index)
diff --git a/ovsdb/storage.c b/ovsdb/storage.c
index fc3d3fb67..b8c4318d7 100644
--- a/ovsdb/storage.c
+++ b/ovsdb/storage.c
@@ -563,10 +563,8 @@ ovsdb_storage_should_compact(struct ovsdb_storage *storage)
             return false;
         }
 
-        /* If we can't snapshot right now, don't. */
+        /* If we can't compact right now, don't. */
         if (storage->raft && !raft_may_snapshot(storage->raft)) {
-            /* Notifying the storage that it needs to make a snapshot soon. */
-            raft_notify_snapshot_recommended(storage->raft);
             return false;
         }
 
-- 
2.43.0


_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to