mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 13:53:09 -06:00
Actually use writer transactions rather than ignoring them
This commit is contained in:
parent
fc786b50ff
commit
66cf7a7886
|
|
@ -276,9 +276,10 @@ func (s *eventStatements) BulkSelectStateAtEventByID(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *eventStatements) UpdateEventState(
|
func (s *eventStatements) UpdateEventState(
|
||||||
ctx context.Context, eventNID types.EventNID, stateNID types.StateSnapshotNID,
|
ctx context.Context, txn *sql.Tx, eventNID types.EventNID, stateNID types.StateSnapshotNID,
|
||||||
) error {
|
) error {
|
||||||
_, err := s.updateEventStateStmt.ExecContext(ctx, int64(eventNID), int64(stateNID))
|
stmt := sqlutil.TxStmt(txn, s.updateEventStateStmt)
|
||||||
|
_, err := stmt.ExecContext(ctx, int64(eventNID), int64(stateNID))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||||
)
|
)
|
||||||
|
|
@ -63,9 +64,10 @@ func NewPostgresPublishedTable(db *sql.DB) (tables.Published, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *publishedStatements) UpsertRoomPublished(
|
func (s *publishedStatements) UpsertRoomPublished(
|
||||||
ctx context.Context, roomID string, published bool,
|
ctx context.Context, txn *sql.Tx, roomID string, published bool,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
_, err = s.upsertPublishedStmt.ExecContext(ctx, roomID, published)
|
stmt := sqlutil.TxStmt(txn, s.upsertPublishedStmt)
|
||||||
|
_, err = stmt.ExecContext(ctx, roomID, published)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||||
)
|
)
|
||||||
|
|
@ -77,9 +78,10 @@ func NewPostgresRoomAliasesTable(db *sql.DB) (tables.RoomAliases, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *roomAliasesStatements) InsertRoomAlias(
|
func (s *roomAliasesStatements) InsertRoomAlias(
|
||||||
ctx context.Context, alias string, roomID string, creatorUserID string,
|
ctx context.Context, txn *sql.Tx, alias string, roomID string, creatorUserID string,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
_, err = s.insertRoomAliasStmt.ExecContext(ctx, alias, roomID, creatorUserID)
|
stmt := sqlutil.TxStmt(txn, s.insertRoomAliasStmt)
|
||||||
|
_, err = stmt.ExecContext(ctx, alias, roomID, creatorUserID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,8 +127,9 @@ func (s *roomAliasesStatements) SelectCreatorIDFromAlias(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *roomAliasesStatements) DeleteRoomAlias(
|
func (s *roomAliasesStatements) DeleteRoomAlias(
|
||||||
ctx context.Context, alias string,
|
ctx context.Context, txn *sql.Tx, alias string,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
_, err = s.deleteRoomAliasStmt.ExecContext(ctx, alias)
|
stmt := sqlutil.TxStmt(txn, s.deleteRoomAliasStmt)
|
||||||
|
_, err = stmt.ExecContext(ctx, alias)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -114,8 +114,8 @@ func (d *Database) EventNIDs(
|
||||||
func (d *Database) SetState(
|
func (d *Database) SetState(
|
||||||
ctx context.Context, eventNID types.EventNID, stateNID types.StateSnapshotNID,
|
ctx context.Context, eventNID types.EventNID, stateNID types.StateSnapshotNID,
|
||||||
) error {
|
) error {
|
||||||
return d.Writer.Do(d.DB, nil, func(_ *sql.Tx) error {
|
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
return d.EventsTable.UpdateEventState(ctx, eventNID, stateNID)
|
return d.EventsTable.UpdateEventState(ctx, txn, eventNID, stateNID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,8 +224,8 @@ func (d *Database) GetRoomVersionForRoomNID(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) SetRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) error {
|
func (d *Database) SetRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) error {
|
||||||
return d.Writer.Do(d.DB, nil, func(_ *sql.Tx) error {
|
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
return d.RoomAliasesTable.InsertRoomAlias(ctx, alias, roomID, creatorUserID)
|
return d.RoomAliasesTable.InsertRoomAlias(ctx, txn, alias, roomID, creatorUserID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,8 +244,8 @@ func (d *Database) GetCreatorIDForAlias(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) RemoveRoomAlias(ctx context.Context, alias string) error {
|
func (d *Database) RemoveRoomAlias(ctx context.Context, alias string) error {
|
||||||
return d.Writer.Do(d.DB, nil, func(_ *sql.Tx) error {
|
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
return d.RoomAliasesTable.DeleteRoomAlias(ctx, alias)
|
return d.RoomAliasesTable.DeleteRoomAlias(ctx, txn, alias)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -471,8 +471,8 @@ func (d *Database) StoreEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) PublishRoom(ctx context.Context, roomID string, publish bool) error {
|
func (d *Database) PublishRoom(ctx context.Context, roomID string, publish bool) error {
|
||||||
return d.Writer.Do(d.DB, nil, func(_ *sql.Tx) error {
|
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
return d.PublishedTable.UpsertRoomPublished(ctx, roomID, publish)
|
return d.PublishedTable.UpsertRoomPublished(ctx, txn, roomID, publish)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -279,9 +279,10 @@ func (s *eventStatements) BulkSelectStateAtEventByID(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *eventStatements) UpdateEventState(
|
func (s *eventStatements) UpdateEventState(
|
||||||
ctx context.Context, eventNID types.EventNID, stateNID types.StateSnapshotNID,
|
ctx context.Context, txn *sql.Tx, eventNID types.EventNID, stateNID types.StateSnapshotNID,
|
||||||
) error {
|
) error {
|
||||||
_, err := s.updateEventStateStmt.ExecContext(ctx, int64(stateNID), int64(eventNID))
|
stmt := sqlutil.TxStmt(txn, s.updateEventStateStmt)
|
||||||
|
_, err := stmt.ExecContext(ctx, int64(stateNID), int64(eventNID))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||||
)
|
)
|
||||||
|
|
@ -65,9 +66,10 @@ func NewSqlitePublishedTable(db *sql.DB) (tables.Published, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *publishedStatements) UpsertRoomPublished(
|
func (s *publishedStatements) UpsertRoomPublished(
|
||||||
ctx context.Context, roomID string, published bool,
|
ctx context.Context, txn *sql.Tx, roomID string, published bool,
|
||||||
) error {
|
) error {
|
||||||
_, err := s.upsertPublishedStmt.ExecContext(ctx, roomID, published)
|
stmt := sqlutil.TxStmt(txn, s.upsertPublishedStmt)
|
||||||
|
_, err := stmt.ExecContext(ctx, roomID, published)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||||
)
|
)
|
||||||
|
|
@ -81,9 +82,10 @@ func NewSqliteRoomAliasesTable(db *sql.DB) (tables.RoomAliases, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *roomAliasesStatements) InsertRoomAlias(
|
func (s *roomAliasesStatements) InsertRoomAlias(
|
||||||
ctx context.Context, alias string, roomID string, creatorUserID string,
|
ctx context.Context, txn *sql.Tx, alias string, roomID string, creatorUserID string,
|
||||||
) error {
|
) error {
|
||||||
_, err := s.insertRoomAliasStmt.ExecContext(ctx, alias, roomID, creatorUserID)
|
stmt := sqlutil.TxStmt(txn, s.insertRoomAliasStmt)
|
||||||
|
_, err := stmt.ExecContext(ctx, alias, roomID, creatorUserID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,8 +133,9 @@ func (s *roomAliasesStatements) SelectCreatorIDFromAlias(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *roomAliasesStatements) DeleteRoomAlias(
|
func (s *roomAliasesStatements) DeleteRoomAlias(
|
||||||
ctx context.Context, alias string,
|
ctx context.Context, txn *sql.Tx, alias string,
|
||||||
) error {
|
) error {
|
||||||
_, err := s.deleteRoomAliasStmt.ExecContext(ctx, alias)
|
stmt := sqlutil.TxStmt(txn, s.deleteRoomAliasStmt)
|
||||||
|
_, err := stmt.ExecContext(ctx, alias)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ type Events interface {
|
||||||
// If any of the requested events are missing from the database it returns a types.MissingEventError.
|
// If any of the requested events are missing from the database it returns a types.MissingEventError.
|
||||||
// If we do not have the state for any of the requested events it returns a types.MissingEventError.
|
// If we do not have the state for any of the requested events it returns a types.MissingEventError.
|
||||||
BulkSelectStateAtEventByID(ctx context.Context, eventIDs []string) ([]types.StateAtEvent, error)
|
BulkSelectStateAtEventByID(ctx context.Context, eventIDs []string) ([]types.StateAtEvent, error)
|
||||||
UpdateEventState(ctx context.Context, eventNID types.EventNID, stateNID types.StateSnapshotNID) error
|
UpdateEventState(ctx context.Context, txn *sql.Tx, eventNID types.EventNID, stateNID types.StateSnapshotNID) error
|
||||||
SelectEventSentToOutput(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) (sentToOutput bool, err error)
|
SelectEventSentToOutput(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) (sentToOutput bool, err error)
|
||||||
UpdateEventSentToOutput(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) error
|
UpdateEventSentToOutput(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) error
|
||||||
SelectEventID(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) (eventID string, err error)
|
SelectEventID(ctx context.Context, txn *sql.Tx, eventNID types.EventNID) (eventID string, err error)
|
||||||
|
|
@ -84,11 +84,11 @@ type StateBlock interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RoomAliases interface {
|
type RoomAliases interface {
|
||||||
InsertRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) (err error)
|
InsertRoomAlias(ctx context.Context, txn *sql.Tx, alias string, roomID string, creatorUserID string) (err error)
|
||||||
SelectRoomIDFromAlias(ctx context.Context, alias string) (roomID string, err error)
|
SelectRoomIDFromAlias(ctx context.Context, alias string) (roomID string, err error)
|
||||||
SelectAliasesFromRoomID(ctx context.Context, roomID string) ([]string, error)
|
SelectAliasesFromRoomID(ctx context.Context, roomID string) ([]string, error)
|
||||||
SelectCreatorIDFromAlias(ctx context.Context, alias string) (creatorID string, err error)
|
SelectCreatorIDFromAlias(ctx context.Context, alias string) (creatorID string, err error)
|
||||||
DeleteRoomAlias(ctx context.Context, alias string) (err error)
|
DeleteRoomAlias(ctx context.Context, txn *sql.Tx, alias string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PreviousEvents interface {
|
type PreviousEvents interface {
|
||||||
|
|
@ -123,7 +123,7 @@ type Membership interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Published interface {
|
type Published interface {
|
||||||
UpsertRoomPublished(ctx context.Context, roomID string, published bool) (err error)
|
UpsertRoomPublished(ctx context.Context, txn *sql.Tx, roomID string, published bool) (err error)
|
||||||
SelectPublishedFromRoomID(ctx context.Context, roomID string) (published bool, err error)
|
SelectPublishedFromRoomID(ctx context.Context, roomID string) (published bool, err error)
|
||||||
SelectAllPublishedRooms(ctx context.Context, published bool) ([]string, error)
|
SelectAllPublishedRooms(ctx context.Context, published bool) ([]string, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue