Limit per-room mutexes to Postgres

This commit is contained in:
Neil Alexander 2020-08-20 15:57:04 +01:00
parent 66cf7a7886
commit b540ef70b6
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 19 additions and 1 deletions

View file

@ -73,7 +73,11 @@ func (r *RoomserverInternalAPI) InputRoomEvents(
response *api.InputRoomEventsResponse, response *api.InputRoomEventsResponse,
) (err error) { ) (err error) {
for i, e := range request.InputRoomEvents { for i, e := range request.InputRoomEvents {
mutex, _ := r.mutexes.LoadOrStore(e.Event.RoomID(), &sync.Mutex{}) roomID := e.Event.RoomID()
if !r.DB.SupportsConcurrentRoomInputs() {
roomID = "global"
}
mutex, _ := r.mutexes.LoadOrStore(roomID, &sync.Mutex{})
mutex.(*sync.Mutex).Lock() mutex.(*sync.Mutex).Lock()
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() mutex.(*sync.Mutex).Unlock()

View file

@ -24,6 +24,8 @@ import (
) )
type Database interface { type Database interface {
// Do we support processing input events for more than one room at a time?
SupportsConcurrentRoomInputs() bool
// Store the room state at an event in the database // Store the room state at an event in the database
AddState( AddState(
ctx context.Context, ctx context.Context,

View file

@ -44,6 +44,10 @@ type Database struct {
RedactionsTable tables.Redactions RedactionsTable tables.Redactions
} }
func (d *Database) SupportsConcurrentRoomInputs() bool {
return true
}
func (d *Database) EventTypeNIDs( func (d *Database) EventTypeNIDs(
ctx context.Context, eventTypes []string, ctx context.Context, eventTypes []string,
) (map[string]types.EventTypeNID, error) { ) (map[string]types.EventTypeNID, error) {

View file

@ -139,6 +139,14 @@ func Open(dbProperties *config.DatabaseOptions) (*Database, error) {
return &d, nil return &d, nil
} }
func (d *Database) SupportsConcurrentRoomInputs() bool {
// This isn't supported in SQLite mode yet because of issues with
// database locks.
// TODO: Look at this again - the problem is probably to do with
// the membership updaters and latest events updaters.
return false
}
func (d *Database) GetLatestEventsForUpdate( func (d *Database) GetLatestEventsForUpdate(
ctx context.Context, roomNID types.RoomNID, ctx context.Context, roomNID types.RoomNID,
) (*shared.LatestEventsUpdater, error) { ) (*shared.LatestEventsUpdater, error) {