mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
Return errors from Do, fix dendritejs
This commit is contained in:
parent
e323bba3fd
commit
6158a8dcc5
|
|
@ -209,7 +209,7 @@ func main() {
|
||||||
p2pPublicRoomProvider := NewLibP2PPublicRoomsProvider(node)
|
p2pPublicRoomProvider := NewLibP2PPublicRoomsProvider(node)
|
||||||
|
|
||||||
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
||||||
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
|
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New(), deviceDB)
|
||||||
asQuery := appservice.SetupAppServiceAPIComponent(
|
asQuery := appservice.SetupAppServiceAPIComponent(
|
||||||
base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
|
base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -123,14 +123,14 @@ type TransactionWriter struct {
|
||||||
// transactionWriterTask represents a specific task.
|
// transactionWriterTask represents a specific task.
|
||||||
type transactionWriterTask struct {
|
type transactionWriterTask struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
f func(txn *sql.Tx)
|
f func(txn *sql.Tx) error
|
||||||
wait chan struct{}
|
wait chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do queues a task to be run by a TransactionWriter. The function
|
// Do queues a task to be run by a TransactionWriter. The function
|
||||||
// provided will be ran within a transaction as supplied by the
|
// provided will be ran within a transaction as supplied by the
|
||||||
// database parameter. This will block until the task is finished.
|
// database parameter. This will block until the task is finished.
|
||||||
func (w *TransactionWriter) Do(db *sql.DB, f func(txn *sql.Tx)) {
|
func (w *TransactionWriter) Do(db *sql.DB, f func(txn *sql.Tx) error) error {
|
||||||
if w.todo == nil {
|
if w.todo == nil {
|
||||||
w.todo = make(chan transactionWriterTask)
|
w.todo = make(chan transactionWriterTask)
|
||||||
}
|
}
|
||||||
|
|
@ -140,10 +140,10 @@ func (w *TransactionWriter) Do(db *sql.DB, f func(txn *sql.Tx)) {
|
||||||
task := transactionWriterTask{
|
task := transactionWriterTask{
|
||||||
db: db,
|
db: db,
|
||||||
f: f,
|
f: f,
|
||||||
wait: make(chan struct{}),
|
wait: make(chan error, 1),
|
||||||
}
|
}
|
||||||
w.todo <- task
|
w.todo <- task
|
||||||
<-task.wait
|
return <-task.wait
|
||||||
}
|
}
|
||||||
|
|
||||||
// run processes the tasks for a given transaction writer. Only one
|
// run processes the tasks for a given transaction writer. Only one
|
||||||
|
|
@ -156,9 +156,8 @@ func (w *TransactionWriter) run() {
|
||||||
}
|
}
|
||||||
defer w.running.Store(false)
|
defer w.running.Store(false)
|
||||||
for task := range w.todo {
|
for task := range w.todo {
|
||||||
_ = WithTransaction(task.db, func(txn *sql.Tx) error {
|
task.wait <- WithTransaction(task.db, func(txn *sql.Tx) error {
|
||||||
task.f(txn)
|
return task.f(txn)
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
close(task.wait)
|
close(task.wait)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1078,8 +1078,8 @@ func (d *Database) StoreNewSendForDeviceMessage(
|
||||||
}
|
}
|
||||||
// Delegate the database write task to the SendToDeviceWriter. It'll guarantee
|
// Delegate the database write task to the SendToDeviceWriter. It'll guarantee
|
||||||
// that we don't lock the table for writes in more than one place.
|
// that we don't lock the table for writes in more than one place.
|
||||||
d.SendToDeviceWriter.Do(d.DB, func(txn *sql.Tx) {
|
err = d.SendToDeviceWriter.Do(d.DB, func(txn *sql.Tx) error {
|
||||||
err = d.AddSendToDeviceEvent(
|
return d.AddSendToDeviceEvent(
|
||||||
ctx, txn, userID, deviceID, string(j),
|
ctx, txn, userID, deviceID, string(j),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
@ -1143,18 +1143,18 @@ func (d *Database) CleanSendToDeviceUpdates(
|
||||||
// If we need to write to the database then we'll ask the SendToDeviceWriter to
|
// If we need to write to the database then we'll ask the SendToDeviceWriter to
|
||||||
// do that for us. It'll guarantee that we don't lock the table for writes in
|
// do that for us. It'll guarantee that we don't lock the table for writes in
|
||||||
// more than one place.
|
// more than one place.
|
||||||
d.SendToDeviceWriter.Do(d.DB, func(txn *sql.Tx) {
|
err = d.SendToDeviceWriter.Do(d.DB, func(txn *sql.Tx) error {
|
||||||
// Delete any send-to-device messages marked for deletion.
|
// Delete any send-to-device messages marked for deletion.
|
||||||
if e := d.SendToDevice.DeleteSendToDeviceMessages(ctx, txn, toDelete); e != nil {
|
if e := d.SendToDevice.DeleteSendToDeviceMessages(ctx, txn, toDelete); e != nil {
|
||||||
err = fmt.Errorf("d.SendToDevice.DeleteSendToDeviceMessages: %w", e)
|
return fmt.Errorf("d.SendToDevice.DeleteSendToDeviceMessages: %w", e)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now update any outstanding send-to-device messages with the new sync token.
|
// Now update any outstanding send-to-device messages with the new sync token.
|
||||||
if e := d.SendToDevice.UpdateSentSendToDeviceMessages(ctx, txn, token.String(), toUpdate); e != nil {
|
if e := d.SendToDevice.UpdateSentSendToDeviceMessages(ctx, txn, token.String(), toUpdate); e != nil {
|
||||||
err = fmt.Errorf("d.SendToDevice.UpdateSentSendToDeviceMessages: %w", err)
|
return fmt.Errorf("d.SendToDevice.UpdateSentSendToDeviceMessages: %w", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue