mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Fix a couple of bugs
This commit is contained in:
parent
96b8c2c3d5
commit
8b89313851
|
|
@ -102,7 +102,7 @@ func (r *Inputer) Start() error {
|
||||||
_ = msg.InProgress() // resets the acknowledgement wait timer
|
_ = msg.InProgress() // resets the acknowledgement wait timer
|
||||||
defer eventsInProgress.Delete(index)
|
defer eventsInProgress.Delete(index)
|
||||||
defer roomserverInputBackpressure.With(prometheus.Labels{"room_id": roomID}).Dec()
|
defer roomserverInputBackpressure.With(prometheus.Labels{"room_id": roomID}).Dec()
|
||||||
retry, err := r.processRoomEventUsingUpdater(context.Background(), roomID, &inputRoomEvent)
|
action, err := r.processRoomEventUsingUpdater(context.Background(), roomID, &inputRoomEvent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, context.DeadlineExceeded) && !errors.Is(err, context.Canceled) {
|
if !errors.Is(err, context.DeadlineExceeded) && !errors.Is(err, context.Canceled) {
|
||||||
sentry.CaptureException(err)
|
sentry.CaptureException(err)
|
||||||
|
|
@ -113,9 +113,10 @@ func (r *Inputer) Start() error {
|
||||||
"type": inputRoomEvent.Event.Type(),
|
"type": inputRoomEvent.Event.Type(),
|
||||||
}).Warn("Roomserver failed to process async event")
|
}).Warn("Roomserver failed to process async event")
|
||||||
}
|
}
|
||||||
if retry {
|
switch action {
|
||||||
|
case retryLater:
|
||||||
_ = msg.Nak()
|
_ = msg.Nak()
|
||||||
} else {
|
case doNotRetry:
|
||||||
_ = msg.Ack()
|
_ = msg.Ack()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -137,35 +138,41 @@ func (r *Inputer) Start() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type retryAction int
|
||||||
|
|
||||||
|
const (
|
||||||
|
doNotRetry retryAction = iota
|
||||||
|
retryLater
|
||||||
|
)
|
||||||
|
|
||||||
// processRoomEventUsingUpdater opens up a room updater and tries to
|
// processRoomEventUsingUpdater opens up a room updater and tries to
|
||||||
// process the event. It returns two values: the bool signifying whether
|
// process the event. It returns whether or not we should positively
|
||||||
// we should retry later if possible (i.e. using NATS, because we couldn't
|
// or negatively acknowledge the event (i.e. for NATS) and an error
|
||||||
// commit the transaction) and an error signifying anything else that may
|
// if it occurred.
|
||||||
// have gone wrong.
|
|
||||||
func (r *Inputer) processRoomEventUsingUpdater(
|
func (r *Inputer) processRoomEventUsingUpdater(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
roomID string,
|
roomID string,
|
||||||
inputRoomEvent *api.InputRoomEvent,
|
inputRoomEvent *api.InputRoomEvent,
|
||||||
) (bool, error) {
|
) (retryAction, error) {
|
||||||
roomInfo, err := r.DB.RoomInfo(ctx, roomID)
|
roomInfo, err := r.DB.RoomInfo(ctx, roomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("r.DB.RoomInfo: %w", err)
|
return doNotRetry, fmt.Errorf("r.DB.RoomInfo: %w", err)
|
||||||
}
|
}
|
||||||
updater, err := r.DB.GetRoomUpdater(ctx, roomInfo)
|
updater, err := r.DB.GetRoomUpdater(ctx, roomInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true, fmt.Errorf("r.DB.GetRoomUpdater: %w", err)
|
return retryLater, fmt.Errorf("r.DB.GetRoomUpdater: %w", err)
|
||||||
}
|
}
|
||||||
commit, err := r.processRoomEvent(ctx, updater, inputRoomEvent)
|
commit, err := r.processRoomEvent(ctx, updater, inputRoomEvent)
|
||||||
if commit {
|
if commit {
|
||||||
if cerr := updater.Commit(); cerr != nil {
|
if cerr := updater.Commit(); cerr != nil {
|
||||||
return true, fmt.Errorf("updater.Commit: %w", cerr)
|
return retryLater, fmt.Errorf("updater.Commit: %w", cerr)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if rerr := updater.Rollback(); rerr != nil {
|
if rerr := updater.Rollback(); rerr != nil {
|
||||||
return true, fmt.Errorf("updater.Rollback: %w", rerr)
|
return retryLater, fmt.Errorf("updater.Rollback: %w", rerr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, err
|
return doNotRetry, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputRoomEvents implements api.RoomserverInternalAPI
|
// InputRoomEvents implements api.RoomserverInternalAPI
|
||||||
|
|
|
||||||
|
|
@ -447,7 +447,7 @@ func (d *Database) events(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
eventIDs, _ := d.EventsTable.BulkSelectEventID(ctx, nil, eventNIDs)
|
eventIDs, _ := d.EventsTable.BulkSelectEventID(ctx, txn, eventNIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
eventIDs = map[types.EventNID]string{}
|
eventIDs = map[types.EventNID]string{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue