From af4957ead89797c5c06a514893e0e8113cee5c76 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Tue, 22 Aug 2017 10:53:49 -0700 Subject: [PATCH] vendor: upgrade 'coreos/bbolt' to v1.3.1-coreos.1 Signed-off-by: Gyu-Ho Lee --- .../github.com/coreos/bbolt/bolt_mips64x.go | 12 ++++ .../github.com/coreos/bbolt/bolt_mipsx.go | 12 ++++ cmd/vendor/github.com/coreos/bbolt/bucket.go | 14 ++--- cmd/vendor/github.com/coreos/bbolt/db.go | 57 +++++++++---------- .../github.com/coreos/bbolt/freelist.go | 2 +- cmd/vendor/github.com/coreos/bbolt/node.go | 2 +- cmd/vendor/github.com/coreos/bbolt/tx.go | 5 +- glide.lock | 6 +- glide.yaml | 2 +- 9 files changed, 64 insertions(+), 48 deletions(-) create mode 100644 cmd/vendor/github.com/coreos/bbolt/bolt_mips64x.go create mode 100644 cmd/vendor/github.com/coreos/bbolt/bolt_mipsx.go diff --git a/cmd/vendor/github.com/coreos/bbolt/bolt_mips64x.go b/cmd/vendor/github.com/coreos/bbolt/bolt_mips64x.go new file mode 100644 index 00000000000..134b578bd44 --- /dev/null +++ b/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 diff --git a/cmd/vendor/github.com/coreos/bbolt/bolt_mipsx.go b/cmd/vendor/github.com/coreos/bbolt/bolt_mipsx.go new file mode 100644 index 00000000000..d5ecb0597e4 --- /dev/null +++ b/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 diff --git a/cmd/vendor/github.com/coreos/bbolt/bucket.go b/cmd/vendor/github.com/coreos/bbolt/bucket.go index 0c5bf27463e..44db88b8abd 100644 --- a/cmd/vendor/github.com/coreos/bbolt/bucket.go +++ b/cmd/vendor/github.com/coreos/bbolt/bucket.go @@ -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 ( @@ -323,7 +316,12 @@ func (b *Bucket) Delete(key []byte) error { // Move cursor to correct position. 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. if (flags & bucketLeafFlag) != 0 { diff --git a/cmd/vendor/github.com/coreos/bbolt/db.go b/cmd/vendor/github.com/coreos/bbolt/db.go index c9d800fcc2c..71933cb6cb3 100644 --- a/cmd/vendor/github.com/coreos/bbolt/db.go +++ b/cmd/vendor/github.com/coreos/bbolt/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 } @@ -200,6 +199,11 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) { // Default values for test hooks 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. if info, err := db.file.Stat(); err != nil { return nil, err @@ -211,20 +215,21 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) { } else { // Read the first meta page to determine the page size. 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) } + } else { + return nil, ErrInvalid } } @@ -241,6 +246,10 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) { return nil, err } + if db.readOnly { + return db, nil + } + db.freelist = newFreelist() noFreeList := db.meta().freelist == pgidNoFreelist 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 // NoFreelistSync unaware boltdb can open the db later. - if !db.NoFreelistSync && noFreeList && ((mode & 0222) != 0) { + if !db.NoFreelistSync && noFreeList { tx, err := db.Begin(true) if tx != nil { 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. 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. buf := make([]byte, db.pageSize*4) for i := 0; i < 2; i++ { @@ -999,6 +1005,9 @@ type Options struct { // If initialMmapSize is smaller than the previous database size, // it takes no effect. InitialMmapSize int + + // PageSize overrides the default OS page size. + PageSize int } // 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 } -func (s *Stats) add(other *Stats) { - s.TxStats.add(&other.TxStats) -} - type Info struct { Data uintptr PageSize int @@ -1110,11 +1115,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) -} diff --git a/cmd/vendor/github.com/coreos/bbolt/freelist.go b/cmd/vendor/github.com/coreos/bbolt/freelist.go index 13ce5166600..78e71cbf27a 100644 --- a/cmd/vendor/github.com/coreos/bbolt/freelist.go +++ b/cmd/vendor/github.com/coreos/bbolt/freelist.go @@ -245,7 +245,7 @@ func (f *freelist) read(p *page) { if count == 0 { f.ids = nil } 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)) copy(f.ids, ids) diff --git a/cmd/vendor/github.com/coreos/bbolt/node.go b/cmd/vendor/github.com/coreos/bbolt/node.go index 159318b229c..f4ce240eddd 100644 --- a/cmd/vendor/github.com/coreos/bbolt/node.go +++ b/cmd/vendor/github.com/coreos/bbolt/node.go @@ -365,7 +365,7 @@ func (n *node) spill() error { } // 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 { return err } diff --git a/cmd/vendor/github.com/coreos/bbolt/tx.go b/cmd/vendor/github.com/coreos/bbolt/tx.go index 6b2fa283491..57c4d5ad8ca 100644 --- a/cmd/vendor/github.com/coreos/bbolt/tx.go +++ b/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. func (tx *Tx) ForEach(fn func(name []byte, b *Bucket) error) 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)) }) } diff --git a/glide.lock b/glide.lock index 528cd4d36fa..c7f71d4d9ea 100644 --- a/glide.lock +++ b/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: - name: github.com/beorn7/perks version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 @@ -10,7 +10,7 @@ imports: - name: github.com/cockroachdb/cmux version: 112f0506e7743d64a6eb8fedbcff13d9979bbf92 - name: github.com/coreos/bbolt - version: 12923fe56c105bca6efbbcc258cd762b4258333d + version: e1c92081e510bb6b2bbfc93e7e6bd0b6dabd3e12 - name: github.com/coreos/go-semver version: 8ab6407b697782a06568d4b7f1db25550ec2e4c6 subpackages: diff --git a/glide.yaml b/glide.yaml index 1fb5602bb16..7a37090c216 100644 --- a/glide.yaml +++ b/glide.yaml @@ -5,7 +5,7 @@ import: - package: github.com/bgentry/speakeasy version: v0.1.0 - package: github.com/coreos/bbolt - version: v1.3.1-coreos.0 + version: v1.3.1-coreos.1 - package: github.com/cockroachdb/cmux version: 112f0506e7743d64a6eb8fedbcff13d9979bbf92 - package: github.com/coreos/go-semver