Skip to content
This repository has been archived by the owner on Dec 3, 2018. It is now read-only.

Switch to bbolt #5

Open
wants to merge 102 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
ef23622
Avoid allocate a hole page, when the node size equals to pageSize
buptmiao Sep 24, 2016
78d099e
Garbage collect pages allocated after minimum txid
May 21, 2017
78b54a4
*: use coreos/bbolt as import path
xiang90 Jun 20, 2017
bffefe5
Merge pull request #4 from coreos/import_test
xiang90 Jun 20, 2017
7149270
*: add option to skip freelist sync
xiang90 Jun 22, 2017
572a8e0
Merge pull request #1 from coreos/no_sync
xiang90 Jun 22, 2017
ad39960
Merge pull request #3 from heyitsanthony/range-gc
xiang90 Jun 24, 2017
05bfb3b
rebuild freelist when opening with FreelistSync after NoFreelistSync
Jul 25, 2017
c359265
Merge pull request #6 from heyitsanthony/restore-freelist
Jul 25, 2017
7ce671b
*: fix gofmt style issues in 'range'
gyuho Jul 13, 2017
a30394a
*: update git paths to 'coreos/bbolt'
gyuho Jul 27, 2017
2ab139b
Merge pull request #8 from gyuho/ci
gyuho Jul 27, 2017
f50ad8e
test: check free page counts on close/reopen for freelist overflow
Aug 9, 2017
03f5e16
freelist: read all free pages on count overflow
Aug 9, 2017
1038faf
test: use qconfig() instead of defaults in TestBucket_Put_Single
Aug 8, 2017
fd5de84
fix NoSyncFreelist reachability checking
Aug 8, 2017
7bc8330
Merge pull request #13 from heyitsanthony/weaken-single-put
Aug 9, 2017
b219ffc
Merge pull request #10 from heyitsanthony/fix-freepage-test
Aug 9, 2017
12923fe
Merge pull request #12 from heyitsanthony/skip-freelist-overflow
Aug 10, 2017
78ca4fd
get rid of os.Getpagesize() calls where appropriate
Aug 10, 2017
012f884
add PageSize to Option struct
Aug 11, 2017
319a33c
Fix issue #543 'bolt bench crashes'
Apr 13, 2016
89b9a2c
make fmt
Aug 11, 2017
e5514a2
pass gosimple
Aug 11, 2017
32c9f9e
pass unused
Aug 11, 2017
d3d8bbd
pass gofmt
Aug 11, 2017
ec37ce8
do not read freelist if database opened readonly
funny-falcon Aug 15, 2015
e264e74
Add support for mips, mips64
Feb 17, 2017
ef8e711
Set FillPercent=1.0 in 'bolt compact'.
dogben Jun 11, 2017
3c6c3ac
Add a test for deletion of non-existing key
pborzenkov Feb 8, 2017
6336a42
Fix deletion of non-existing keys
pborzenkov Feb 8, 2017
1ab9756
fix overflow breaking 32-bit test builds
Aug 11, 2017
045bd0e
Merge pull request #26 from heyitsanthony/fix-32bit-test
Aug 11, 2017
ca5f9b6
Merge pull request #21 from heyitsanthony/add_mips_support
Aug 11, 2017
6b378d8
Merge pull request #18 from heyitsanthony/fmt
Aug 11, 2017
c5d7f33
Merge pull request #22 from heyitsanthony/fill-compact
Aug 11, 2017
2fe83be
Merge pull request #19 from heyitsanthony/skip-freelist-read
Aug 11, 2017
a6c45c1
Merge pull request #16 from heyitsanthony/config-page-size
Aug 11, 2017
9fc2cf1
Merge pull request #23 from heyitsanthony/del-nonexisting
Aug 11, 2017
533739c
Merge pull request #17 from heyitsanthony/fix543
Aug 11, 2017
f07641f
Add "dump" and "page" commands to CLI usage
lmars Jul 28, 2015
0ca39eb
Add "buckets", "keys" and "get" CLI commands
lmars Jul 28, 2015
3efc7f7
Merge pull request #20 from heyitsanthony/readd-cli-commands
Aug 11, 2017
4d8f7f7
README: update links to 'coreos/bbolt'
gyuho Aug 11, 2017
2db8c23
Merge pull request #27 from gyuho/README
gyuho Aug 11, 2017
dd1d5a7
Merge pull request #24 from heyitsanthony/node-gap
Aug 11, 2017
9d07787
README: add goreportcard badge
gyuho Aug 11, 2017
c309230
*: go vet fixes
gyuho Aug 11, 2017
e1c9208
Merge pull request #28 from gyuho/goreport
gyuho Aug 11, 2017
92ba45f
README: explain purpose of bbolt fork
Aug 24, 2017
9c39199
Merge pull request #32 from heyitsanthony/readme-fork
Aug 24, 2017
69fa13f
Add NoSync field to Options
tylertreat Aug 24, 2017
337da34
Merge pull request #30 from tylertreat/nosync_option
Aug 24, 2017
e6a9c1d
add coverage reports
Aug 30, 2017
a148de8
Merge pull request #33 from heyitsanthony/cov
Aug 30, 2017
3a49aac
Added support for no timeout locks on db files (#35)
dmoklaf Sep 6, 2017
9245fa7
Increase freelist.releaseRange unit test coverage.
jpbetz Sep 7, 2017
4ff482b
Merge pull request #36 from jpbetz/freelist-tests
xiang90 Sep 8, 2017
4ce1b5e
tx: use io.SeekStart in WriteTo function
lorneli Sep 11, 2017
d72f760
Improve test coverage for releaseRange rollbacks.
jpbetz Sep 7, 2017
4d3ab93
Merge pull request #37 from jpbetz/tx-tests
xiang90 Sep 11, 2017
d294ec8
db: add test in read-only mode
lorneli Sep 12, 2017
ea18f34
db: return t.Rollback directly in the end of View function
lorneli Sep 10, 2017
cca7a90
Merge pull request #43 from lorneli/bbolt_seek
Sep 12, 2017
63f0e07
Merge pull request #46 from lorneli/bbolt_db_test
Sep 12, 2017
a4199f8
Merge pull request #41 from lorneli/bbolt_db
xiang90 Sep 12, 2017
53a930f
tx: just close file once in WriteTo function
lorneli Sep 11, 2017
e39821f
*: fix gofmt errors and makefile test
Sep 13, 2017
fb37144
Merge pull request #48 from heyitsanthony/fix-fmt-test
Sep 14, 2017
2760028
Merge pull request #44 from lorneli/bbolt_tx
Sep 14, 2017
ba5a58d
test tx.Check() on read only db
Sep 13, 2017
69918b9
Fix bolt CLI tool print entire freelist, and to dump keys/value bytes…
jpbetz Sep 14, 2017
ebf39dc
Merge pull request #50 from jpbetz/page-kv-and-full-freelist
xiang90 Sep 20, 2017
bdfe415
tx: load freelist on Check()
Sep 13, 2017
700b8ea
Merge pull request #52 from jpbetz/fix-readonly-check
xiang90 Sep 22, 2017
235a427
Removed 'moribund' since some people think it's a bit derogatory towa…
virtualsue Sep 25, 2017
54f6fad
Merge pull request #56 from virtualsue/master
xiang90 Sep 27, 2017
68861c5
db_test.go: remove temp files after tests
gyuho Sep 28, 2017
3eac9d3
Merge pull request #57 from gyuho/clean-up
gyuho Sep 28, 2017
b4c13d4
Add 'boltcli' to the list of projects that use Bolt
spacewander Oct 29, 2017
60725ac
Merge pull request #63 from spacewander/add_boltcli
xiang90 Oct 31, 2017
434419a
fix funlock error when call db.Close on windows
Nov 1, 2017
3c6cbfb
Merge pull request #64 from kwf2030/master
xiang90 Nov 1, 2017
22635d7
tx: fix the number of pages is not incorrectly counted
Nov 8, 2017
237a4fc
Panic if page provided to freelist.read is incorrect page type.
jpbetz Nov 15, 2017
f4ebd07
Merge pull request #66 from jpbetz/freelist-check
gyuho Nov 16, 2017
386b851
freelist: set alloc tx for freelist to prior txn
heyitsanthony Nov 16, 2017
41fefe7
test: check concurrent WriteTo operations aren't corrupted
heyitsanthony Nov 16, 2017
32c383e
Merge pull request #67 from heyitsanthony/fix-freelist-corruption
gyuho Nov 16, 2017
bcfcdab
Remove unnecessary if in batch handling
tv42 Nov 18, 2017
b436469
Merge pull request #68 from heyitsanthony/sync-silly-if
xiang90 Nov 26, 2017
48ea1b3
Merge pull request #65 from zrss/fix-page-cnt
xiang90 Dec 7, 2017
cef3333
bolt_ppc.go: define `var brokenUnaligned`
mvo5 Jan 18, 2018
ee30b74
Merge pull request #73 from mvo5/master
xiang90 Jan 18, 2018
fafe4b7
Close waits for the transactions to finish
rcoelho Feb 13, 2018
584b1a3
Breaking the long line
rcoelho Feb 14, 2018
b44cfbd
Merge pull request #80 from rcoelho/close-wait-transactions
xiang90 Feb 14, 2018
eb69cfa
change import to NebulousLabs/bolt
lukechampine Feb 14, 2018
86a90cd
remap old size if new mmap fails
lukechampine Jul 18, 2017
97348af
add MmapError type
lukechampine Jul 18, 2017
4917b25
fix mmap error type
lukechampine Jul 20, 2017
f3da9d4
Merge branch 'master' into bbolt
lukechampine Feb 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.test
*.swp
/bin/
cmd/bolt/bolt
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@ default: build
race:
@go test -v -race -test.run="TestSimulate_(100op|1000op)"

fmt:
!(gofmt -l -s -d $(shell find . -name \*.go) | grep '[a-z]')

# go get honnef.co/go/tools/simple
gosimple:
gosimple ./...

# go get honnef.co/go/tools/unused
unused:
unused ./...

# go get github.com/kisielk/errcheck
errcheck:
@errcheck -ignorepkg=bytes -ignore=os:Remove github.com/boltdb/bolt
@errcheck -ignorepkg=bytes -ignore=os:Remove github.com/NebulousLabs/bolt

test:
@go test -v -cover .
@go test -v ./cmd/bolt
test:
go test -timeout 20m -v -coverprofile cover.out -covermode atomic
# Note: gets "program not an importable package" in out of path builds
go test -v ./cmd/bolt

.PHONY: fmt test
.PHONY: race fmt errcheck test gosimple unused
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Bolt [![Coverage Status](https://coveralls.io/repos/boltdb/bolt/badge.svg?branch=master)](https://coveralls.io/r/boltdb/bolt?branch=master) [![GoDoc](https://godoc.org/github.com/boltdb/bolt?status.svg)](https://godoc.org/github.com/boltdb/bolt) ![Version](https://img.shields.io/badge/version-1.2.1-green.svg)
bbolt
====

[![Go Report Card](https://goreportcard.com/badge/github.com/coreos/bbolt?style=flat-square)](https://goreportcard.com/report/github.com/coreos/bbolt)
[![Coverage](https://codecov.io/gh/coreos/bbolt/branch/master/graph/badge.svg)](https://codecov.io/gh/coreos/bbolt)
[![Godoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/coreos/bbolt)

bbolt is a fork of [Ben Johnson's][gh_ben] [Bolt][bolt] key/value
store. The purpose of this fork is to provide the Go community with an active
maintenance and development target for Bolt; the goal is improved reliability
and stability. bbolt includes bug fixes, performance enhancements, and features
not found in Bolt while preserving backwards compatibility with the Bolt API.

Bolt is a pure Go key/value store inspired by [Howard Chu's][hyc_symas]
[LMDB project][lmdb]. The goal of the project is to provide a simple,
fast, and reliable database for projects that don't require a full database
Expand All @@ -10,6 +20,8 @@ Since Bolt is meant to be used as such a low-level piece of functionality,
simplicity is key. The API will be small and only focus on getting values
and setting values. That's it.

[gh_ben]: https://github.com/benbjohnson
[bolt]: https://github.com/boltdb/bolt
[hyc_symas]: https://twitter.com/hyc_symas
[lmdb]: http://symas.com/mdb/

Expand Down Expand Up @@ -59,7 +71,7 @@ Shopify and Heroku use Bolt-backed services every day.
To start using Bolt, install Go and run `go get`:

```sh
$ go get github.com/boltdb/bolt/...
$ go get github.com/coreos/bbolt/...
```

This will retrieve the library and install the `bolt` command line utility into
Expand Down Expand Up @@ -522,7 +534,7 @@ this from a read-only transaction, it will perform a hot backup and not block
your other database reads and writes.

By default, it will use a regular file handle which will utilize the operating
system's page cache. See the [`Tx`](https://godoc.org/github.com/boltdb/bolt#Tx)
system's page cache. See the [`Tx`](https://godoc.org/github.com/coreos/bbolt#Tx)
documentation for information about optimizing for larger-than-RAM datasets.

One common use case is to backup over HTTP so you can use tools like `cURL` to
Expand Down Expand Up @@ -811,7 +823,7 @@ Here are a few things to note when evaluating and using Bolt:

## Reading the Source

Bolt is a relatively small code base (<3KLOC) for an embedded, serializable,
Bolt is a relatively small code base (<5KLOC) for an embedded, serializable,
transactional key/value database so it can be a good starting point for people
interested in how databases work.

Expand Down Expand Up @@ -907,6 +919,7 @@ Below is a list of public, open source projects that use Bolt:
* [torrent](https://github.com/anacrolix/torrent) - Full-featured BitTorrent client package and utilities in Go. BoltDB is a storage backend in development.
* [gopherpit](https://github.com/gopherpit/gopherpit) - A web service to manage Go remote import paths with custom domains
* [bolter](https://github.com/hasit/bolter) - Command-line app for viewing BoltDB file in your terminal.
* [boltcli](https://github.com/spacewander/boltcli) - the redis-cli for boltdb with Lua script support.
* [btcwallet](https://github.com/btcsuite/btcwallet) - A bitcoin wallet.
* [dcrwallet](https://github.com/decred/dcrwallet) - A wallet for the Decred cryptocurrency.
* [Ironsmith](https://github.com/timshannon/ironsmith) - A simple, script-driven continuous integration (build - > test -> release) tool, with no external dependencies
Expand Down
30 changes: 30 additions & 0 deletions allocate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package bolt

import (
"testing"
)

func TestTx_allocatePageStats(t *testing.T) {
f := newFreelist()
f.ids = []pgid{2, 3}

tx := &Tx{
db: &DB{
freelist: f,
pageSize: defaultPageSize,
},
meta: &meta{},
pages: make(map[pgid]*page),
}

prePageCnt := tx.Stats().PageCount
allocateCnt := f.free_count()

if _, err := tx.allocate(allocateCnt); err != nil {
t.Fatal(err)
}

if tx.Stats().PageCount != prePageCnt+allocateCnt {
t.Errorf("Allocated %d but got %d page in stats", allocateCnt, tx.Stats().PageCount)
}
}
12 changes: 12 additions & 0 deletions bolt_mips64x.go
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions bolt_mipsx.go
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions bolt_ppc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ const maxMapSize = 0x7FFFFFFF // 2GB

// maxAllocSize is the size used when creating array pointers.
const maxAllocSize = 0xFFFFFFF

// Are unaligned load/stores broken on this arch?
var brokenUnaligned = false
33 changes: 18 additions & 15 deletions bolt_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,32 @@ import (
// flock acquires an advisory lock on a file descriptor.
func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) error {
var t time.Time
if timeout != 0 {
t = time.Now()
}
fd := db.file.Fd()
flag := syscall.LOCK_NB
if exclusive {
flag |= syscall.LOCK_EX
} else {
flag |= syscall.LOCK_SH
}
for {
// If we're beyond our timeout then return an error.
// This can only occur after we've attempted a flock once.
if t.IsZero() {
t = time.Now()
} else if timeout > 0 && time.Since(t) > timeout {
return ErrTimeout
}
flag := syscall.LOCK_SH
if exclusive {
flag = syscall.LOCK_EX
}

// Otherwise attempt to obtain an exclusive lock.
err := syscall.Flock(int(db.file.Fd()), flag|syscall.LOCK_NB)
// Attempt to obtain an exclusive lock.
err := syscall.Flock(int(fd), flag)
if err == nil {
return nil
} else if err != syscall.EWOULDBLOCK {
return err
}

// If we timed out then return an error.
if timeout != 0 && time.Since(t) > timeout-flockRetryTimeout {
return ErrTimeout
}

// Wait for a bit and try again.
time.Sleep(50 * time.Millisecond)
time.Sleep(flockRetryTimeout)
}
}

Expand Down
39 changes: 19 additions & 20 deletions bolt_unix_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,33 @@ import (
// flock acquires an advisory lock on a file descriptor.
func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) error {
var t time.Time
if timeout != 0 {
t = time.Now()
}
fd := db.file.Fd()
var lockType int16
if exclusive {
lockType = syscall.F_WRLCK
} else {
lockType = syscall.F_RDLCK
}
for {
// If we're beyond our timeout then return an error.
// This can only occur after we've attempted a flock once.
if t.IsZero() {
t = time.Now()
} else if timeout > 0 && time.Since(t) > timeout {
return ErrTimeout
}
var lock syscall.Flock_t
lock.Start = 0
lock.Len = 0
lock.Pid = 0
lock.Whence = 0
lock.Pid = 0
if exclusive {
lock.Type = syscall.F_WRLCK
} else {
lock.Type = syscall.F_RDLCK
}
err := syscall.FcntlFlock(db.file.Fd(), syscall.F_SETLK, &lock)
// Attempt to obtain an exclusive lock.
lock := syscall.Flock_t{Type: lockType}
err := syscall.FcntlFlock(fd, syscall.F_SETLK, &lock)
if err == nil {
return nil
} else if err != syscall.EAGAIN {
return err
}

// If we timed out then return an error.
if timeout != 0 && time.Since(t) > timeout-flockRetryTimeout {
return ErrTimeout
}

// Wait for a bit and try again.
time.Sleep(50 * time.Millisecond)
time.Sleep(flockRetryTimeout)
}
}

Expand Down
31 changes: 16 additions & 15 deletions bolt_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,30 @@ func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) erro
db.lockfile = f

var t time.Time
if timeout != 0 {
t = time.Now()
}
fd := f.Fd()
var flag uint32 = flagLockFailImmediately
if exclusive {
flag |= flagLockExclusive
}
for {
// If we're beyond our timeout then return an error.
// This can only occur after we've attempted a flock once.
if t.IsZero() {
t = time.Now()
} else if timeout > 0 && time.Since(t) > timeout {
return ErrTimeout
}

var flag uint32 = flagLockFailImmediately
if exclusive {
flag |= flagLockExclusive
}

err := lockFileEx(syscall.Handle(db.lockfile.Fd()), flag, 0, 1, 0, &syscall.Overlapped{})
// Attempt to obtain an exclusive lock.
err := lockFileEx(syscall.Handle(fd), flag, 0, 1, 0, &syscall.Overlapped{})
if err == nil {
return nil
} else if err != errLockViolation {
return err
}

// If we timed oumercit then return an error.
if timeout != 0 && time.Since(t) > timeout-flockRetryTimeout {
return ErrTimeout
}

// Wait for a bit and try again.
time.Sleep(50 * time.Millisecond)
time.Sleep(flockRetryTimeout)
}
}

Expand Down
14 changes: 6 additions & 8 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
Loading