mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-23 22:09:09 +02:00
[client] Extract the peer phases of a sync pass into applyPeerPhases
This commit is contained in:
+28
-20
@@ -1730,30 +1730,11 @@ func (e *Engine) updateNetworkMap(networkMap *mgmProto.NetworkMap, maxBatch int,
|
|||||||
// peer was deleted), remotePeers is already empty, so the bounded diff below removes
|
// peer was deleted), remotePeers is already empty, so the bounded diff below removes
|
||||||
// every peer in batches — same path as a normal update, no unbounded removeAllPeers
|
// every peer in batches — same path as a normal update, no unbounded removeAllPeers
|
||||||
// held under syncMsgMux in one shot.
|
// held under syncMsgMux in one shot.
|
||||||
doneRemoved := e.phase("removed_peers")
|
needMore, err := e.applyPeerPhases(remotePeers, maxBatch)
|
||||||
removeMore, err := e.removePeers(remotePeers, maxBatch)
|
|
||||||
doneRemoved()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doneModified := e.phase("modified_peers")
|
|
||||||
modifyMore, err := e.modifyPeers(remotePeers, maxBatch)
|
|
||||||
doneModified()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
doneAdded := e.phase("added_peers")
|
|
||||||
addMore, err := e.addNewPeers(remotePeers, maxBatch)
|
|
||||||
doneAdded()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// needMore signals the caller to re-run when a peer phase hit its per-pass cap.
|
|
||||||
needMore := removeMore || modifyMore || addMore
|
|
||||||
|
|
||||||
e.statusRecorder.FinishPeerListModifications()
|
e.statusRecorder.FinishPeerListModifications()
|
||||||
|
|
||||||
// The SSH and lazy-exclude steps walk the whole map and need every target peer
|
// The SSH and lazy-exclude steps walk the whole map and need every target peer
|
||||||
@@ -1781,6 +1762,33 @@ func (e *Engine) updateNetworkMap(networkMap *mgmProto.NetworkMap, maxBatch int,
|
|||||||
return needMore, nil
|
return needMore, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// applyPeerPhases removes, modifies and adds up to maxBatch peers each, and
|
||||||
|
// reports whether any phase hit the cap.
|
||||||
|
func (e *Engine) applyPeerPhases(remotePeers []*mgmProto.RemotePeerConfig, maxBatch int) (bool, error) {
|
||||||
|
doneRemoved := e.phase("removed_peers")
|
||||||
|
removeMore, err := e.removePeers(remotePeers, maxBatch)
|
||||||
|
doneRemoved()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
doneModified := e.phase("modified_peers")
|
||||||
|
modifyMore, err := e.modifyPeers(remotePeers, maxBatch)
|
||||||
|
doneModified()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
doneAdded := e.phase("added_peers")
|
||||||
|
addMore, err := e.addNewPeers(remotePeers, maxBatch)
|
||||||
|
doneAdded()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return removeMore || modifyMore || addMore, nil
|
||||||
|
}
|
||||||
|
|
||||||
// applyWholesale applies the cheap, local, idempotent map sections (lazy feature
|
// applyWholesale applies the cheap, local, idempotent map sections (lazy feature
|
||||||
// flag, firewall/legacy management, DNS, routes, ACL filtering, DNS forwarder) that
|
// flag, firewall/legacy management, DNS, routes, ACL filtering, DNS forwarder) that
|
||||||
// must be in place before peers come up. It runs once per target, on the first pass.
|
// must be in place before peers come up. It runs once per target, on the first pass.
|
||||||
|
|||||||
Reference in New Issue
Block a user