fix(linter): run go fmt on the repo (#1870)

This commit is contained in:
Aman Mangal
2023-02-14 22:41:02 +05:30
committed by GitHub
parent 3758356d91
commit a472d2ad50
18 changed files with 87 additions and 70 deletions
+11 -11
View File
@@ -1,5 +1,6 @@
run:
tests: false
skip-dirs:
skip-files:
linters-settings:
lll:
@@ -8,14 +9,13 @@ linters-settings:
linters:
disable-all: true
enable:
# - errcheck
# - ineffassign
# - gas
# - errcheck
# - ineffassign
# - gas
- gofmt
# - golint
- gosimple
- govet
- lll
# - varcheck
# - unused
# - gosec
# - gosimple
# - govet
# - lll
# - unused
# - staticcheck
- goimports
+16 -14
View File
@@ -945,7 +945,8 @@ func (db *DB) doWrites(lc *z.Closer) {
// batchSet applies a list of badger.Entry. If a request level error occurs it
// will be returned.
// Check(kv.BatchSet(entries))
//
// Check(kv.BatchSet(entries))
func (db *DB) batchSet(entries []*Entry) error {
req, err := db.sendToWriteCh(entries)
if err != nil {
@@ -958,9 +959,10 @@ func (db *DB) batchSet(entries []*Entry) error {
// batchSetAsync is the asynchronous version of batchSet. It accepts a callback
// function which is called when all the sets are complete. If a request level
// error occurs, it will be passed back via the callback.
// err := kv.BatchSetAsync(entries, func(err error)) {
// Check(err)
// }
//
// err := kv.BatchSetAsync(entries, func(err error)) {
// Check(err)
// }
func (db *DB) batchSetAsync(entries []*Entry, f func(error)) error {
req, err := db.sendToWriteCh(entries)
if err != nil {
@@ -1719,16 +1721,16 @@ func (db *DB) dropAll() (func(), error) {
}
// DropPrefix would drop all the keys with the provided prefix. It does this in the following way:
// - Stop accepting new writes.
// - Stop memtable flushes before acquiring lock. Because we're acquring lock here
// and memtable flush stalls for lock, which leads to deadlock
// - Flush out all memtables, skipping over keys with the given prefix, Kp.
// - Write out the value log header to memtables when flushing, so we don't accidentally bring Kp
// back after a restart.
// - Stop compaction.
// - Compact L0->L1, skipping over Kp.
// - Compact rest of the levels, Li->Li, picking tables which have Kp.
// - Resume memtable flushes, compactions and writes.
// - Stop accepting new writes.
// - Stop memtable flushes before acquiring lock. Because we're acquring lock here
// and memtable flush stalls for lock, which leads to deadlock
// - Flush out all memtables, skipping over keys with the given prefix, Kp.
// - Write out the value log header to memtables when flushing, so we don't accidentally bring Kp
// back after a restart.
// - Stop compaction.
// - Compact L0->L1, skipping over Kp.
// - Compact rest of the levels, Li->Li, picking tables which have Kp.
// - Resume memtable flushes, compactions and writes.
func (db *DB) DropPrefix(prefixes ...[]byte) error {
if len(prefixes) == 0 {
return nil
+10 -5
View File
@@ -657,12 +657,17 @@ func TestL0GCBug(t *testing.T) {
//
// The test has 3 steps
// Step 1 - Create badger data. It is necessary that the value size is
// greater than valuethreshold. The value log file size after
// this step is around 170 bytes.
//
// greater than valuethreshold. The value log file size after
// this step is around 170 bytes.
//
// Step 2 - Re-open the same badger and simulate a crash. The value log file
// size after this crash is around 2 GB (we increase the file size to mmap it).
//
// size after this crash is around 2 GB (we increase the file size to mmap it).
//
// Step 3 - Re-open the same badger. We should be able to read all the data
// inserted in the first step.
//
// inserted in the first step.
func TestWindowsDataLoss(t *testing.T) {
if runtime.GOOS != "windows" {
t.Skip("The test is only for Windows.")
@@ -995,7 +1000,7 @@ func TestKeyCount(t *testing.T) {
}()
write := func(kvs *pb.KVList) error {
buf := z.NewBuffer(1 << 20, "test")
buf := z.NewBuffer(1<<20, "test")
defer buf.Release()
for _, kv := range kvs.Kv {
+3 -3
View File
@@ -123,9 +123,9 @@ func syncDir(dir string) error {
// Opening an exclusive-use file returns an error.
// The expected error strings are:
//
// - "open/create -- file is locked" (cwfs, kfs)
// - "exclusive lock" (fossil)
// - "exclusive use file already open" (ramfs)
// - "open/create -- file is locked" (cwfs, kfs)
// - "exclusive lock" (fossil)
// - "exclusive use file already open" (ramfs)
//
// See https://github.com/golang/go/blob/go1.15rc1/src/cmd/go/internal/lockedfile/lockedfile_plan9.go#L16
var lockedErrStrings = [...]string{
+1
View File
@@ -1,3 +1,4 @@
//go:build !windows && !plan9
// +build !windows,!plan9
/*
+1
View File
@@ -1,3 +1,4 @@
//go:build windows
// +build windows
/*
+1 -2
View File
@@ -10,8 +10,7 @@ hence reducing both write amplification and the size of the LSM tree. This
allows LSM tree to be served entirely from RAM, while the values are served
from SSD.
Usage
# Usage
Badger has the following main types: DB, Txn, Item and Iterator. DB contains
keys that are associated with values. It must be opened with the appropriate
+18 -10
View File
@@ -324,12 +324,16 @@ func TestIteratorReadOnlyWithNoData(t *testing.T) {
// pkg: github.com/dgraph-io/badger
// BenchmarkIteratePrefixSingleKey/Key_lookups-4 10000 365539 ns/op
// --- BENCH: BenchmarkIteratePrefixSingleKey/Key_lookups-4
// iterator_test.go:147: Inner b.N: 1
// iterator_test.go:147: Inner b.N: 100
// iterator_test.go:147: Inner b.N: 10000
//
// iterator_test.go:147: Inner b.N: 1
// iterator_test.go:147: Inner b.N: 100
// iterator_test.go:147: Inner b.N: 10000
//
// --- BENCH: BenchmarkIteratePrefixSingleKey
// iterator_test.go:143: LSM files: 79
// iterator_test.go:145: Outer b.N: 1
//
// iterator_test.go:143: LSM files: 79
// iterator_test.go:145: Outer b.N: 1
//
// PASS
// ok github.com/dgraph-io/badger 41.586s
//
@@ -339,12 +343,16 @@ func TestIteratorReadOnlyWithNoData(t *testing.T) {
// pkg: github.com/dgraph-io/badger
// BenchmarkIteratePrefixSingleKey/Key_lookups-4 10000 460924 ns/op
// --- BENCH: BenchmarkIteratePrefixSingleKey/Key_lookups-4
// iterator_test.go:147: Inner b.N: 1
// iterator_test.go:147: Inner b.N: 100
// iterator_test.go:147: Inner b.N: 10000
//
// iterator_test.go:147: Inner b.N: 1
// iterator_test.go:147: Inner b.N: 100
// iterator_test.go:147: Inner b.N: 10000
//
// --- BENCH: BenchmarkIteratePrefixSingleKey
// iterator_test.go:143: LSM files: 83
// iterator_test.go:145: Outer b.N: 1
//
// iterator_test.go:143: LSM files: 83
// iterator_test.go:145: Outer b.N: 1
//
// PASS
// ok github.com/dgraph-io/badger 41.836s
//
+1 -1
View File
@@ -514,7 +514,7 @@ func (opt Options) WithValueThreshold(val int64) Options {
// and only 1 percent in vlog. The value threshold will be dynamically updated within the range of
// [ValueThreshold, Options.maxValueThreshold]
//
// Say VLogPercentile with 1.0 means threshold will eventually set to Options.maxValueThreshold
// # Say VLogPercentile with 1.0 means threshold will eventually set to Options.maxValueThreshold
//
// The default value of VLogPercentile is 0.0.
func (opt Options) WithVLogPercentile(t float64) Options {
+4 -4
View File
@@ -27,13 +27,13 @@ import (
)
type subscriber struct {
id uint64
id uint64
matches []pb.Match
sendCh chan *pb.KVList
subCloser *z.Closer
// this will be atomic pointer which will be used to
// track whether the subscriber is active or not
active *uint64
active *uint64
}
type publisher struct {
@@ -126,8 +126,8 @@ func (p *publisher) newSubscriber(c *z.Closer, matches []pb.Match) subscriber {
p.nextID++
active := uint64(1)
s := subscriber{
active: &active,
id: id,
active: &active,
id: id,
matches: matches,
sendCh: ch,
subCloser: c,
+1 -2
View File
@@ -40,7 +40,6 @@ func TestPublisherDeadlock(t *testing.T) {
var firstUpdate sync.WaitGroup
firstUpdate.Add(1)
var subDone sync.WaitGroup
subDone.Add(1)
go func() {
@@ -61,7 +60,7 @@ func TestPublisherDeadlock(t *testing.T) {
return txn.SetEntry(e)
})
require.NoError(t, err)
} ()
}()
firstUpdate.Wait()
req := int64(0)
+11 -11
View File
@@ -36,7 +36,7 @@ import (
func getSortedKVList(valueSize, listSize int) *z.Buffer {
value := make([]byte, valueSize)
y.Check2(rand.Read(value))
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
for i := 0; i < listSize; i++ {
key := make([]byte, 8)
binary.BigEndian.PutUint64(key, uint64(i))
@@ -175,7 +175,7 @@ func TestStreamWriter3(t *testing.T) {
value := make([]byte, valueSize)
y.Check2(rand.Read(value))
counter := 0
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
defer buf.Release()
for i := 0; i < noOfKeys; i++ {
key := make([]byte, 8)
@@ -272,7 +272,7 @@ func TestStreamWriter4(t *testing.T) {
require.NoError(t, err, "error while updating db")
}
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
defer buf.Release()
KVToBuffer(&pb.KV{
Key: []byte("key-1"),
@@ -297,7 +297,7 @@ func TestStreamWriter5(t *testing.T) {
right[0] = 0xff
copy(right[1:], []byte("break"))
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
defer buf.Release()
KVToBuffer(&pb.KV{
Key: left,
@@ -336,7 +336,7 @@ func TestStreamWriter6(t *testing.T) {
// will be written to level 6, we need to insert at least 1 mb of data.
// Setting keycount below 32 would cause this test to fail.
keyCount := 40
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
defer buf.Release()
for i := range str {
for j := 0; j < keyCount; j++ {
@@ -377,7 +377,7 @@ func TestStreamWriterCancel(t *testing.T) {
runBadgerTest(t, &opt, func(t *testing.T, db *DB) {
str := []string{"a", "a", "b", "b", "c", "c"}
ver := 1
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
defer buf.Release()
for i := range str {
kv := &pb.KV{
@@ -411,7 +411,7 @@ func TestStreamDone(t *testing.T) {
var val [10]byte
rand.Read(val[:])
for i := 0; i < 10; i++ {
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
defer buf.Release()
kv1 := &pb.KV{
Key: []byte(fmt.Sprintf("%d", i)),
@@ -452,7 +452,7 @@ func TestSendOnClosedStream(t *testing.T) {
var val [10]byte
rand.Read(val[:])
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
defer buf.Release()
kv1 := &pb.KV{
Key: []byte(fmt.Sprintf("%d", 1)),
@@ -475,7 +475,7 @@ func TestSendOnClosedStream(t *testing.T) {
require.NoError(t, db.Close())
}()
// Send once stream is closed.
buf1 := z.NewBuffer(10 << 20, "test")
buf1 := z.NewBuffer(10<<20, "test")
defer buf1.Release()
kv1 = &pb.KV{
Key: []byte(fmt.Sprintf("%d", 2)),
@@ -502,7 +502,7 @@ func TestSendOnClosedStream2(t *testing.T) {
var val [10]byte
rand.Read(val[:])
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
defer buf.Release()
kv1 := &pb.KV{
Key: []byte(fmt.Sprintf("%d", 1)),
@@ -549,7 +549,7 @@ func TestStreamWriterEncrypted(t *testing.T) {
key := []byte("mykey")
value := []byte("myvalue")
buf := z.NewBuffer(10 << 20, "test")
buf := z.NewBuffer(10<<20, "test")
defer buf.Release()
KVToBuffer(&pb.KV{
Key: key,
+1 -1
View File
@@ -809,7 +809,7 @@ func (t *Table) decompress(b *block) error {
if sz, err := snappy.DecodedLen(b.data); err == nil {
dst = z.Calloc(sz, "Table.Decompress")
} else {
dst = z.Calloc(len(b.data) * 4, "Table.Decompress") // Take a guess.
dst = z.Calloc(len(b.data)*4, "Table.Decompress") // Take a guess.
}
b.data, err = snappy.Decode(dst, b.data)
if err != nil {
+3 -3
View File
@@ -757,9 +757,9 @@ func (txn *Txn) ReadTs() uint64 {
// to. Commit API internally runs Discard, but running it twice wouldn't cause
// any issues.
//
// txn := db.NewTransaction(false)
// defer txn.Discard()
// // Call various APIs.
// txn := db.NewTransaction(false)
// defer txn.Discard()
// // Call various APIs.
func (db *DB) NewTransaction(update bool) *Txn {
return db.newTransaction(update, false)
}
+1
View File
@@ -1,3 +1,4 @@
//go:build !dragonfly && !freebsd && !windows && !plan9
// +build !dragonfly,!freebsd,!windows,!plan9
/*
+1
View File
@@ -1,3 +1,4 @@
//go:build dragonfly || freebsd || windows || plan9
// +build dragonfly freebsd windows plan9
/*
+1 -1
View File
@@ -166,4 +166,4 @@ func getFromMap(enabled bool, metric *expvar.Map, key string) expvar.Var {
}
return metric.Get(key)
}
}
+2 -2
View File
@@ -51,8 +51,8 @@ type mark struct {
// WaterMark is used to keep track of the minimum un-finished index. Typically, an index k becomes
// finished or "done" according to a WaterMark once Done(k) has been called
// 1. as many times as Begin(k) has, AND
// 2. a positive number of times.
// 1. as many times as Begin(k) has, AND
// 2. a positive number of times.
//
// An index may also become "done" by calling SetDoneUntil at a time such that it is not
// inter-mingled with Begin/Done calls.