mirror of https://github.com/etcd-io/bbolt.git
pass unused
parent
e5514a24a6
commit
32c9f9e929
|
@ -14,13 +14,6 @@ const (
|
|||
MaxValueSize = (1 << 31) - 2
|
||||
)
|
||||
|
||||
const (
|
||||
maxUint = ^uint(0)
|
||||
minUint = 0
|
||||
maxInt = int(^uint(0) >> 1)
|
||||
minInt = -maxInt - 1
|
||||
)
|
||||
|
||||
const bucketHeaderSize = int(unsafe.Sizeof(bucket{}))
|
||||
|
||||
const (
|
||||
|
|
|
@ -48,12 +48,6 @@ var (
|
|||
|
||||
// ErrPageIDRequired is returned when a required page id is not specified.
|
||||
ErrPageIDRequired = errors.New("page id required")
|
||||
|
||||
// ErrPageNotFound is returned when specifying a page above the high water mark.
|
||||
ErrPageNotFound = errors.New("page not found")
|
||||
|
||||
// ErrPageFreed is returned when reading a page that has already been freed.
|
||||
ErrPageFreed = errors.New("page freed")
|
||||
)
|
||||
|
||||
// PageHeaderSize represents the size of the bolt.page header.
|
||||
|
@ -1023,12 +1017,12 @@ func (cmd *BenchCommand) runWritesRandom(db *bolt.DB, options *BenchOptions, res
|
|||
|
||||
func (cmd *BenchCommand) runWritesSequentialNested(db *bolt.DB, options *BenchOptions, results *BenchResults) error {
|
||||
var i = uint32(0)
|
||||
return cmd.runWritesWithSource(db, options, results, func() uint32 { i++; return i })
|
||||
return cmd.runWritesNestedWithSource(db, options, results, func() uint32 { i++; return i })
|
||||
}
|
||||
|
||||
func (cmd *BenchCommand) runWritesRandomNested(db *bolt.DB, options *BenchOptions, results *BenchResults) error {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
return cmd.runWritesWithSource(db, options, results, func() uint32 { return r.Uint32() })
|
||||
return cmd.runWritesNestedWithSource(db, options, results, func() uint32 { return r.Uint32() })
|
||||
}
|
||||
|
||||
func (cmd *BenchCommand) runWritesWithSource(db *bolt.DB, options *BenchOptions, results *BenchResults, keySource func() uint32) error {
|
||||
|
|
15
db.go
15
db.go
|
@ -7,9 +7,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
@ -193,6 +191,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
|
|||
// The database file is locked using the shared lock (more than one process may
|
||||
// hold a lock at the same time) otherwise (options.ReadOnly is set).
|
||||
if err := flock(db, mode, !db.readOnly, options.Timeout); err != nil {
|
||||
db.lockfile = nil // make 'unused' happy. TODO: rework locks
|
||||
_ = db.close()
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1040,10 +1039,6 @@ func (s *Stats) Sub(other *Stats) Stats {
|
|||
return diff
|
||||
}
|
||||
|
||||
func (s *Stats) add(other *Stats) {
|
||||
s.TxStats.add(&other.TxStats)
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
Data uintptr
|
||||
PageSize int
|
||||
|
@ -1110,11 +1105,3 @@ func _assert(condition bool, msg string, v ...interface{}) {
|
|||
panic(fmt.Sprintf("assertion failed: "+msg, v...))
|
||||
}
|
||||
}
|
||||
|
||||
func warn(v ...interface{}) { fmt.Fprintln(os.Stderr, v...) }
|
||||
func warnf(msg string, v ...interface{}) { fmt.Fprintf(os.Stderr, msg+"\n", v...) }
|
||||
|
||||
func printstack() {
|
||||
stack := strings.Join(strings.Split(string(debug.Stack()), "\n")[2:], "\n")
|
||||
fmt.Fprintln(os.Stderr, stack)
|
||||
}
|
||||
|
|
48
db_test.go
48
db_test.go
|
@ -12,8 +12,6 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -24,12 +22,6 @@ import (
|
|||
|
||||
var statsFlag = flag.Bool("stats", false, "show performance stats")
|
||||
|
||||
// version is the data file format version.
|
||||
const version = 2
|
||||
|
||||
// magic is the marker value to indicate that a file is a Bolt DB.
|
||||
const magic uint32 = 0xED0CDAED
|
||||
|
||||
// pageSize is the size of one page in the data file.
|
||||
const pageSize = 4096
|
||||
|
||||
|
@ -1575,40 +1567,6 @@ func tempfile() string {
|
|||
return f.Name()
|
||||
}
|
||||
|
||||
// mustContainKeys checks that a bucket contains a given set of keys.
|
||||
func mustContainKeys(b *bolt.Bucket, m map[string]string) {
|
||||
found := make(map[string]string)
|
||||
if err := b.ForEach(func(k, _ []byte) error {
|
||||
found[string(k)] = ""
|
||||
return nil
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Check for keys found in bucket that shouldn't be there.
|
||||
var keys []string
|
||||
for k := range found {
|
||||
if _, ok := m[string(k)]; !ok {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
if len(keys) > 0 {
|
||||
sort.Strings(keys)
|
||||
panic(fmt.Sprintf("keys found(%d): %s", len(keys), strings.Join(keys, ",")))
|
||||
}
|
||||
|
||||
// Check for keys not found in bucket that should be there.
|
||||
for k := range m {
|
||||
if _, ok := found[string(k)]; !ok {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
if len(keys) > 0 {
|
||||
sort.Strings(keys)
|
||||
panic(fmt.Sprintf("keys not found(%d): %s", len(keys), strings.Join(keys, ",")))
|
||||
}
|
||||
}
|
||||
|
||||
func trunc(b []byte, length int) []byte {
|
||||
if length < len(b) {
|
||||
return b[:length]
|
||||
|
@ -1628,15 +1586,9 @@ func fileSize(path string) int64 {
|
|||
return fi.Size()
|
||||
}
|
||||
|
||||
func warn(v ...interface{}) { fmt.Fprintln(os.Stderr, v...) }
|
||||
func warnf(msg string, v ...interface{}) { fmt.Fprintf(os.Stderr, msg+"\n", v...) }
|
||||
|
||||
// u64tob converts a uint64 into an 8-byte slice.
|
||||
func u64tob(v uint64) []byte {
|
||||
b := make([]byte, 8)
|
||||
binary.BigEndian.PutUint64(b, v)
|
||||
return b
|
||||
}
|
||||
|
||||
// btou64 converts an 8-byte slice into an uint64.
|
||||
func btou64(b []byte) uint64 { return binary.BigEndian.Uint64(b) }
|
||||
|
|
Loading…
Reference in New Issue