mirror of
https://github.com/etcd-io/bbolt.git
synced 2025-05-31 11:42:30 +00:00
Ignore multiple transaction commit/rollback/close.
This commit is contained in:
parent
7214e089c0
commit
3a1b152562
@ -82,6 +82,10 @@ func (t *RWTransaction) DeleteBucket(name string) error {
|
|||||||
// Commit writes all changes to disk and updates the meta page.
|
// Commit writes all changes to disk and updates the meta page.
|
||||||
// Returns an error if a disk write error occurs.
|
// Returns an error if a disk write error occurs.
|
||||||
func (t *RWTransaction) Commit() error {
|
func (t *RWTransaction) Commit() error {
|
||||||
|
if t.db == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
defer t.close()
|
defer t.close()
|
||||||
|
|
||||||
// TODO(benbjohnson): Use vectorized I/O to write out dirty pages.
|
// TODO(benbjohnson): Use vectorized I/O to write out dirty pages.
|
||||||
@ -119,7 +123,10 @@ func (t *RWTransaction) Rollback() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *RWTransaction) close() {
|
func (t *RWTransaction) close() {
|
||||||
|
if t.db != nil {
|
||||||
t.db.rwlock.Unlock()
|
t.db.rwlock.Unlock()
|
||||||
|
t.db = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate returns a contiguous block of memory starting at a given page.
|
// allocate returns a contiguous block of memory starting at a given page.
|
||||||
|
@ -40,10 +40,14 @@ func (t *Transaction) id() txnid {
|
|||||||
|
|
||||||
// Close closes the transaction and releases any pages it is using.
|
// Close closes the transaction and releases any pages it is using.
|
||||||
func (t *Transaction) Close() {
|
func (t *Transaction) Close() {
|
||||||
|
if t.db != nil {
|
||||||
if t.rwtransaction != nil {
|
if t.rwtransaction != nil {
|
||||||
t.rwtransaction.Rollback()
|
t.rwtransaction.Rollback()
|
||||||
}
|
} else {
|
||||||
t.db.removeTransaction(t)
|
t.db.removeTransaction(t)
|
||||||
|
t.db = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DB returns a reference to the database that created the transaction.
|
// DB returns a reference to the database that created the transaction.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user