Browse Source

Merge pull request #8436 from gyuho/bbolt

vendor: upgrade 'coreos/bbolt' to v1.3.1-coreos.1
Gyu-Ho Lee 8 years ago
parent
commit
897cadc88c

+ 12 - 0
cmd/vendor/github.com/coreos/bbolt/bolt_mips64x.go

@@ -0,0 +1,12 @@
+// +build mips64 mips64le
+
+package bolt
+
+// maxMapSize represents the largest mmap size supported by Bolt.
+const maxMapSize = 0x8000000000 // 512GB
+
+// maxAllocSize is the size used when creating array pointers.
+const maxAllocSize = 0x7FFFFFFF
+
+// Are unaligned load/stores broken on this arch?
+var brokenUnaligned = false

+ 12 - 0
cmd/vendor/github.com/coreos/bbolt/bolt_mipsx.go

@@ -0,0 +1,12 @@
+// +build mips mipsle
+
+package bolt
+
+// maxMapSize represents the largest mmap size supported by Bolt.
+const maxMapSize = 0x40000000 // 1GB
+
+// maxAllocSize is the size used when creating array pointers.
+const maxAllocSize = 0xFFFFFFF
+
+// Are unaligned load/stores broken on this arch?
+var brokenUnaligned = false

+ 6 - 8
cmd/vendor/github.com/coreos/bbolt/bucket.go

