0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-11-18 07:40:53 +01:00
This commit is contained in:
Neil Alexander 2020-12-04 17:37:48 +00:00
parent e0fde0c24e
commit 7faef15339
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 10 additions and 4 deletions

View file

@ -60,8 +60,8 @@ type destinationQueue struct {
transactionCount atomic.Int32 // how many events in this transaction so far
notifyPDUs chan *queuedPDU // interrupts idle wait for PDUs
notifyEDUs chan *queuedEDU // interrupts idle wait for EDUs
pendingPDUs []*queuedPDU // owned by backgroundSender goroutine
pendingEDUs []*queuedEDU // owned by backgroundSender goroutine
pendingPDUs []*queuedPDU // owned by backgroundSender goroutine once started
pendingEDUs []*queuedEDU // owned by backgroundSender goroutine once started
interruptBackoff chan bool // interrupts backoff
}
@ -171,6 +171,7 @@ func (oq *destinationQueue) getPendingFromDatabase() {
// in the database.
ctx := context.Background()
if pduCapacity := maxPDUsInMemory - len(oq.pendingPDUs); pduCapacity > 0 {
// We have room in memory for some PDUs - let's request no more than that.
if pdus, err := oq.db.GetPendingPDUs(ctx, oq.destination, pduCapacity); err == nil {
for receipt, pdu := range pdus {
oq.pendingPDUs = append(oq.pendingPDUs, &queuedPDU{receipt, pdu})
@ -180,6 +181,7 @@ func (oq *destinationQueue) getPendingFromDatabase() {
}
}
if eduCapacity := maxPDUsInMemory - len(oq.pendingPDUs); eduCapacity > 0 {
// We have room in memory for some EDUs - let's request no more than that.
if edus, err := oq.db.GetPendingEDUs(ctx, oq.destination, eduCapacity); err == nil {
for receipt, edu := range edus {
oq.pendingEDUs = append(oq.pendingEDUs, &queuedEDU{receipt, edu})
@ -188,6 +190,11 @@ func (oq *destinationQueue) getPendingFromDatabase() {
logrus.WithError(err).Errorf("Failed to get pending EDUs for %q", oq.destination)
}
}
// If we've retrieved all of the events from the database with room to spare
// in memory then we'll no longer consider this queue to be overflowed.
if len(oq.pendingPDUs) < maxPDUsInMemory && len(oq.pendingEDUs) < maxEDUsInMemory {
oq.overflowed.Store(false)
}
}
// backgroundSend is the worker goroutine for sending events.

View file

@ -84,8 +84,7 @@ func NewOutgoingQueues(
log.WithError(err).Error("Failed to get EDU server names for destination queue hydration")
}
for serverName := range serverNames {
queue := queues.getQueue(serverName)
if !queue.statistics.Blacklisted() {
if queue := queues.getQueue(serverName); !queue.statistics.Blacklisted() {
queue.wakeQueueIfNeeded()
}
}