diff options
| author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-25 08:31:04 -0700 |
|---|---|---|
| committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-25 08:31:04 -0700 |
| commit | 41fb285e37bc0767f5cc5b2b91c58aef60695922 (patch) | |
| tree | e93032c8de0b1460d9f0b8a198a4eee41c0b1437 /transaction.go | |
| parent | Merge pull request #51 from benbjohnson/bucket-refactor (diff) | |
| download | dedo-41fb285e37bc0767f5cc5b2b91c58aef60695922.tar.gz dedo-41fb285e37bc0767f5cc5b2b91c58aef60695922.tar.xz | |
Remove RWTransaction.Bucket().
Add an reference to the RWTransaction onto Transaction so that calls to
Transaction.Bucket() and Transaction.Buckets() return writable buckets
when attached to a writabe transaction.
Diffstat (limited to '')
| -rw-r--r-- | transaction.go | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/transaction.go b/transaction.go index f62db8c..90f388b 100644 --- a/transaction.go +++ b/transaction.go @@ -8,10 +8,11 @@ package bolt // can not be reclaimed by the writer until no more transactions are using them. // A long running read transaction can cause the database to quickly grow. type Transaction struct { - db *DB - meta *meta - buckets *buckets - pages map[pgid]*page + db *DB + rwtransaction *RWTransaction + meta *meta + buckets *buckets + pages map[pgid]*page } // txnid represents the internal transaction identifier. @@ -38,6 +39,9 @@ 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() + } t.db.removeTransaction(t) } @@ -46,7 +50,7 @@ func (t *Transaction) DB() *DB { return t.db } -// Bucket retrieves a read-only bucket by name. +// Bucket retrieves a bucket by name. // Returns nil if the bucket does not exist. func (t *Transaction) Bucket(name string) *Bucket { b := t.buckets.get(name) @@ -55,18 +59,23 @@ func (t *Transaction) Bucket(name string) *Bucket { } return &Bucket{ - bucket: b, - name: name, - transaction: t, + bucket: b, + name: name, + transaction: t, + rwtransaction: t.rwtransaction, } } // Buckets retrieves a list of all buckets. -// All returned buckets are read-only. func (t *Transaction) Buckets() []*Bucket { buckets := make([]*Bucket, 0, len(t.buckets.items)) for name, b := range t.buckets.items { - bucket := &Bucket{bucket: b, transaction: t, name: name} + bucket := &Bucket{ + bucket: b, + name: name, + transaction: t, + rwtransaction: t.rwtransaction, + } buckets = append(buckets, bucket) } return buckets |