@@ -14,13 +14,6 @@ const (
 	MaxValueSize = (1 << 31) - 2
 	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 bucketHeaderSize = int(unsafe.Sizeof(bucket{}))
 
 
 const (
 const (
@@ -323,7 +316,12 @@ func (b *Bucket) Delete(key []byte) error {
 
 
 	// Move cursor to correct position.
 	// Move cursor to correct position.
 	c := b.Cursor()
 	c := b.Cursor()
-	_, _, flags := c.seek(key)
+	k, _, flags := c.seek(key)
+
+	// Return nil if the key doesn't exist.
+	if !bytes.Equal(key, k) {
+		return nil
+	}
 
 
 	// Return an error if there is already existing bucket value.
 	// Return an error if there is already existing bucket value.
 	if (flags & bucketLeafFlag) != 0 {
 	if (flags & bucketLeafFlag) != 0 {

+ 27 - 30
cmd/vendor/github.com/coreos/bbolt/db.go

@@ -7,9 +7,7 @@ import (
 	"log"
 	"log"
 	"os"
 	"os"
 	"runtime"
 	"runtime"
-	"runtime/debug"
 	"sort"
 	"sort"
-	"strings"
 	"sync"
 	"sync"
 	"time"
 	"time"
 	"unsafe"
 	"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
 	// 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).
 	// hold a lock at the same time) otherwise (options.ReadOnly is set).
 	if err := flock(db, mode, !db.readOnly, options.Timeout); err != nil {
 	if err := flock(db, mode, !db.readOnly, options.Timeout); err != nil {
+		db.lockfile = nil // make 'unused' happy. TODO: rework locks
 		_ = db.close()
 		_ = db.close()
 		return nil, err
 		return nil, err
 	}
 	}
@@ -200,6 +199,11 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
 	// Default values for test hooks
 	// Default values for test hooks
 	db.ops.writeAt = db.file.WriteAt
 	db.ops.writeAt = db.file.WriteAt
 
 
+	if db.pageSize = options.PageSize; db.pageSize == 0 {
+		// Set the default page size to the OS page size.
+		db.pageSize = defaultPageSize
+	}
+
 	// Initialize the database if it doesn't exist.
 	// Initialize the database if it doesn't exist.
 	if info, err := db.file.Stat(); err != nil {
 	if info, err := db.file.Stat(); err != nil {
 		return nil, err
 		return nil, err
@@ -211,20 +215,21 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
 	} else {
 	} else {
 		// Read the first meta page to determine the page size.
 		// Read the first meta page to determine the page size.
 		var buf [0x1000]byte
 		var buf [0x1000]byte
-		if _, err := db.file.ReadAt(buf[:], 0); err == nil {
-			m := db.pageInBuffer(buf[:], 0).meta()
-			if err := m.validate(); err != nil {
-				// If we can't read the page size, we can assume it's the same
-				// as the OS -- since that's how the page size was chosen in the
-				// first place.
-				//
-				// If the first page is invalid and this OS uses a different
-				// page size than what the database was created with then we
-				// are out of luck and cannot access the database.
-				db.pageSize = os.Getpagesize()
-			} else {
+		// If we can't read the page size, but can read a page, assume
+		// it's the same as the OS or one given -- since that's how the
+		// page size was chosen in the first place.
+		//
+		// If the first page is invalid and this OS uses a different
+		// page size than what the database was created with then we
+		// are out of luck and cannot access the database.
+		//
+		// TODO: scan for next page
+		if bw, err := db.file.ReadAt(buf[:], 0); err == nil && bw == len(buf) {
+			if m := db.pageInBuffer(buf[:], 0).meta(); m.validate() == nil {
 				db.pageSize = int(m.pageSize)
 				db.pageSize = int(m.pageSize)
 			}
 			}
+		} else {
+			return nil, ErrInvalid
 		}
 		}
 	}
 	}
 
 
@@ -241,6 +246,10 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
 		return nil, err
 		return nil, err
 	}
 	}
 
 
+	if db.readOnly {
+		return db, nil
+	}
+
 	db.freelist = newFreelist()
 	db.freelist = newFreelist()
 	noFreeList := db.meta().freelist == pgidNoFreelist
 	noFreeList := db.meta().freelist == pgidNoFreelist
 	if noFreeList {
 	if noFreeList {
@@ -254,7 +263,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
 
 
 	// Flush freelist when transitioning from no sync to sync so
 	// Flush freelist when transitioning from no sync to sync so
 	// NoFreelistSync unaware boltdb can open the db later.
 	// NoFreelistSync unaware boltdb can open the db later.
-	if !db.NoFreelistSync && noFreeList && ((mode & 0222) != 0) {
+	if !db.NoFreelistSync && noFreeList {
 		tx, err := db.Begin(true)
 		tx, err := db.Begin(true)
 		if tx != nil {
 		if tx != nil {
 			err = tx.Commit()
 			err = tx.Commit()
@@ -370,9 +379,6 @@ func (db *DB) mmapSize(size int) (int, error) {
 
 
 // init creates a new database file and initializes its meta pages.
 // init creates a new database file and initializes its meta pages.
 func (db *DB) init() error {
 func (db *DB) init() error {
-	// Set the page size to the OS page size.
-	db.pageSize = os.Getpagesize()
-
 	// Create two meta pages on a buffer.
 	// Create two meta pages on a buffer.
 	buf := make([]byte, db.pageSize*4)
 	buf := make([]byte, db.pageSize*4)
 	for i := 0; i < 2; i++ {
 	for i := 0; i < 2; i++ {
@@ -999,6 +1005,9 @@ type Options struct {
 	// If initialMmapSize is smaller than the previous database size,
 	// If initialMmapSize is smaller than the previous database size,
 	// it takes no effect.
 	// it takes no effect.
 	InitialMmapSize int
 	InitialMmapSize int
+
+	// PageSize overrides the default OS page size.
+	PageSize int
 }
 }
 
 
 // DefaultOptions represent the options used if nil options are passed into Open().
 // DefaultOptions represent the options used if nil options are passed into Open().
@@ -1040,10 +1049,6 @@ func (s *Stats) Sub(other *Stats) Stats {
 	return diff
 	return diff
 }
 }
 
 
-func (s *Stats) add(other *Stats) {
-	s.TxStats.add(&other.TxStats)
-}
-
 type Info struct {
 type Info struct {
 	Data     uintptr
 	Data     uintptr
 	PageSize int
 	PageSize int
@@ -1110,11 +1115,3 @@ func _assert(condition bool, msg string, v ...interface{}) {
 		panic(fmt.Sprintf("assertion failed: "+msg, v...))
 		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)
-}

+ 1 - 1
cmd/vendor/github.com/coreos/bbolt/freelist.go

@@ -245,7 +245,7 @@ func (f *freelist) read(p *page) {
 	if count == 0 {
 	if count == 0 {
 		f.ids = nil
 		f.ids = nil
 	} else {
 	} else {
-		ids := ((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[idx:idx+count]
+		ids := ((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[idx : idx+count]
 		f.ids = make([]pgid, len(ids))
 		f.ids = make([]pgid, len(ids))
 		copy(f.ids, ids)
 		copy(f.ids, ids)
 
 

+ 1 - 1
cmd/vendor/github.com/coreos/bbolt/node.go

@@ -365,7 +365,7 @@ func (n *node) spill() error {
 		}
 		}
 
 
 		// Allocate contiguous space for the node.
 		// Allocate contiguous space for the node.
-		p, err := tx.allocate((node.size() / tx.db.pageSize) + 1)
+		p, err := tx.allocate((node.size() + tx.db.pageSize - 1) / tx.db.pageSize)
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}

+ 1 - 4
cmd/vendor/github.com/coreos/bbolt/tx.go

@@ -126,10 +126,7 @@ func (tx *Tx) DeleteBucket(name []byte) error {
 // the error is returned to the caller.
 // the error is returned to the caller.
 func (tx *Tx) ForEach(fn func(name []byte, b *Bucket) error) error {
 func (tx *Tx) ForEach(fn func(name []byte, b *Bucket) error) error {
 	return tx.root.ForEach(func(k, v []byte) error {
 	return tx.root.ForEach(func(k, v []byte) error {
-		if err := fn(k, tx.root.Bucket(k)); err != nil {
-			return err
-		}
-		return nil
+		return fn(k, tx.root.Bucket(k))
 	})
 	})
 }
 }
 
 

+ 3 - 3
glide.lock

@@ -1,5 +1,5 @@
-hash: cb6ec5f6ddc889073b7f3667a6c8d0ea4df28e4b81d3e8888aca4a01476b8d6d
-updated: 2017-08-19T18:37:17.884672072-07:00
+hash: b0a745e42cc5c2bfb0d21ee80a9efaf646fbe179aa3561c0bd7a73179d57a3f0
+updated: 2017-08-22T11:01:08.044444615-07:00
 imports:
 imports:
 - name: github.com/beorn7/perks
 - name: github.com/beorn7/perks
   version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9
   version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9
@@ -10,7 +10,7 @@ imports:
 - name: github.com/cockroachdb/cmux
 - name: github.com/cockroachdb/cmux
   version: 112f0506e7743d64a6eb8fedbcff13d9979bbf92
   version: 112f0506e7743d64a6eb8fedbcff13d9979bbf92
 - name: github.com/coreos/bbolt
 - name: github.com/coreos/bbolt
-  version: 12923fe56c105bca6efbbcc258cd762b4258333d
+  version: e1c92081e510bb6b2bbfc93e7e6bd0b6dabd3e12
 - name: github.com/coreos/go-semver
 - name: github.com/coreos/go-semver
   version: 8ab6407b697782a06568d4b7f1db25550ec2e4c6
   version: 8ab6407b697782a06568d4b7f1db25550ec2e4c6
   subpackages:
   subpackages:

+ 1 - 1
glide.yaml

@@ -5,7 +5,7 @@ import:
 - package: github.com/bgentry/speakeasy
 - package: github.com/bgentry/speakeasy
   version: v0.1.0
   version: v0.1.0
 - package: github.com/coreos/bbolt
 - package: github.com/coreos/bbolt
-  version: v1.3.1-coreos.0
+  version: v1.3.1-coreos.1
 - package: github.com/cockroachdb/cmux
 - package: github.com/cockroachdb/cmux
   version: 112f0506e7743d64a6eb8fedbcff13d9979bbf92
   version: 112f0506e7743d64a6eb8fedbcff13d9979bbf92
 - package: github.com/coreos/go-semver
 - package: github.com/coreos/go-semver