Tweak transaction handling behaviour for /sync

This commit is contained in:
Neil Alexander 2022-09-30 15:44:30 +01:00
parent 0e2fb63b4f
commit f14c3a2526
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
10 changed files with 16 additions and 1 deletions

View file

@ -20,6 +20,7 @@ import (
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/dendrite/internal/eventutil" "github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/syncapi/storage/shared" "github.com/matrix-org/dendrite/syncapi/storage/shared"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
@ -27,6 +28,7 @@ import (
) )
type DatabaseTransaction interface { type DatabaseTransaction interface {
sqlutil.Transaction
SharedUsers SharedUsers
MaxStreamPositionForPDUs(ctx context.Context) (types.StreamPosition, error) MaxStreamPositionForPDUs(ctx context.Context) (types.StreamPosition, error)

View file

@ -54,6 +54,7 @@ func (p *AccountDataStreamProvider) IncrementalSync(
) )
if err != nil { if err != nil {
req.Log.WithError(err).Error("p.DB.GetAccountDataInRange failed") req.Log.WithError(err).Error("p.DB.GetAccountDataInRange failed")
_ = snapshot.Rollback()
return from return from
} }

View file

@ -34,11 +34,13 @@ func (p *DeviceListStreamProvider) IncrementalSync(
to, _, err = internal.DeviceListCatchup(context.Background(), snapshot, p.keyAPI, p.rsAPI, req.Device.UserID, req.Response, from, to) to, _, err = internal.DeviceListCatchup(context.Background(), snapshot, p.keyAPI, p.rsAPI, req.Device.UserID, req.Response, from, to)
if err != nil { if err != nil {
req.Log.WithError(err).Error("internal.DeviceListCatchup failed") req.Log.WithError(err).Error("internal.DeviceListCatchup failed")
_ = snapshot.Rollback()
return from return from
} }
err = internal.DeviceOTKCounts(req.Context, p.keyAPI, req.Device.UserID, req.Device.ID, req.Response) err = internal.DeviceOTKCounts(req.Context, p.keyAPI, req.Device.UserID, req.Device.ID, req.Response)
if err != nil { if err != nil {
req.Log.WithError(err).Error("internal.DeviceListCatchup failed") req.Log.WithError(err).Error("internal.DeviceListCatchup failed")
_ = snapshot.Rollback()
return from return from
} }

View file

@ -56,6 +56,7 @@ func (p *InviteStreamProvider) IncrementalSync(
) )
if err != nil { if err != nil {
req.Log.WithError(err).Error("p.DB.InviteEventsInRange failed") req.Log.WithError(err).Error("p.DB.InviteEventsInRange failed")
_ = snapshot.Rollback()
return from return from
} }

View file

@ -46,6 +46,7 @@ func (p *NotificationDataStreamProvider) IncrementalSync(
countsByRoom, err := snapshot.GetUserUnreadNotificationCountsForRooms(ctx, req.Device.UserID, req.Rooms) countsByRoom, err := snapshot.GetUserUnreadNotificationCountsForRooms(ctx, req.Device.UserID, req.Rooms)
if err != nil { if err != nil {
req.Log.WithError(err).Error("GetUserUnreadNotificationCountsForRooms failed") req.Log.WithError(err).Error("GetUserUnreadNotificationCountsForRooms failed")
_ = snapshot.Rollback()
return from return from
} }

View file

@ -75,6 +75,7 @@ func (p *PDUStreamProvider) CompleteSync(
joinedRoomIDs, err := snapshot.RoomIDsWithMembership(ctx, req.Device.UserID, gomatrixserverlib.Join) joinedRoomIDs, err := snapshot.RoomIDsWithMembership(ctx, req.Device.UserID, gomatrixserverlib.Join)
if err != nil { if err != nil {
req.Log.WithError(err).Error("p.DB.RoomIDsWithMembership failed") req.Log.WithError(err).Error("p.DB.RoomIDsWithMembership failed")
_ = snapshot.Rollback()
return from return from
} }
@ -101,6 +102,7 @@ func (p *PDUStreamProvider) CompleteSync(
) )
if jerr != nil { if jerr != nil {
req.Log.WithError(jerr).Error("p.getJoinResponseForCompleteSync failed") req.Log.WithError(jerr).Error("p.getJoinResponseForCompleteSync failed")
_ = snapshot.Rollback()
continue // return from continue // return from
} }
req.Response.Rooms.Join[roomID] = *jr req.Response.Rooms.Join[roomID] = *jr
@ -111,6 +113,7 @@ func (p *PDUStreamProvider) CompleteSync(
peeks, err := snapshot.PeeksInRange(ctx, req.Device.UserID, req.Device.ID, r) peeks, err := snapshot.PeeksInRange(ctx, req.Device.UserID, req.Device.ID, r)
if err != nil { if err != nil {
req.Log.WithError(err).Error("p.DB.PeeksInRange failed") req.Log.WithError(err).Error("p.DB.PeeksInRange failed")
_ = snapshot.Rollback()
return from return from
} }
for _, peek := range peeks { for _, peek := range peeks {
@ -121,6 +124,7 @@ func (p *PDUStreamProvider) CompleteSync(
) )
if err != nil { if err != nil {
req.Log.WithError(err).Error("p.getJoinResponseForCompleteSync failed") req.Log.WithError(err).Error("p.getJoinResponseForCompleteSync failed")
_ = snapshot.Rollback()
continue // return from continue // return from
} }
req.Response.Rooms.Peek[peek.RoomID] = *jr req.Response.Rooms.Peek[peek.RoomID] = *jr

View file

@ -67,6 +67,7 @@ func (p *PresenceStreamProvider) IncrementalSync(
presences, err := snapshot.PresenceAfter(ctx, from, gomatrixserverlib.EventFilter{Limit: 1000}) presences, err := snapshot.PresenceAfter(ctx, from, gomatrixserverlib.EventFilter{Limit: 1000})
if err != nil { if err != nil {
req.Log.WithError(err).Error("p.DB.PresenceAfter failed") req.Log.WithError(err).Error("p.DB.PresenceAfter failed")
_ = snapshot.Rollback()
return from return from
} }
@ -95,6 +96,7 @@ func (p *PresenceStreamProvider) IncrementalSync(
presences[roomUsers[i]], err = snapshot.GetPresence(ctx, roomUsers[i]) presences[roomUsers[i]], err = snapshot.GetPresence(ctx, roomUsers[i])
if err != nil { if err != nil {
req.Log.WithError(err).Error("unable to query presence for user") req.Log.WithError(err).Error("unable to query presence for user")
_ = snapshot.Rollback()
return from return from
} }
if len(presences) > req.Filter.Presence.Limit { if len(presences) > req.Filter.Presence.Limit {

View file

@ -52,6 +52,7 @@ func (p *ReceiptStreamProvider) IncrementalSync(
lastPos, receipts, err := snapshot.RoomReceiptsAfter(ctx, joinedRooms, from) lastPos, receipts, err := snapshot.RoomReceiptsAfter(ctx, joinedRooms, from)
if err != nil { if err != nil {
req.Log.WithError(err).Error("p.DB.RoomReceiptsAfter failed") req.Log.WithError(err).Error("p.DB.RoomReceiptsAfter failed")
_ = snapshot.Rollback()
return from return from
} }

View file

@ -44,6 +44,7 @@ func (p *SendToDeviceStreamProvider) IncrementalSync(
lastPos, events, err := snapshot.SendToDeviceUpdatesForSync(req.Context, req.Device.UserID, req.Device.ID, from, to) lastPos, events, err := snapshot.SendToDeviceUpdatesForSync(req.Context, req.Device.UserID, req.Device.ID, from, to)
if err != nil { if err != nil {
req.Log.WithError(err).Error("p.DB.SendToDeviceUpdatesForSync failed") req.Log.WithError(err).Error("p.DB.SendToDeviceUpdatesForSync failed")
_ = snapshot.Rollback()
return from return from
} }

View file

@ -310,7 +310,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.
logrus.WithError(err).Error("Failed to acquire database snapshot for sync request") logrus.WithError(err).Error("Failed to acquire database snapshot for sync request")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }
defer snapshot.Rollback() // nolint:errcheck defer snapshot.Commit() // nolint:errcheck
if syncReq.Since.IsEmpty() { if syncReq.Since.IsEmpty() {
// Complete sync // Complete sync