Skip to content

Commit

Permalink
manually rollback failed tx as its causing idle connections (#1881)
Browse files Browse the repository at this point in the history
  • Loading branch information
badgersrus authored Apr 22, 2024
1 parent 3df0495 commit 2dde817
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions go/host/storage/hostdb/hostdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ func (b *dbTransaction) Write() error {
}
return nil
}

func (b *dbTransaction) Rollback() error {
if err := b.tx.Rollback(); err != nil {
return fmt.Errorf("failed to rollback host transaction. Cause: %w", err)
}
return nil
}
9 changes: 9 additions & 0 deletions go/host/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func (s *storageImpl) AddBatch(batch *common.ExtBatch) error {
}

if err := hostdb.AddBatch(dbtx, s.db.GetSQLStatement(), batch); err != nil {
if err := dbtx.Rollback(); err != nil {
return err
}
return fmt.Errorf("could not add batch to host. Cause: %w", err)
}

Expand All @@ -56,6 +59,9 @@ func (s *storageImpl) AddRollup(rollup *common.ExtRollup, metadata *common.Publi
}

if err := hostdb.AddRollup(dbtx, s.db.GetSQLStatement(), rollup, metadata, block); err != nil {
if err := dbtx.Rollback(); err != nil {
return err
}
return fmt.Errorf("could not add rollup to host. Cause: %w", err)
}

Expand All @@ -72,6 +78,9 @@ func (s *storageImpl) AddBlock(b *types.Header, rollupHash common.L2RollupHash)
}

if err := hostdb.AddBlock(dbtx, s.db.GetSQLStatement(), b, rollupHash); err != nil {
if err := dbtx.Rollback(); err != nil {
return err
}
return fmt.Errorf("could not add block to host. Cause: %w", err)
}

Expand Down

0 comments on commit 2dde817

Please sign in to comment.