From fd6c0aa81a9042cc03701b8c1c39720ba02beab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Sat, 26 Mar 2022 00:26:41 +0100 Subject: [PATCH 1/6] Makefile: Move to golangci-lint --- Makefile | 15 +++------------ db_test.go | 4 ++-- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 21ecf48f6..1623c8470 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/db_test.go b/db_test.go index f6f7de253..a512a01c1 100644 --- a/db_test.go +++ b/db_test.go @@ -30,7 +30,7 @@ const pageHeaderSize = 16 // meta represents a simplified version of a database meta page for testing. type meta struct { - magic uint32 + _ uint32 version uint32 _ uint32 _ uint32 @@ -38,7 +38,7 @@ type meta struct { _ uint64 pgid uint64 _ uint64 - checksum uint64 + _ uint64 } // Ensure that a database can be opened without error. From ff70d213eb059a2ab0204fa21e91a3c9c11478fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Sat, 26 Mar 2022 00:26:28 +0100 Subject: [PATCH 2/6] .github: Move from travis to github actions --- .github/workflows/tests.yaml | 16 ++++++++++++++++ .travis.yml | 18 ------------------ 2 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/tests.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 000000000..a142f302d --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,16 @@ +name: Tests +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: "1.17.8" + - run: make fmt + - run: make race + - run: make test + # Enable when fixed (same as make lint) + # - name: golangci-lint + # uses: golangci/golangci-lint-action@v2 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 452601e49..000000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: go -go_import_path: go.etcd.io/bbolt - -sudo: false - -go: -- 1.15 - -before_install: -- go get -v golang.org/x/sys/unix -- go get -v honnef.co/go/tools/... -- go get -v github.com/kisielk/errcheck - -script: -- make fmt -- make test -- make race -# - make errcheck From 9b606419b141631d5ecfd511fa0fd7ceb201d298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Thu, 20 Oct 2022 21:08:13 +0200 Subject: [PATCH 3/6] Run gofmt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Rüger --- .github/workflows/tests.yaml | 2 +- bolt_loong64.go | 1 + db_test.go | 18 +++++++++--------- doc.go | 8 ++------ mlock_unix.go | 2 +- mlock_windows.go | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a142f302d..cb03796e5 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -7,7 +7,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: "1.17.8" + go-version: "1.17.13" - run: make fmt - run: make race - run: make test diff --git a/bolt_loong64.go b/bolt_loong64.go index c5bb7cb85..31c17c1d0 100644 --- a/bolt_loong64.go +++ b/bolt_loong64.go @@ -1,3 +1,4 @@ +//go:build loong64 // +build loong64 package bbolt diff --git a/db_test.go b/db_test.go index a512a01c1..c7c63cf15 100644 --- a/db_test.go +++ b/db_test.go @@ -30,15 +30,15 @@ const pageHeaderSize = 16 // meta represents a simplified version of a database meta page for testing. type meta struct { - _ uint32 - version uint32 - _ uint32 - _ uint32 - _ [16]byte - _ uint64 - pgid uint64 - _ uint64 - _ uint64 + _ uint32 + version uint32 + _ uint32 + _ uint32 + _ [16]byte + _ uint64 + pgid uint64 + _ uint64 + _ uint64 } // Ensure that a database can be opened without error. diff --git a/doc.go b/doc.go index 95f25f01c..d1007e4b0 100644 --- a/doc.go +++ b/doc.go @@ -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 @@ -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 @@ -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 diff --git a/mlock_unix.go b/mlock_unix.go index 7e578d43f..744a972f5 100644 --- a/mlock_unix.go +++ b/mlock_unix.go @@ -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 diff --git a/mlock_windows.go b/mlock_windows.go index b4a36a493..00b0fb431 100644 --- a/mlock_windows.go +++ b/mlock_windows.go @@ -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") } From b2cf45b995160bc272928db3b791cc24f4ebc489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Thu, 20 Oct 2022 22:33:49 +0200 Subject: [PATCH 4/6] .github: Update actions to latest version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Rüger --- .github/workflows/tests.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index cb03796e5..06fa26cad 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -4,8 +4,8 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 with: go-version: "1.17.13" - run: make fmt From 33c86c78caac1f6fde9b52811cf052b89fe9ca85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Thu, 20 Oct 2022 22:40:14 +0200 Subject: [PATCH 5/6] .github: Enable lint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Rüger --- .github/workflows/tests.yaml | 5 ++--- cmd/bbolt/main.go | 16 +++++++++++++--- compact.go | 9 +++++++-- db_test.go | 10 ++++++++-- tx.go | 2 +- tx_test.go | 10 ++++++++-- unix_test.go | 6 +++--- 7 files changed, 42 insertions(+), 16 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 06fa26cad..b328c635a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -11,6 +11,5 @@ jobs: - run: make fmt - run: make race - run: make test - # Enable when fixed (same as make lint) - # - name: golangci-lint - # uses: golangci/golangci-lint-action@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 diff --git a/cmd/bbolt/main.go b/cmd/bbolt/main.go index 5009aecd2..bec49be3d 100644 --- a/cmd/bbolt/main.go +++ b/cmd/bbolt/main.go @@ -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. @@ -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) diff --git a/compact.go b/compact.go index e4fe91b04..5f1d4c3b5 100644 --- a/compact.go +++ b/compact.go @@ -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. @@ -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" diff --git a/db_test.go b/db_test.go index c7c63cf15..84794e51d 100644 --- a/db_test.go +++ b/db_test.go @@ -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() diff --git a/tx.go b/tx.go index 869d41200..451cc2c98 100644 --- a/tx.go +++ b/tx.go @@ -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 diff --git a/tx_test.go b/tx_test.go index 14345d0bc..4fe99db2c 100644 --- a/tx_test.go +++ b/tx_test.go @@ -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. @@ -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. diff --git a/unix_test.go b/unix_test.go index ac06c4f40..d39dfd820 100644 --- a/unix_test.go +++ b/unix_test.go @@ -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, - )) + ) } } From 759180711786fa59b92c44a4a291df4114f6177b Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Sun, 13 Nov 2022 13:34:17 +0800 Subject: [PATCH 6/6] bump golang.org/x/sys to v0.2.0 Signed-off-by: Benjamin Wang --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index bfd61423c..cbafe64fd 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index c13f8f470..beac707cf 100644 --- a/go.sum +++ b/go.sum @@ -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=