File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,7 @@ type DB struct {
132
132
pageSize int
133
133
opened bool
134
134
rwtx * Tx
135
+ txs []* Tx
135
136
136
137
freelist fl.Interface
137
138
freelistLoad sync.Once
@@ -793,6 +794,9 @@ func (db *DB) beginTx() (*Tx, error) {
793
794
t := & Tx {}
794
795
t .init (db )
795
796
797
+ // Keep track of transaction until it closes.
798
+ db .txs = append (db .txs , t )
799
+ n := len (db .txs )
796
800
if db .freelist != nil {
797
801
db .freelist .AddReadonlyTXID (t .meta .Txid ())
798
802
}
@@ -803,7 +807,7 @@ func (db *DB) beginTx() (*Tx, error) {
803
807
// Update the transaction stats.
804
808
db .statlock .Lock ()
805
809
db .stats .TxN ++
806
- db .stats .OpenTxN ++
810
+ db .stats .OpenTxN = n
807
811
db .statlock .Unlock ()
808
812
809
813
return t , nil
@@ -852,6 +856,17 @@ func (db *DB) removeTx(tx *Tx) {
852
856
// Use the meta lock to restrict access to the DB object.
853
857
db .metalock .Lock ()
854
858
859
+ // Remove the transaction.
860
+ for i , t := range db .txs {
861
+ if t == tx {
862
+ last := len (db .txs ) - 1
863
+ db .txs [i ] = db .txs [last ]
864
+ db .txs [last ] = nil
865
+ db .txs = db .txs [:last ]
866
+ break
867
+ }
868
+ }
869
+ n := len (db .txs )
855
870
if db .freelist != nil {
856
871
db .freelist .RemoveReadonlyTXID (tx .meta .Txid ())
857
872
}
@@ -861,7 +876,7 @@ func (db *DB) removeTx(tx *Tx) {
861
876
862
877
// Merge statistics.
863
878
db .statlock .Lock ()
864
- db .stats .OpenTxN --
879
+ db .stats .OpenTxN = n
865
880
db .stats .TxStats .add (& tx .stats )
866
881
db .statlock .Unlock ()
867
882
}
You can’t perform that action at this time.
0 commit comments