From 92a9f2e200e83fd0b3ddef177f9a454b0273c17e Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Tue, 27 May 2014 11:31:55 -0600 Subject: Remove DB.Check(). Allow read-only Tx.Check(). This commit removes the DB.Check() function and instead makes the user decide whether a transaction should be writable or read-only. Tx.Check() is not safe to use concurrently on a read-only transaction, however, it significantly improves the performance of it. --- tx.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tx.go') diff --git a/tx.go b/tx.go index 8791adf..a0ae5bd 100644 --- a/tx.go +++ b/tx.go @@ -284,12 +284,14 @@ func (tx *Tx) CopyFile(path string, mode os.FileMode) error { } // Check performs several consistency checks on the database for this transaction. -// An error is returned if any inconsistency is found or if executed on a read-only transaction. +// An error is returned if any inconsistency is found. +// +// It can be safely run concurrently on a writable transaction. However, this +// incurs a high cost for large databases and databases with a lot of subbuckets +// because of caching. This overhead can be removed if running on a read-only +// transaction, however, it is not safe to execute other writer transactions at +// the same time. func (tx *Tx) Check() error { - if !tx.writable { - return ErrTxNotWritable - } - var errors ErrorList // Check if any pages are double freed. @@ -466,12 +468,10 @@ func (tx *Tx) forEachPage(pgid pgid, depth int, fn func(*page, int)) { } // Page returns page information for a given page number. -// This is only available from writable transactions. +// This is only safe for concurrent use when used by a writable transaction. func (tx *Tx) Page(id int) (*PageInfo, error) { if tx.db == nil { return nil, ErrTxClosed - } else if !tx.writable { - return nil, ErrTxNotWritable } else if pgid(id) >= tx.meta.pgid { return nil, nil } -- cgit v1.2.3