mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 05:12:46 +00:00
Reset transaction after a failure
This commit is contained in:
parent
16048be236
commit
0116db79c6
11 changed files with 40 additions and 17 deletions
|
@ -29,6 +29,7 @@ import (
|
|||
|
||||
type DatabaseTransaction interface {
|
||||
sqlutil.Transaction
|
||||
Reset() (err error)
|
||||
SharedUsers
|
||||
|
||||
MaxStreamPositionForPDUs(ctx context.Context) (types.StreamPosition, error)
|
||||
|
|
|
@ -77,6 +77,7 @@ func (d *Database) NewDatabaseSnapshot(ctx context.Context) (*DatabaseTransactio
|
|||
}
|
||||
return &DatabaseTransaction{
|
||||
Database: d,
|
||||
ctx: ctx,
|
||||
txn: txn,
|
||||
}, nil
|
||||
*/
|
||||
|
@ -89,6 +90,7 @@ func (d *Database) NewDatabaseTransaction(ctx context.Context) (*DatabaseTransac
|
|||
}
|
||||
return &DatabaseTransaction{
|
||||
Database: d,
|
||||
ctx: ctx,
|
||||
txn: txn,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
type DatabaseTransaction struct {
|
||||
*Database
|
||||
ctx context.Context
|
||||
txn *sql.Tx
|
||||
}
|
||||
|
||||
|
@ -30,6 +31,19 @@ func (d *DatabaseTransaction) Rollback() error {
|
|||
return d.txn.Rollback()
|
||||
}
|
||||
|
||||
func (d *DatabaseTransaction) Reset() (err error) {
|
||||
if d.txn == nil {
|
||||
return nil
|
||||
}
|
||||
if err = d.txn.Rollback(); err != nil {
|
||||
return err
|
||||
}
|
||||
if d.txn, err = d.DB.BeginTx(d.ctx, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *DatabaseTransaction) MaxStreamPositionForPDUs(ctx context.Context) (types.StreamPosition, error) {
|
||||
id, err := d.OutputEvents.SelectMaxEventID(ctx, d.txn)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue