aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-10-20 19:32:33 +0100
committerGitHub <noreply@github.com>2020-10-20 19:32:33 +0100
commit6b8791b8688991ad04e8231af3838aa090c6bd52 (patch)
tree92f1d85d8adc05b7c7617b9c8432f2ab4422febd
parent7612f64e3c177b388420699f3fec4ecb563b66ee (diff)
Always call overridden form of GetLatestEventsForUpdate (#1554)
This ensures we don't make txns on sqlite still, which can cause 'database is locked' errors.
-rw-r--r--roomserver/storage/shared/storage.go38
-rw-r--r--roomserver/storage/sqlite3/storage.go35
2 files changed, 39 insertions, 34 deletions
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index 51dcb888..aec15ab2 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -27,23 +27,24 @@ import (
const redactionsArePermanent = true
type Database struct {
- DB *sql.DB
- Cache caching.RoomServerCaches
- Writer sqlutil.Writer
- EventsTable tables.Events
- EventJSONTable tables.EventJSON
- EventTypesTable tables.EventTypes
- EventStateKeysTable tables.EventStateKeys
- RoomsTable tables.Rooms
- TransactionsTable tables.Transactions
- StateSnapshotTable tables.StateSnapshot
- StateBlockTable tables.StateBlock
- RoomAliasesTable tables.RoomAliases
- PrevEventsTable tables.PreviousEvents
- InvitesTable tables.Invites
- MembershipTable tables.Membership
- PublishedTable tables.Published
- RedactionsTable tables.Redactions
+ DB *sql.DB
+ Cache caching.RoomServerCaches
+ Writer sqlutil.Writer
+ EventsTable tables.Events
+ EventJSONTable tables.EventJSON
+ EventTypesTable tables.EventTypes
+ EventStateKeysTable tables.EventStateKeys
+ RoomsTable tables.Rooms
+ TransactionsTable tables.Transactions
+ StateSnapshotTable tables.StateSnapshot
+ StateBlockTable tables.StateBlock
+ RoomAliasesTable tables.RoomAliases
+ PrevEventsTable tables.PreviousEvents
+ InvitesTable tables.Invites
+ MembershipTable tables.Membership
+ PublishedTable tables.Published
+ RedactionsTable tables.Redactions
+ GetLatestEventsForUpdateFn func(ctx context.Context, roomInfo types.RoomInfo) (*LatestEventsUpdater, error)
}
func (d *Database) SupportsConcurrentRoomInputs() bool {
@@ -372,6 +373,9 @@ func (d *Database) MembershipUpdater(
func (d *Database) GetLatestEventsForUpdate(
ctx context.Context, roomInfo types.RoomInfo,
) (*LatestEventsUpdater, error) {
+ if d.GetLatestEventsForUpdateFn != nil {
+ return d.GetLatestEventsForUpdateFn(ctx, roomInfo)
+ }
txn, err := d.DB.Begin()
if err != nil {
return nil, err
diff --git a/roomserver/storage/sqlite3/storage.go b/roomserver/storage/sqlite3/storage.go
index 4a74bf73..6d9b860f 100644
--- a/roomserver/storage/sqlite3/storage.go
+++ b/roomserver/storage/sqlite3/storage.go
@@ -120,23 +120,24 @@ func Open(dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches)
return nil, err
}
d.Database = shared.Database{
- DB: d.db,
- Cache: cache,
- Writer: d.writer,
- EventsTable: d.events,
- EventTypesTable: d.eventTypes,
- EventStateKeysTable: d.eventStateKeys,
- EventJSONTable: d.eventJSON,
- RoomsTable: d.rooms,
- TransactionsTable: d.transactions,
- StateBlockTable: stateBlock,
- StateSnapshotTable: stateSnapshot,
- PrevEventsTable: d.prevEvents,
- RoomAliasesTable: roomAliases,
- InvitesTable: d.invites,
- MembershipTable: d.membership,
- PublishedTable: published,
- RedactionsTable: redactions,
+ DB: d.db,
+ Cache: cache,
+ Writer: d.writer,
+ EventsTable: d.events,
+ EventTypesTable: d.eventTypes,
+ EventStateKeysTable: d.eventStateKeys,
+ EventJSONTable: d.eventJSON,
+ RoomsTable: d.rooms,
+ TransactionsTable: d.transactions,
+ StateBlockTable: stateBlock,
+ StateSnapshotTable: stateSnapshot,
+ PrevEventsTable: d.prevEvents,
+ RoomAliasesTable: roomAliases,
+ InvitesTable: d.invites,
+ MembershipTable: d.membership,
+ PublishedTable: published,
+ RedactionsTable: redactions,
+ GetLatestEventsForUpdateFn: d.GetLatestEventsForUpdate,
}
return &d, nil
}