mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Add p2p wakeup broadcast handling to pinecone demos (#2841)
Adds wakeup broadcast handling to the pinecone demos. This will reset their blacklist status and interrupt any ongoing federation queue backoffs currently in progress for this peer. The end result is that any queued events will quickly be sent to the peer if they had disconnected while attempting to send events to them.
This commit is contained in:
parent
ffd8e21ce5
commit
a8e7ffc7ab
10 changed files with 172 additions and 12 deletions
|
@ -141,23 +141,44 @@ func (oq *destinationQueue) handleBackoffNotifier() {
|
|||
}
|
||||
}
|
||||
|
||||
// wakeQueueIfEventsPending calls wakeQueueAndNotify only if there are
|
||||
// pending events or if forceWakeup is true. This prevents starting the
|
||||
// queue unnecessarily.
|
||||
func (oq *destinationQueue) wakeQueueIfEventsPending(forceWakeup bool) {
|
||||
eventsPending := func() bool {
|
||||
oq.pendingMutex.Lock()
|
||||
defer oq.pendingMutex.Unlock()
|
||||
return len(oq.pendingPDUs) > 0 || len(oq.pendingEDUs) > 0
|
||||
}
|
||||
|
||||
// NOTE : Only wakeup and notify the queue if there are pending events
|
||||
// or if forceWakeup is true. Otherwise there is no reason to start the
|
||||
// queue goroutine and waste resources.
|
||||
if forceWakeup || eventsPending() {
|
||||
logrus.Info("Starting queue due to pending events or forceWakeup")
|
||||
oq.wakeQueueAndNotify()
|
||||
}
|
||||
}
|
||||
|
||||
// wakeQueueAndNotify ensures the destination queue is running and notifies it
|
||||
// that there is pending work.
|
||||
func (oq *destinationQueue) wakeQueueAndNotify() {
|
||||
// Wake up the queue if it's asleep.
|
||||
oq.wakeQueueIfNeeded()
|
||||
// NOTE : Send notification before waking queue to prevent a race
|
||||
// where the queue was running and stops due to a timeout in between
|
||||
// checking it and sending the notification.
|
||||
|
||||
// Notify the queue that there are events ready to send.
|
||||
select {
|
||||
case oq.notify <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
|
||||
// Wake up the queue if it's asleep.
|
||||
oq.wakeQueueIfNeeded()
|
||||
}
|
||||
|
||||
// wakeQueueIfNeeded will wake up the destination queue if it is
|
||||
// not already running. If it is running but it is backing off
|
||||
// then we will interrupt the backoff, causing any federation
|
||||
// requests to retry.
|
||||
// not already running.
|
||||
func (oq *destinationQueue) wakeQueueIfNeeded() {
|
||||
// Clear the backingOff flag and update the backoff metrics if it was set.
|
||||
if oq.backingOff.CompareAndSwap(true, false) {
|
||||
|
|
|
@ -374,14 +374,24 @@ func (oqs *OutgoingQueues) SendEDU(
|
|||
return nil
|
||||
}
|
||||
|
||||
// IsServerBlacklisted returns whether or not the provided server is currently
|
||||
// blacklisted.
|
||||
func (oqs *OutgoingQueues) IsServerBlacklisted(srv gomatrixserverlib.ServerName) bool {
|
||||
return oqs.statistics.ForServer(srv).Blacklisted()
|
||||
}
|
||||
|
||||
// RetryServer attempts to resend events to the given server if we had given up.
|
||||
func (oqs *OutgoingQueues) RetryServer(srv gomatrixserverlib.ServerName) {
|
||||
if oqs.disabled {
|
||||
return
|
||||
}
|
||||
oqs.statistics.ForServer(srv).RemoveBlacklist()
|
||||
|
||||
serverStatistics := oqs.statistics.ForServer(srv)
|
||||
forceWakeup := serverStatistics.Blacklisted()
|
||||
serverStatistics.RemoveBlacklist()
|
||||
serverStatistics.ClearBackoff()
|
||||
|
||||
if queue := oqs.getQueue(srv); queue != nil {
|
||||
queue.statistics.ClearBackoff()
|
||||
queue.wakeQueueIfNeeded()
|
||||
queue.wakeQueueIfEventsPending(forceWakeup)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue