MCPcopy
hub / github.com/apache/casbin / Rollback

Method Rollback

transaction_commit.go:105–132  ·  view source on GitHub ↗

Rollback rolls back the transaction. This will rollback the database transaction and clear the transaction state.

()

Source from the content-addressed store, hash-verified

103// Rollback rolls back the transaction.
104// This will rollback the database transaction and clear the transaction state.
105func (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.
135func (tx *Transaction) applyOperationsToDatabase() error {

Callers

nothing calls this directly

Calls 3

tryLockWithTimeoutFunction · 0.85
DeleteMethod · 0.65
RollbackMethod · 0.65

Tested by

no test coverage detected