Skip to content

Commit

Permalink
Refactor Rollback -> Discard
Browse files Browse the repository at this point in the history
  • Loading branch information
bigs committed Aug 7, 2018
1 parent 176b871 commit c2b3791
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (d *datastore) NewTransaction(readOnly bool) ds.Txn {

func (d *datastore) Put(key ds.Key, value interface{}) error {
txn := d.NewTransaction(false)
defer txn.Rollback()
defer txn.Discard()

if err := txn.Put(key, value); err != nil {
return err
Expand All @@ -90,7 +90,7 @@ func (d *datastore) Put(key ds.Key, value interface{}) error {

func (d *datastore) PutWithTTL(key ds.Key, value interface{}, ttl time.Duration) error {
txn := d.NewTransaction(false).(*txn)
defer txn.Rollback()
defer txn.Discard()

if err := txn.PutWithTTL(key, value, ttl); err != nil {
return err
Expand All @@ -101,7 +101,7 @@ func (d *datastore) PutWithTTL(key ds.Key, value interface{}, ttl time.Duration)

func (d *datastore) SetTTL(key ds.Key, ttl time.Duration) error {
txn := d.NewTransaction(false).(*txn)
defer txn.Rollback()
defer txn.Discard()

if err := txn.SetTTL(key, ttl); err != nil {
return err
Expand All @@ -112,21 +112,21 @@ func (d *datastore) SetTTL(key ds.Key, ttl time.Duration) error {

func (d *datastore) Get(key ds.Key) (value interface{}, err error) {
txn := d.NewTransaction(true)
defer txn.Rollback()
defer txn.Discard()

return txn.Get(key)
}

func (d *datastore) Has(key ds.Key) (bool, error) {
txn := d.NewTransaction(true)
defer txn.Rollback()
defer txn.Discard()

return txn.Has(key)
}

func (d *datastore) Delete(key ds.Key) error {
txn := d.NewTransaction(false)
defer txn.Rollback()
defer txn.Discard()

err := txn.Delete(key)
if err != nil {
Expand All @@ -138,7 +138,7 @@ func (d *datastore) Delete(key ds.Key) error {

func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
txn := d.NewTransaction(true)
defer txn.Rollback()
defer txn.Discard()

return txn.Query(q)
}
Expand Down Expand Up @@ -304,6 +304,6 @@ func (t *txn) Commit() error {
return t.txn.Commit(nil)
}

func (t *txn) Rollback() {
func (t *txn) Discard() {
t.txn.Discard()
}
6 changes: 3 additions & 3 deletions ds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func TestDiskUsage(t *testing.T) {
d.Close()
}

func TestTxnRollback(t *testing.T) {
func TestTxnDiscard(t *testing.T) {
d, err := NewDatastore("/tmp/testing_badger_du", nil)
defer os.RemoveAll("/tmp/testing_badger_du")
if err != nil {
Expand All @@ -561,7 +561,7 @@ func TestTxnRollback(t *testing.T) {
if err := txn.Put(key, []byte{1, 2, 3}); err != nil {
t.Fatal(err)
}
txn.Rollback()
txn.Discard()
has, err := d.Has(key)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -684,7 +684,7 @@ func TestTTL(t *testing.T) {
t.Fatal(err)
}
}
txn.Rollback()
txn.Discard()

time.Sleep(time.Second)

Expand Down

0 comments on commit c2b3791

Please sign in to comment.