aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-05-21 13:46:12 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-05-21 13:46:12 -0600
commit7432bc341f8bbfc73eefc3278f2698e712e516b8 (patch)
tree33897520b5bd98383fe3b17cc9090e931c690b9c /db.go
parentMerge pull request #171 from Shopify/tx_copy (diff)
parentFix freelist allocate(). (diff)
downloaddedo-7432bc341f8bbfc73eefc3278f2698e712e516b8.tar.gz
dedo-7432bc341f8bbfc73eefc3278f2698e712e516b8.tar.xz
Merge pull request #169 from benbjohnson/allocation
Fix freelist allocation direction.
Diffstat (limited to 'db.go')
-rw-r--r--db.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/db.go b/db.go
index 1a1f997..5b6cc3e 100644
--- a/db.go
+++ b/db.go
@@ -350,7 +350,6 @@ func (db *DB) beginTx() (*Tx, error) {
// Lock the meta pages while we initialize the transaction.
db.metalock.Lock()
- defer db.metalock.Unlock()
// Exit if the database is not open yet.
if !db.opened {
@@ -364,6 +363,16 @@ func (db *DB) beginTx() (*Tx, error) {
// Keep track of transaction until it closes.
db.txs = append(db.txs, t)
+ n := len(db.txs)
+
+ // Unlock the meta pages.
+ db.metalock.Unlock()
+
+ // Update the transaction stats.
+ db.statlock.Lock()
+ db.stats.TxN++
+ db.stats.OpenTxN = n
+ db.statlock.Unlock()
return t, nil
}
@@ -417,12 +426,14 @@ func (db *DB) removeTx(tx *Tx) {
break
}
}
+ n := len(db.txs)
// Unlock the meta pages.
db.metalock.Unlock()
// Merge statistics.
db.statlock.Lock()
+ db.stats.OpenTxN = n
db.stats.TxStats.add(&tx.stats)
db.statlock.Unlock()
}
@@ -552,6 +563,10 @@ func (db *DB) allocate(count int) (*page, error) {
// Stats represents statistics about the database.
type Stats struct {
+ // Transaction stats
+ TxN int // total number of completed read transactions
+ OpenTxN int // number of currently open read transactions
+
TxStats TxStats // global, ongoing stats.
}