diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-03-23 10:34:53 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-03-23 10:34:53 -0600 |
commit | 76f6ead6b0c5bbdc6eaaf487a896e63e6ecf7bc6 (patch) | |
tree | 96a0dbb8820c3eec1a596363875d75f80acd68ca /tx.go | |
parent | Merge pull request #76 from benbjohnson/fsync (diff) | |
download | dedo-76f6ead6b0c5bbdc6eaaf487a896e63e6ecf7bc6.tar.gz dedo-76f6ead6b0c5bbdc6eaaf487a896e63e6ecf7bc6.tar.xz |
Mark Do()/With() transaction as managed.
Transaction created from Do() and With() are now considered "managed".
Managed transactions cannot be manually committed or rolled back since
the Do() and With() functions provide that functionally automatically.
Previously, a Tx could be manually committed and then any changes after
that would be lost.
Diffstat (limited to 'tx.go')
-rw-r--r-- | tx.go | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -18,6 +18,7 @@ type txid uint64 // quickly grow. type Tx struct { writable bool + managed bool db *DB meta *meta buckets *buckets @@ -155,7 +156,9 @@ func (t *Tx) DeleteBucket(name string) error { // Commit writes all changes to disk and updates the meta page. // Returns an error if a disk write error occurs. func (t *Tx) Commit() error { - if t.db == nil { + if t.managed { + panic("managed tx commit not allowed") + } else if t.db == nil { return nil } else if !t.writable { t.Rollback() @@ -194,6 +197,9 @@ func (t *Tx) Commit() error { // Rollback closes the transaction and ignores all previous updates. func (t *Tx) Rollback() { + if t.managed { + panic("managed tx rollback not allowed") + } t.close() } |