aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-03-01 12:53:05 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-03-01 12:53:05 -0700
commit3a1b152562a98de231f73e35c4df03994268328e (patch)
treef5ea028ad0f740234b4f8a54a6dc137259b84db1
parentMerge pull request #57 from benbjohnson/node-aware-cursors (diff)
downloaddedo-3a1b152562a98de231f73e35c4df03994268328e.tar.gz
dedo-3a1b152562a98de231f73e35c4df03994268328e.tar.xz
Ignore multiple transaction commit/rollback/close.
-rw-r--r--db.go2
-rw-r--r--rwtransaction.go9
-rw-r--r--transaction.go10
3 files changed, 16 insertions, 5 deletions
diff --git a/db.go b/db.go
index 8403afc..30b5c47 100644
--- a/db.go
+++ b/db.go
@@ -571,7 +571,7 @@ func (db *DB) Stat() (*Stat, error) {
// page retrieves a page reference from the mmap based on the current page size.
func (db *DB) page(id pgid) *page {
- pos := id*pgid(db.pageSize)
+ pos := id * pgid(db.pageSize)
return (*page)(unsafe.Pointer(&db.data[pos]))
}
diff --git a/rwtransaction.go b/rwtransaction.go
index f47597f..776cf55 100644
--- a/rwtransaction.go
+++ b/rwtransaction.go
@@ -82,6 +82,10 @@ func (t *RWTransaction) 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 *RWTransaction) Commit() error {
+ if t.db == nil {
+ return nil
+ }
+
defer t.close()
// TODO(benbjohnson): Use vectorized I/O to write out dirty pages.
@@ -119,7 +123,10 @@ func (t *RWTransaction) Rollback() {
}
func (t *RWTransaction) close() {
- t.db.rwlock.Unlock()
+ if t.db != nil {
+ t.db.rwlock.Unlock()
+ t.db = nil
+ }
}
// allocate returns a contiguous block of memory starting at a given page.
diff --git a/transaction.go b/transaction.go
index d680e24..857defb 100644
--- a/transaction.go
+++ b/transaction.go
@@ -40,10 +40,14 @@ func (t *Transaction) id() txnid {
// Close closes the transaction and releases any pages it is using.
func (t *Transaction) Close() {
- if t.rwtransaction != nil {
- t.rwtransaction.Rollback()
+ if t.db != nil {
+ if t.rwtransaction != nil {
+ t.rwtransaction.Rollback()
+ } else {
+ t.db.removeTransaction(t)
+ t.db = nil
+ }
}
- t.db.removeTransaction(t)
}
// DB returns a reference to the database that created the transaction.