mirror of
https://github.com/etcd-io/bbolt.git
synced 2025-05-31 11:42:30 +00:00
Merge pull request #210 from benbjohnson/default-options
Add DefaultOptions variable.
This commit is contained in:
commit
c45c4a1ae6
27
bucket.go
27
bucket.go
@ -2,7 +2,6 @@ package bolt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@ -15,32 +14,6 @@ const (
|
|||||||
MaxValueSize = 4294967295
|
MaxValueSize = 4294967295
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// ErrBucketNotFound is returned when trying to access a bucket that has
|
|
||||||
// not been created yet.
|
|
||||||
ErrBucketNotFound = errors.New("bucket not found")
|
|
||||||
|
|
||||||
// ErrBucketExists is returned when creating a bucket that already exists.
|
|
||||||
ErrBucketExists = errors.New("bucket already exists")
|
|
||||||
|
|
||||||
// ErrBucketNameRequired is returned when creating a bucket with a blank name.
|
|
||||||
ErrBucketNameRequired = errors.New("bucket name required")
|
|
||||||
|
|
||||||
// ErrKeyRequired is returned when inserting a zero-length key.
|
|
||||||
ErrKeyRequired = errors.New("key required")
|
|
||||||
|
|
||||||
// ErrKeyTooLarge is returned when inserting a key that is larger than MaxKeySize.
|
|
||||||
ErrKeyTooLarge = errors.New("key too large")
|
|
||||||
|
|
||||||
// ErrValueTooLarge is returned when inserting a value that is larger than MaxValueSize.
|
|
||||||
ErrValueTooLarge = errors.New("value too large")
|
|
||||||
|
|
||||||
// ErrIncompatibleValue is returned when trying create or delete a bucket
|
|
||||||
// on an existing non-bucket key or when trying to create or delete a
|
|
||||||
// non-bucket key on an existing bucket key.
|
|
||||||
ErrIncompatibleValue = errors.New("incompatible value")
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxUint = ^uint(0)
|
maxUint = ^uint(0)
|
||||||
minUint = 0
|
minUint = 0
|
||||||
|
35
db.go
35
db.go
@ -1,7 +1,6 @@
|
|||||||
package bolt
|
package bolt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"os"
|
"os"
|
||||||
@ -33,30 +32,6 @@ const (
|
|||||||
// This value can be changed by setting DB.FillPercent.
|
// This value can be changed by setting DB.FillPercent.
|
||||||
const DefaultFillPercent = 0.5
|
const DefaultFillPercent = 0.5
|
||||||
|
|
||||||
var (
|
|
||||||
// ErrDatabaseNotOpen is returned when a DB instance is accessed before it
|
|
||||||
// is opened or after it is closed.
|
|
||||||
ErrDatabaseNotOpen = errors.New("database not open")
|
|
||||||
|
|
||||||
// ErrDatabaseOpen is returned when opening a database that is
|
|
||||||
// already open.
|
|
||||||
ErrDatabaseOpen = errors.New("database already open")
|
|
||||||
|
|
||||||
// ErrInvalid is returned when a data file is not a Bolt-formatted database.
|
|
||||||
ErrInvalid = errors.New("invalid database")
|
|
||||||
|
|
||||||
// ErrVersionMismatch is returned when the data file was created with a
|
|
||||||
// different version of Bolt.
|
|
||||||
ErrVersionMismatch = errors.New("version mismatch")
|
|
||||||
|
|
||||||
// ErrChecksum is returned when either meta page checksum does not match.
|
|
||||||
ErrChecksum = errors.New("checksum error")
|
|
||||||
|
|
||||||
// ErrTimeout is returned when a database cannot obtain an exclusive lock
|
|
||||||
// on the data file after the timeout passed to Open().
|
|
||||||
ErrTimeout = errors.New("timeout")
|
|
||||||
)
|
|
||||||
|
|
||||||
// DB represents a collection of buckets persisted to a file on disk.
|
// DB represents a collection of buckets persisted to a file on disk.
|
||||||
// All data access is performed through transactions which can be obtained through the DB.
|
// All data access is performed through transactions which can be obtained through the DB.
|
||||||
// All the functions on DB will return a ErrDatabaseNotOpen if accessed before Open() is called.
|
// All the functions on DB will return a ErrDatabaseNotOpen if accessed before Open() is called.
|
||||||
@ -117,9 +92,9 @@ func (db *DB) String() string {
|
|||||||
func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
|
func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
|
||||||
var db = &DB{opened: true, FillPercent: DefaultFillPercent}
|
var db = &DB{opened: true, FillPercent: DefaultFillPercent}
|
||||||
|
|
||||||
// Set default options.
|
// Set default options if no options are provided.
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = &Options{}
|
options = DefaultOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open data file and separate sync handler for metadata writes.
|
// Open data file and separate sync handler for metadata writes.
|
||||||
@ -575,6 +550,12 @@ type Options struct {
|
|||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultOptions represent the options used if nil options are passed into Open().
|
||||||
|
// No timeout is used which will cause Bolt to wait indefinitely for a lock.
|
||||||
|
var DefaultOptions = &Options{
|
||||||
|
Timeout: 0,
|
||||||
|
}
|
||||||
|
|
||||||
// Stats represents statistics about the database.
|
// Stats represents statistics about the database.
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
// Freelist stats
|
// Freelist stats
|
||||||
|
70
errors.go
Normal file
70
errors.go
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package bolt
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
// These errors can be returned when opening or calling methods on a DB.
|
||||||
|
var (
|
||||||
|
// ErrDatabaseNotOpen is returned when a DB instance is accessed before it
|
||||||
|
// is opened or after it is closed.
|
||||||
|
ErrDatabaseNotOpen = errors.New("database not open")
|
||||||
|
|
||||||
|
// ErrDatabaseOpen is returned when opening a database that is
|
||||||
|
// already open.
|
||||||
|
ErrDatabaseOpen = errors.New("database already open")
|
||||||
|
|
||||||
|
// ErrInvalid is returned when a data file is not a Bolt-formatted database.
|
||||||
|
ErrInvalid = errors.New("invalid database")
|
||||||
|
|
||||||
|
// ErrVersionMismatch is returned when the data file was created with a
|
||||||
|
// different version of Bolt.
|
||||||
|
ErrVersionMismatch = errors.New("version mismatch")
|
||||||
|
|
||||||
|
// ErrChecksum is returned when either meta page checksum does not match.
|
||||||
|
ErrChecksum = errors.New("checksum error")
|
||||||
|
|
||||||
|
// ErrTimeout is returned when a database cannot obtain an exclusive lock
|
||||||
|
// on the data file after the timeout passed to Open().
|
||||||
|
ErrTimeout = errors.New("timeout")
|
||||||
|
)
|
||||||
|
|
||||||
|
// These errors can occur when beginning or committing a Tx.
|
||||||
|
var (
|
||||||
|
// ErrTxNotWritable is returned when performing a write operation on a
|
||||||
|
// read-only transaction.
|
||||||
|
ErrTxNotWritable = errors.New("tx not writable")
|
||||||
|
|
||||||
|
// ErrTxClosed is returned when committing or rolling back a transaction
|
||||||
|
// that has already been committed or rolled back.
|
||||||
|
ErrTxClosed = errors.New("tx closed")
|
||||||
|
|
||||||
|
// ErrFreelistOverflow is returned when the total number of free pages
|
||||||
|
// exceeds 65,536 and the freelist cannot hold any more.
|
||||||
|
ErrFreelistOverflow = errors.New("freelist overflow")
|
||||||
|
)
|
||||||
|
|
||||||
|
// These errors can occur when putting or deleting a value or a bucket.
|
||||||
|
var (
|
||||||
|
// ErrBucketNotFound is returned when trying to access a bucket that has
|
||||||
|
// not been created yet.
|
||||||
|
ErrBucketNotFound = errors.New("bucket not found")
|
||||||
|
|
||||||
|
// ErrBucketExists is returned when creating a bucket that already exists.
|
||||||
|
ErrBucketExists = errors.New("bucket already exists")
|
||||||
|
|
||||||
|
// ErrBucketNameRequired is returned when creating a bucket with a blank name.
|
||||||
|
ErrBucketNameRequired = errors.New("bucket name required")
|
||||||
|
|
||||||
|
// ErrKeyRequired is returned when inserting a zero-length key.
|
||||||
|
ErrKeyRequired = errors.New("key required")
|
||||||
|
|
||||||
|
// ErrKeyTooLarge is returned when inserting a key that is larger than MaxKeySize.
|
||||||
|
ErrKeyTooLarge = errors.New("key too large")
|
||||||
|
|
||||||
|
// ErrValueTooLarge is returned when inserting a value that is larger than MaxValueSize.
|
||||||
|
ErrValueTooLarge = errors.New("value too large")
|
||||||
|
|
||||||
|
// ErrIncompatibleValue is returned when trying create or delete a bucket
|
||||||
|
// on an existing non-bucket key or when trying to create or delete a
|
||||||
|
// non-bucket key on an existing bucket key.
|
||||||
|
ErrIncompatibleValue = errors.New("incompatible value")
|
||||||
|
)
|
@ -1,18 +1,11 @@
|
|||||||
package bolt
|
package bolt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// ErrFreelistOverflow is returned when the total number of free pages
|
|
||||||
// exceeds 65,536 and the freelist cannot hold any more.
|
|
||||||
ErrFreelistOverflow = errors.New("freelist overflow")
|
|
||||||
)
|
|
||||||
|
|
||||||
// freelist represents a list of all pages that are available for allocation.
|
// freelist represents a list of all pages that are available for allocation.
|
||||||
// It also tracks pages that have been freed but are still in use by open transactions.
|
// It also tracks pages that have been freed but are still in use by open transactions.
|
||||||
type freelist struct {
|
type freelist struct {
|
||||||
|
11
tx.go
11
tx.go
@ -1,7 +1,6 @@
|
|||||||
package bolt
|
package bolt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@ -10,16 +9,6 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// ErrTxNotWritable is returned when performing a write operation on a
|
|
||||||
// read-only transaction.
|
|
||||||
ErrTxNotWritable = errors.New("tx not writable")
|
|
||||||
|
|
||||||
// ErrTxClosed is returned when committing or rolling back a transaction
|
|
||||||
// that has already been committed or rolled back.
|
|
||||||
ErrTxClosed = errors.New("tx closed")
|
|
||||||
)
|
|
||||||
|
|
||||||
// txid represents the internal transaction identifier.
|
// txid represents the internal transaction identifier.
|
||||||
type txid uint64
|
type txid uint64
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user