Rollback rolls back the transaction. This will rollback the database transaction and clear the transaction state.
()
| 103 | // Rollback rolls back the transaction. |
| 104 | // This will rollback the database transaction and clear the transaction state. |
| 105 | func (tx *Transaction) Rollback() error { |
| 106 | // Try to acquire the commit lock with timeout. |
| 107 | if !tryLockWithTimeout(&tx.enforcer.commitLock, tx.startTime, defaultLockTimeout) { |
| 108 | tx.enforcer.activeTransactions.Delete(tx.id) |
| 109 | return errors.New("transaction timeout: failed to acquire lock for rollback") |
| 110 | } |
| 111 | defer tx.enforcer.commitLock.Unlock() |
| 112 | |
| 113 | tx.mutex.Lock() |
| 114 | defer tx.mutex.Unlock() |
| 115 | |
| 116 | if tx.committed { |
| 117 | return errors.New("transaction already committed") |
| 118 | } |
| 119 | if tx.rolledBack { |
| 120 | return errors.New("transaction already rolled back") |
| 121 | } |
| 122 | |
| 123 | // Rollback database transaction. |
| 124 | if err := tx.txContext.Rollback(); err != nil { |
| 125 | return err |
| 126 | } |
| 127 | |
| 128 | tx.rolledBack = true |
| 129 | tx.enforcer.activeTransactions.Delete(tx.id) |
| 130 | |
| 131 | return nil |
| 132 | } |
| 133 | |
| 134 | // applyOperationsToDatabase applies all buffered operations to the database. |
| 135 | func (tx *Transaction) applyOperationsToDatabase() error { |
nothing calls this directly
no test coverage detected