Rollback closes the transaction.
()
| 534 | |
| 535 | // Rollback closes the transaction. |
| 536 | func (tx *Tx) Rollback() error { |
| 537 | if tx.db == nil { |
| 538 | tx.setStatusClosed() |
| 539 | return ErrDBClosed |
| 540 | } |
| 541 | if tx.isCommitting() { |
| 542 | return ErrCannotRollbackACommittingTx |
| 543 | } |
| 544 | |
| 545 | if tx.isClosed() { |
| 546 | return ErrCannotRollbackAClosedTx |
| 547 | } |
| 548 | |
| 549 | tx.setStatusClosed() |
| 550 | tx.unlock() |
| 551 | |
| 552 | // Unregister from TransactionManager so active tracking stays correct |
| 553 | tx.db.transactionMgr.UnregisterTx(tx.id) |
| 554 | |
| 555 | tx.db = nil |
| 556 | tx.pendingWrites = nil |
| 557 | |
| 558 | return nil |
| 559 | } |
| 560 | |
| 561 | // lock locks the database based on the transaction type. |
| 562 | func (tx *Tx) lock() { |