Skip to content

Commit

Permalink
fix(errors): log when a deferred transaction rollback does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
tgragnato committed Jan 17, 2024
1 parent 61f4f66 commit 7d51e71
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion mold/count.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mold

import (
"github.com/sirupsen/logrus"
"github.com/xujiajun/nutsdb"
)

Expand All @@ -14,7 +15,12 @@ func (db *Mold) Count(filter string) (int, error) {
if err != nil {
return -1, err
}
defer tx.Rollback()
defer func() {
err := tx.Rollback()
if err != nil {
logrus.Debugln(err.Error())
}
}()

if filter != "" {
data, _, err = tx.PrefixSearchScan(bucket, []byte{}, filter, 0, -1)
Expand Down
8 changes: 7 additions & 1 deletion mold/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ package mold
import (
_event "github.com/immobiliare/peephole/mold/event"
_util "github.com/immobiliare/peephole/util"
"github.com/sirupsen/logrus"
)

func (db *Mold) Read(id string) (*_event.Event, error) {
tx, err := db.Begin(false)
if err != nil {
return nil, err
}
defer tx.Rollback()
defer func() {
err := tx.Rollback()
if err != nil {
logrus.Debugln(err.Error())
}
}()

data, err := tx.Get(bucket, []byte(id))
if err != nil && err.Error() == "key not found" {
Expand Down
8 changes: 7 additions & 1 deletion mold/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mold
import (
_event "github.com/immobiliare/peephole/mold/event"
_util "github.com/immobiliare/peephole/util"
"github.com/sirupsen/logrus"
"github.com/xujiajun/nutsdb"
)

Expand All @@ -16,7 +17,12 @@ func (db *Mold) Select(filter string, page, limit int) ([]_event.Event, error) {
if err != nil {
return []_event.Event{}, err
}
defer tx.Rollback()
defer func() {
err := tx.Rollback()
if err != nil {
logrus.Debugln(err.Error())
}
}()

if filter != "" {
data, _, err = tx.PrefixSearchScan(bucket, []byte{}, filter, page*limit, limit)
Expand Down

0 comments on commit 7d51e71

Please sign in to comment.