mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 13:53:09 -06:00
Per-room input mutex
This commit is contained in:
parent
5ad47d3b3d
commit
bbb86553c9
|
|
@ -21,6 +21,6 @@ type RoomserverInternalAPI struct {
|
||||||
KeyRing gomatrixserverlib.JSONVerifier
|
KeyRing gomatrixserverlib.JSONVerifier
|
||||||
FedClient *gomatrixserverlib.FederationClient
|
FedClient *gomatrixserverlib.FederationClient
|
||||||
OutputRoomEventTopic string // Kafka topic for new output room events
|
OutputRoomEventTopic string // Kafka topic for new output room events
|
||||||
mutex sync.Mutex // Protects calls to processRoomEvent
|
mutexes sync.Map // room ID -> *sync.Mutex, protects calls to processRoomEvent
|
||||||
fsAPI fsAPI.FederationSenderInternalAPI
|
fsAPI fsAPI.FederationSenderInternalAPI
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package internal
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/Shopify/sarama"
|
"github.com/Shopify/sarama"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
|
@ -71,13 +72,14 @@ func (r *RoomserverInternalAPI) InputRoomEvents(
|
||||||
request *api.InputRoomEventsRequest,
|
request *api.InputRoomEventsRequest,
|
||||||
response *api.InputRoomEventsResponse,
|
response *api.InputRoomEventsResponse,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
// We lock as processRoomEvent can only be called once at a time
|
for i, e := range request.InputRoomEvents {
|
||||||
r.mutex.Lock()
|
mutex, _ := r.mutexes.LoadOrStore(e.Event.RoomID(), &sync.Mutex{})
|
||||||
defer r.mutex.Unlock()
|
mutex.(*sync.Mutex).Lock()
|
||||||
for i := range request.InputRoomEvents {
|
|
||||||
if response.EventID, err = r.processRoomEvent(ctx, request.InputRoomEvents[i]); err != nil {
|
if response.EventID, err = r.processRoomEvent(ctx, request.InputRoomEvents[i]); err != nil {
|
||||||
|
mutex.(*sync.Mutex).Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
mutex.(*sync.Mutex).Unlock()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue