@@ -39,6 +39,8 @@ const (
39
39
// default page size for db is set to the OS page size.
40
40
var defaultPageSize = os .Getpagesize ()
41
41
42
+ var ErrDiskFull = errors .New ("db cannot grow, likely due to lack of disk space" )
43
+
42
44
// DB represents a collection of buckets persisted to a file on disk.
43
45
// All data access is performed through transactions which can be obtained through the DB.
44
46
// All the functions on DB will return a ErrDatabaseNotOpen if accessed before Open() is called.
@@ -109,6 +111,7 @@ type DB struct {
109
111
txs []* Tx
110
112
freelist * freelist
111
113
stats Stats
114
+ unusable bool // true if mmap has failed
112
115
113
116
pagePool sync.Pool
114
117
@@ -480,6 +483,10 @@ func (db *DB) beginTx() (*Tx, error) {
480
483
db .metalock .Unlock ()
481
484
return nil , ErrDatabaseNotOpen
482
485
}
486
+ // Exit if database is unusable.
487
+ if db .unusable {
488
+ return nil , ErrDiskFull
489
+ }
483
490
484
491
// Create a transaction associated with the database.
485
492
t := & Tx {}
@@ -521,6 +528,10 @@ func (db *DB) beginRWTx() (*Tx, error) {
521
528
db .rwlock .Unlock ()
522
529
return nil , ErrDatabaseNotOpen
523
530
}
531
+ // Exit if database is unusable.
532
+ if db .unusable {
533
+ return nil , ErrDiskFull
534
+ }
524
535
525
536
// Create a transaction associated with the database.
526
537
t := & Tx {writable : true }
0 commit comments