Skip to content

Commit

Permalink
Merge branch 'master' into fix_cursor_last
Browse files Browse the repository at this point in the history
  • Loading branch information
dchaofei committed Nov 14, 2022
2 parents 3d8280f + c5901d2 commit 6f56243
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 63 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.17.13"
- run: make fmt
- run: make race
- run: make test
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

15 changes: 3 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@ race:
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 go.etcd.io/bbolt
lint:
golangci-lint run ./...

test:
TEST_FREELIST_TYPE=hashmap go test -timeout 20m -v -coverprofile cover.out -covermode atomic
Expand All @@ -33,4 +24,4 @@ test:
# Note: gets "program not an importable package" in out of path builds
@TEST_FREELIST_TYPE=array go test -v ./cmd/bbolt

.PHONY: race fmt errcheck test gosimple unused
.PHONY: race fmt test lint
1 change: 1 addition & 0 deletions bolt_loong64.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build loong64
// +build loong64

package bbolt
Expand Down
16 changes: 13 additions & 3 deletions cmd/bbolt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,11 @@ func (cmd *BenchCommand) startProfiling(options *BenchOptions) {
fmt.Fprintf(cmd.Stderr, "bench: could not create cpu profile %q: %v\n", options.CPUProfile, err)
os.Exit(1)
}
pprof.StartCPUProfile(cpuprofile)
err = pprof.StartCPUProfile(cpuprofile)
if err != nil {
fmt.Fprintf(cmd.Stderr, "bench: could not start cpu profile %q: %v\n", options.CPUProfile, err)
os.Exit(1)
}
}

// Start memory profiling.
Expand Down Expand Up @@ -1664,13 +1668,19 @@ func (cmd *BenchCommand) stopProfiling() {
}

if memprofile != nil {
pprof.Lookup("heap").WriteTo(memprofile, 0)
err := pprof.Lookup("heap").WriteTo(memprofile, 0)
if err != nil {
fmt.Fprintf(cmd.Stderr, "bench: could not write mem profile")
}
memprofile.Close()
memprofile = nil
}

if blockprofile != nil {
pprof.Lookup("block").WriteTo(blockprofile, 0)
err := pprof.Lookup("block").WriteTo(blockprofile, 0)
if err != nil {
fmt.Fprintf(cmd.Stderr, "bench: could not write block profile")
}
blockprofile.Close()
blockprofile = nil
runtime.SetBlockProfileRate(0)
Expand Down
9 changes: 7 additions & 2 deletions compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ func Compact(dst, src *DB, txMaxSize int64) error {
if err != nil {
return err
}
defer tx.Rollback()
defer func() {
if tempErr := tx.Rollback(); tempErr != nil {
err = tempErr
}
}()

if err := walk(src, func(keys [][]byte, k, v []byte, seq uint64) error {
// On each key/value, check if we have exceeded tx size.
Expand Down Expand Up @@ -73,8 +77,9 @@ func Compact(dst, src *DB, txMaxSize int64) error {
}); err != nil {
return err
}
err = tx.Commit()

return tx.Commit()
return err
}

// walkFunc is the type of the function called for keys (buckets and "normal"
Expand Down
28 changes: 17 additions & 11 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const pageHeaderSize = 16

// meta represents a simplified version of a database meta page for testing.
type meta struct {
magic uint32
version uint32
_ uint32
_ uint32
_ [16]byte
_ uint64
pgid uint64
_ uint64
checksum uint64
_ uint32
version uint32
_ uint32
_ uint32
_ [16]byte
_ uint64
pgid uint64
_ uint64
_ uint64
}

// Ensure that a database can be opened without error.
Expand Down Expand Up @@ -647,8 +647,14 @@ func TestDB_Concurrent_WriteTo(t *testing.T) {
panic(err)
}
time.Sleep(time.Duration(rand.Intn(20)+1) * time.Millisecond)
tx.WriteTo(f)
tx.Rollback()
_, err = tx.WriteTo(f)
if err != nil {
panic(err)
}
err = tx.Rollback()
if err != nil {
panic(err)
}
f.Close()
snap := &DB{nil, f.Name(), o}
snap.MustReopen()
Expand Down
8 changes: 2 additions & 6 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ The design of Bolt is based on Howard Chu's LMDB database project.
Bolt currently works on Windows, Mac OS X, and Linux.
Basics
# Basics
There are only a few types in Bolt: DB, Bucket, Tx, and Cursor. The DB is
a collection of buckets and is represented by a single file on disk. A bucket is
Expand All @@ -27,8 +26,7 @@ iterate over the dataset sequentially. Read-write transactions can create and
delete buckets and can insert and remove keys. Only one read-write transaction
is allowed at a time.
Caveats
# Caveats
The database uses a read-only, memory-mapped data file to ensure that
applications cannot corrupt the database, however, this means that keys and
Expand All @@ -38,7 +36,5 @@ will cause Go to panic.
Keys and values retrieved from the database are only valid for the life of
the transaction. When used outside the transaction, these byte slices can
point to different data or can point to invalid memory which will cause a panic.
*/
package bbolt
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module go.etcd.io/bbolt

go 1.17

require golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d
require golang.org/x/sys v0.2.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d h1:L/IKR6COd7ubZrs2oTnTi73IhgqJ71c9s80WsQnh0Es=
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2 changes: 1 addition & 1 deletion mlock_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func mlock(db *DB, fileSize int) error {
return nil
}

//munlock unlocks memory of db file
// munlock unlocks memory of db file
func munlock(db *DB, fileSize int) error {
if db.dataref == nil {
return nil
Expand Down
2 changes: 1 addition & 1 deletion mlock_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ func mlock(_ *DB, _ int) error {
panic("mlock is supported only on UNIX systems")
}

//munlock unlocks memory of db file
// munlock unlocks memory of db file
func munlock(_ *DB, _ int) error {
panic("munlock is supported only on UNIX systems")
}
2 changes: 1 addition & 1 deletion tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (tx *Tx) write() error {
for i := range buf {
buf[i] = 0
}
tx.db.pagePool.Put(buf)
tx.db.pagePool.Put(buf) //nolint:staticcheck
}

return nil
Expand Down
10 changes: 8 additions & 2 deletions tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func TestTx_Check_ReadOnly(t *testing.T) {
}
}
// Close the view transaction
tx.Rollback()
err = tx.Rollback()
if err != nil {
t.Fatal(err)
}
}

// Ensure that committing a closed transaction returns an error.
Expand Down Expand Up @@ -112,7 +115,10 @@ func TestTx_Commit_ErrTxNotWritable(t *testing.T) {
t.Fatal(err)
}
// Close the view transaction
tx.Rollback()
err = tx.Rollback()
if err != nil {
t.Fatal(err)
}
}

// Ensure that a transaction can retrieve a cursor on the root bucket.
Expand Down
6 changes: 3 additions & 3 deletions unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func skipOnMemlockLimitBelow(t *testing.T, memlockLimitRequest uint64) {
}

if info.Cur < memlockLimitRequest {
t.Skip(fmt.Sprintf(
"skipping as RLIMIT_MEMLOCK is unsufficient: %v < %v",
t.Skipf(
"skipping as RLIMIT_MEMLOCK is insufficient: %v < %v",
info.Cur,
memlockLimitRequest,
))
)
}
}

0 comments on commit 6f56243

Please sign in to comment.