mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Godeps: update boltdb/bolt for MAP_POPULATE
This is for https://github.com/boltdb/bolt/pull/455.
This commit is contained in:
parent
de02254659
commit
b4e0dbe721
4
Godeps/Godeps.json
generated
4
Godeps/Godeps.json
generated
@ -24,8 +24,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/boltdb/bolt",
|
"ImportPath": "github.com/boltdb/bolt",
|
||||||
"Comment": "v1.0-158-g81db894",
|
"Comment": "v1.1.0-19-g0b00eff",
|
||||||
"Rev": "81db89446cb805bc352f803151f47fea849241e2"
|
"Rev": "0b00effdd7a8270ebd91c24297e51643e370dd52"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/bradfitz/http2",
|
"ImportPath": "github.com/bradfitz/http2",
|
||||||
|
2
Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go
generated
vendored
2
Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix.go
generated
vendored
@ -58,7 +58,7 @@ func mmap(db *DB, sz int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map the data file to memory.
|
// Map the data file to memory.
|
||||||
b, err := syscall.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED)
|
b, err := syscall.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
5
Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix_solaris.go
generated
vendored
5
Godeps/_workspace/src/github.com/boltdb/bolt/bolt_unix_solaris.go
generated
vendored
@ -2,11 +2,12 @@ package bolt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/sys/unix"
|
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// flock acquires an advisory lock on a file descriptor.
|
// flock acquires an advisory lock on a file descriptor.
|
||||||
@ -67,7 +68,7 @@ func mmap(db *DB, sz int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map the data file to memory.
|
// Map the data file to memory.
|
||||||
b, err := unix.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED)
|
b, err := unix.Mmap(int(db.file.Fd()), 0, sz, syscall.PROT_READ, syscall.MAP_SHARED|db.MmapFlags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
16
Godeps/_workspace/src/github.com/boltdb/bolt/cursor.go
generated
vendored
16
Godeps/_workspace/src/github.com/boltdb/bolt/cursor.go
generated
vendored
@ -34,6 +34,13 @@ func (c *Cursor) First() (key []byte, value []byte) {
|
|||||||
p, n := c.bucket.pageNode(c.bucket.root)
|
p, n := c.bucket.pageNode(c.bucket.root)
|
||||||
c.stack = append(c.stack, elemRef{page: p, node: n, index: 0})
|
c.stack = append(c.stack, elemRef{page: p, node: n, index: 0})
|
||||||
c.first()
|
c.first()
|
||||||
|
|
||||||
|
// If we land on an empty page then move to the next value.
|
||||||
|
// https://github.com/boltdb/bolt/issues/450
|
||||||
|
if c.stack[len(c.stack)-1].count() == 0 {
|
||||||
|
c.next()
|
||||||
|
}
|
||||||
|
|
||||||
k, v, flags := c.keyValue()
|
k, v, flags := c.keyValue()
|
||||||
if (flags & uint32(bucketLeafFlag)) != 0 {
|
if (flags & uint32(bucketLeafFlag)) != 0 {
|
||||||
return k, nil
|
return k, nil
|
||||||
@ -209,6 +216,7 @@ func (c *Cursor) last() {
|
|||||||
// next moves to the next leaf element and returns the key and value.
|
// next moves to the next leaf element and returns the key and value.
|
||||||
// If the cursor is at the last leaf element then it stays there and returns nil.
|
// If the cursor is at the last leaf element then it stays there and returns nil.
|
||||||
func (c *Cursor) next() (key []byte, value []byte, flags uint32) {
|
func (c *Cursor) next() (key []byte, value []byte, flags uint32) {
|
||||||
|
for {
|
||||||
// Attempt to move over one element until we're successful.
|
// Attempt to move over one element until we're successful.
|
||||||
// Move up the stack as we hit the end of each page in our stack.
|
// Move up the stack as we hit the end of each page in our stack.
|
||||||
var i int
|
var i int
|
||||||
@ -230,7 +238,15 @@ func (c *Cursor) next() (key []byte, value []byte, flags uint32) {
|
|||||||
// first element of the first leaf page.
|
// first element of the first leaf page.
|
||||||
c.stack = c.stack[:i+1]
|
c.stack = c.stack[:i+1]
|
||||||
c.first()
|
c.first()
|
||||||
|
|
||||||
|
// If this is an empty page then restart and move back up the stack.
|
||||||
|
// https://github.com/boltdb/bolt/issues/450
|
||||||
|
if c.stack[len(c.stack)-1].count() == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
return c.keyValue()
|
return c.keyValue()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// search recursively performs a binary search against a given page/node until it finds a given key.
|
// search recursively performs a binary search against a given page/node until it finds a given key.
|
||||||
|
43
Godeps/_workspace/src/github.com/boltdb/bolt/cursor_test.go
generated
vendored
43
Godeps/_workspace/src/github.com/boltdb/bolt/cursor_test.go
generated
vendored
@ -303,6 +303,49 @@ func TestCursor_Restart(t *testing.T) {
|
|||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that a cursor can skip over empty pages that have been deleted.
|
||||||
|
func TestCursor_First_EmptyPages(t *testing.T) {
|
||||||
|
db := NewTestDB()
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
// Create 1000 keys in the "widgets" bucket.
|
||||||
|
db.Update(func(tx *bolt.Tx) error {
|
||||||
|
b, err := tx.CreateBucket([]byte("widgets"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
if err := b.Put(u64tob(uint64(i)), []byte{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
// Delete half the keys and then try to iterate.
|
||||||
|
db.Update(func(tx *bolt.Tx) error {
|
||||||
|
b := tx.Bucket([]byte("widgets"))
|
||||||
|
for i := 0; i < 600; i++ {
|
||||||
|
if err := b.Delete(u64tob(uint64(i))); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c := b.Cursor()
|
||||||
|
var n int
|
||||||
|
for k, _ := c.First(); k != nil; k, _ = c.Next() {
|
||||||
|
n++
|
||||||
|
}
|
||||||
|
if n != 400 {
|
||||||
|
t.Fatalf("unexpected key count: %d", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure that a Tx can iterate over all elements in a bucket.
|
// Ensure that a Tx can iterate over all elements in a bucket.
|
||||||
func TestCursor_QuickCheck(t *testing.T) {
|
func TestCursor_QuickCheck(t *testing.T) {
|
||||||
f := func(items testdata) bool {
|
f := func(items testdata) bool {
|
||||||
|
8
Godeps/_workspace/src/github.com/boltdb/bolt/db.go
generated
vendored
8
Godeps/_workspace/src/github.com/boltdb/bolt/db.go
generated
vendored
@ -63,6 +63,10 @@ type DB struct {
|
|||||||
// https://github.com/boltdb/bolt/issues/284
|
// https://github.com/boltdb/bolt/issues/284
|
||||||
NoGrowSync bool
|
NoGrowSync bool
|
||||||
|
|
||||||
|
// If you want to read the entire database fast, you can set MmapFlag to
|
||||||
|
// syscall.MAP_POPULATE on Linux 2.6.23+ for sequential read-ahead.
|
||||||
|
MmapFlags int
|
||||||
|
|
||||||
// MaxBatchSize is the maximum size of a batch. Default value is
|
// MaxBatchSize is the maximum size of a batch. Default value is
|
||||||
// copied from DefaultMaxBatchSize in Open.
|
// copied from DefaultMaxBatchSize in Open.
|
||||||
//
|
//
|
||||||
@ -136,6 +140,7 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
|
|||||||
options = DefaultOptions
|
options = DefaultOptions
|
||||||
}
|
}
|
||||||
db.NoGrowSync = options.NoGrowSync
|
db.NoGrowSync = options.NoGrowSync
|
||||||
|
db.MmapFlags = options.MmapFlags
|
||||||
|
|
||||||
// Set default values for later DB operations.
|
// Set default values for later DB operations.
|
||||||
db.MaxBatchSize = DefaultMaxBatchSize
|
db.MaxBatchSize = DefaultMaxBatchSize
|
||||||
@ -672,6 +677,9 @@ type Options struct {
|
|||||||
// Open database in read-only mode. Uses flock(..., LOCK_SH |LOCK_NB) to
|
// Open database in read-only mode. Uses flock(..., LOCK_SH |LOCK_NB) to
|
||||||
// grab a shared lock (UNIX).
|
// grab a shared lock (UNIX).
|
||||||
ReadOnly bool
|
ReadOnly bool
|
||||||
|
|
||||||
|
// Sets the DB.MmapFlags flag before memory mapping the file.
|
||||||
|
MmapFlags 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().
|
||||||
|
Loading…
x
Reference in New Issue
Block a user