diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-19 12:08:33 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-19 12:08:33 -0600 |
commit | 782ead0dbf3095d0e843c2036bf40cc8ecd9b4d1 (patch) | |
tree | 19babfefc617c7f82bc5dcfc287b3f4809a6623a /db.go | |
parent | Merge pull request #166 from benbjohnson/fill-percent (diff) | |
download | dedo-782ead0dbf3095d0e843c2036bf40cc8ecd9b4d1.tar.gz dedo-782ead0dbf3095d0e843c2036bf40cc8ecd9b4d1.tar.xz |
Fix freelist allocation direction.
This commit fixes the freelist so that it frees from the beginning of the data file
instead of the end. It also adds a fast path for pages which can be allocated from
the first free pages and it includes read transaction stats.
Diffstat (limited to 'db.go')
-rw-r--r-- | db.go | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -351,7 +351,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 { @@ -365,6 +364,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 } @@ -418,12 +427,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() } @@ -612,6 +623,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. } |