handle exclusive writer txn for cleanliness

This commit is contained in:
Matthew Hodgson 2020-09-09 02:15:58 +01:00
parent de53608f98
commit b45436aab0

View file

@ -30,7 +30,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/storage/tables"
"github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// Database is a temporary struct until we have made syncserver.go the same for both pq/sqlite // Database is a temporary struct until we have made syncserver.go the same for both pq/sqlite
@ -169,8 +169,8 @@ func (d *Database) RetireInviteEvent(
func (d *Database) AddPeek( func (d *Database) AddPeek(
ctx context.Context, roomID, userID, deviceID string, ctx context.Context, roomID, userID, deviceID string,
) (sp types.StreamPosition, err error) { ) (sp types.StreamPosition, err error) {
_ = d.Writer.Do(nil, nil, func(_ *sql.Tx) error { _ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
sp, err = d.Peeks.InsertPeek(ctx, nil, roomID, userID, deviceID) sp, err = d.Peeks.InsertPeek(ctx, txn, roomID, userID, deviceID)
return nil return nil
}) })
return return
@ -182,8 +182,8 @@ func (d *Database) AddPeek(
func (d *Database) DeletePeeks( func (d *Database) DeletePeeks(
ctx context.Context, roomID, userID string, ctx context.Context, roomID, userID string,
) (sp types.StreamPosition, err error) { ) (sp types.StreamPosition, err error) {
_ = d.Writer.Do(nil, nil, func(_ *sql.Tx) error { _ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
sp, err = d.Peeks.DeletePeeks(ctx, nil, roomID, userID) sp, err = d.Peeks.DeletePeeks(ctx, txn, roomID, userID)
return nil return nil
}) })
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
@ -230,7 +230,7 @@ func (d *Database) StreamEventsToEvents(device *userapi.Device, in []types.Strea
"transaction_id", in[i].TransactionID.TransactionID, "transaction_id", in[i].TransactionID.TransactionID,
) )
if err != nil { if err != nil {
logrus.WithFields(logrus.Fields{ log.WithFields(log.Fields{
"event_id": out[i].EventID(), "event_id": out[i].EventID(),
}).WithError(err).Warnf("Failed to add transaction ID to event") }).WithError(err).Warnf("Failed to add transaction ID to event")
} }
@ -624,7 +624,7 @@ func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, reda
return err return err
} }
if len(redactedEvents) == 0 { if len(redactedEvents) == 0 {
logrus.WithField("event_id", redactedEventID).WithField("redaction_event", redactedBecause.EventID()).Warnf("missing redacted event for redaction") log.WithField("event_id", redactedEventID).WithField("redaction_event", redactedBecause.EventID()).Warnf("missing redacted event for redaction")
return nil return nil
} }
eventToRedact := redactedEvents[0].Unwrap() eventToRedact := redactedEvents[0].Unwrap()