Skip to content

Commit 270b48d

Browse files
authored
fix(linter): run go fmt on the repo (#1870)
1 parent 5eb141c commit 270b48d

18 files changed

+87
-70
lines changed

.golangci.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
run:
2-
tests: false
2+
skip-dirs:
3+
skip-files:
34

45
linters-settings:
56
lll:
@@ -8,14 +9,13 @@ linters-settings:
89
linters:
910
disable-all: true
1011
enable:
11-
# - errcheck
12-
# - ineffassign
13-
# - gas
12+
# - errcheck
13+
# - ineffassign
14+
# - gas
1415
- gofmt
15-
# - golint
16-
- gosimple
17-
- govet
18-
- lll
19-
# - varcheck
20-
# - unused
21-
# - gosec
16+
# - gosimple
17+
# - govet
18+
# - lll
19+
# - unused
20+
# - staticcheck
21+
- goimports

db.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,8 @@ func (db *DB) doWrites(lc *z.Closer) {
945945

946946
// batchSet applies a list of badger.Entry. If a request level error occurs it
947947
// will be returned.
948-
// Check(kv.BatchSet(entries))
948+
//
949+
// Check(kv.BatchSet(entries))
949950
func (db *DB) batchSet(entries []*Entry) error {
950951
req, err := db.sendToWriteCh(entries)
951952
if err != nil {
@@ -958,9 +959,10 @@ func (db *DB) batchSet(entries []*Entry) error {
958959
// batchSetAsync is the asynchronous version of batchSet. It accepts a callback
959960
// function which is called when all the sets are complete. If a request level
960961
// error occurs, it will be passed back via the callback.
961-
// err := kv.BatchSetAsync(entries, func(err error)) {
962-
// Check(err)
963-
// }
962+
//
963+
// err := kv.BatchSetAsync(entries, func(err error)) {
964+
// Check(err)
965+
// }
964966
func (db *DB) batchSetAsync(entries []*Entry, f func(error)) error {
965967
req, err := db.sendToWriteCh(entries)
966968
if err != nil {
@@ -1719,16 +1721,16 @@ func (db *DB) dropAll() (func(), error) {
17191721
}
17201722

17211723
// DropPrefix would drop all the keys with the provided prefix. It does this in the following way:
1722-
// - Stop accepting new writes.
1723-
// - Stop memtable flushes before acquiring lock. Because we're acquring lock here
1724-
// and memtable flush stalls for lock, which leads to deadlock
1725-
// - Flush out all memtables, skipping over keys with the given prefix, Kp.
1726-
// - Write out the value log header to memtables when flushing, so we don't accidentally bring Kp
1727-
// back after a restart.
1728-
// - Stop compaction.
1729-
// - Compact L0->L1, skipping over Kp.
1730-
// - Compact rest of the levels, Li->Li, picking tables which have Kp.
1731-
// - Resume memtable flushes, compactions and writes.
1724+
// - Stop accepting new writes.
1725+
// - Stop memtable flushes before acquiring lock. Because we're acquring lock here
1726+
// and memtable flush stalls for lock, which leads to deadlock
1727+
// - Flush out all memtables, skipping over keys with the given prefix, Kp.
1728+
// - Write out the value log header to memtables when flushing, so we don't accidentally bring Kp
1729+
// back after a restart.
1730+
// - Stop compaction.
1731+
// - Compact L0->L1, skipping over Kp.
1732+
// - Compact rest of the levels, Li->Li, picking tables which have Kp.
1733+
// - Resume memtable flushes, compactions and writes.
17321734
func (db *DB) DropPrefix(prefixes ...[]byte) error {
17331735
if len(prefixes) == 0 {
17341736
return nil

db2_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,17 @@ func TestL0GCBug(t *testing.T) {
657657
//
658658
// The test has 3 steps
659659
// Step 1 - Create badger data. It is necessary that the value size is
660-
// greater than valuethreshold. The value log file size after
661-
// this step is around 170 bytes.
660+
//
661+
// greater than valuethreshold. The value log file size after
662+
// this step is around 170 bytes.
663+
//
662664
// Step 2 - Re-open the same badger and simulate a crash. The value log file
663-
// size after this crash is around 2 GB (we increase the file size to mmap it).
665+
//
666+
// size after this crash is around 2 GB (we increase the file size to mmap it).
667+
//
664668
// Step 3 - Re-open the same badger. We should be able to read all the data
665-
// inserted in the first step.
669+
//
670+
// inserted in the first step.
666671
func TestWindowsDataLoss(t *testing.T) {
667672
if runtime.GOOS != "windows" {
668673
t.Skip("The test is only for Windows.")
@@ -995,7 +1000,7 @@ func TestKeyCount(t *testing.T) {
9951000
}()
9961001

9971002
write := func(kvs *pb.KVList) error {
998-
buf := z.NewBuffer(1 << 20, "test")
1003+
buf := z.NewBuffer(1<<20, "test")
9991004
defer buf.Release()
10001005

10011006
for _, kv := range kvs.Kv {

dir_plan9.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ func syncDir(dir string) error {
123123
// Opening an exclusive-use file returns an error.
124124
// The expected error strings are:
125125
//
126-
// - "open/create -- file is locked" (cwfs, kfs)
127-
// - "exclusive lock" (fossil)
128-
// - "exclusive use file already open" (ramfs)
126+
// - "open/create -- file is locked" (cwfs, kfs)
127+
// - "exclusive lock" (fossil)
128+
// - "exclusive use file already open" (ramfs)
129129
//
130130
// See https://github.com/golang/go/blob/go1.15rc1/src/cmd/go/internal/lockedfile/lockedfile_plan9.go#L16
131131
var lockedErrStrings = [...]string{

dir_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows && !plan9
12
// +build !windows,!plan9
23

34
/*

dir_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows
12
// +build windows
23

34
/*

doc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ hence reducing both write amplification and the size of the LSM tree. This
1010
allows LSM tree to be served entirely from RAM, while the values are served
1111
from SSD.
1212
13-
14-
Usage
13+
# Usage
1514
1615
Badger has the following main types: DB, Txn, Item and Iterator. DB contains
1716
keys that are associated with values. It must be opened with the appropriate

iterator_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,16 @@ func TestIteratorReadOnlyWithNoData(t *testing.T) {
324324
// pkg: github.com/dgraph-io/badger
325325
// BenchmarkIteratePrefixSingleKey/Key_lookups-4 10000 365539 ns/op
326326
// --- BENCH: BenchmarkIteratePrefixSingleKey/Key_lookups-4
327-
// iterator_test.go:147: Inner b.N: 1
328-
// iterator_test.go:147: Inner b.N: 100
329-
// iterator_test.go:147: Inner b.N: 10000
327+
//
328+
// iterator_test.go:147: Inner b.N: 1
329+
// iterator_test.go:147: Inner b.N: 100
330+
// iterator_test.go:147: Inner b.N: 10000
331+
//
330332
// --- BENCH: BenchmarkIteratePrefixSingleKey
331-
// iterator_test.go:143: LSM files: 79
332-
// iterator_test.go:145: Outer b.N: 1
333+
//
334+
// iterator_test.go:143: LSM files: 79
335+
// iterator_test.go:145: Outer b.N: 1
336+
//
333337
// PASS
334338
// ok github.com/dgraph-io/badger 41.586s
335339
//
@@ -339,12 +343,16 @@ func TestIteratorReadOnlyWithNoData(t *testing.T) {
339343
// pkg: github.com/dgraph-io/badger
340344
// BenchmarkIteratePrefixSingleKey/Key_lookups-4 10000 460924 ns/op
341345
// --- BENCH: BenchmarkIteratePrefixSingleKey/Key_lookups-4
342-
// iterator_test.go:147: Inner b.N: 1
343-
// iterator_test.go:147: Inner b.N: 100
344-
// iterator_test.go:147: Inner b.N: 10000
346+
//
347+
// iterator_test.go:147: Inner b.N: 1
348+
// iterator_test.go:147: Inner b.N: 100
349+
// iterator_test.go:147: Inner b.N: 10000
350+
//
345351
// --- BENCH: BenchmarkIteratePrefixSingleKey
346-
// iterator_test.go:143: LSM files: 83
347-
// iterator_test.go:145: Outer b.N: 1
352+
//
353+
// iterator_test.go:143: LSM files: 83
354+
// iterator_test.go:145: Outer b.N: 1
355+
//
348356
// PASS
349357
// ok github.com/dgraph-io/badger 41.836s
350358
//

options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ func (opt Options) WithValueThreshold(val int64) Options {
514514
// and only 1 percent in vlog. The value threshold will be dynamically updated within the range of
515515
// [ValueThreshold, Options.maxValueThreshold]
516516
//
517-
// Say VLogPercentile with 1.0 means threshold will eventually set to Options.maxValueThreshold
517+
// # Say VLogPercentile with 1.0 means threshold will eventually set to Options.maxValueThreshold
518518
//
519519
// The default value of VLogPercentile is 0.0.
520520
func (opt Options) WithVLogPercentile(t float64) Options {

publisher.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ import (
2727
)
2828

2929
type subscriber struct {
30-
id uint64
30+
id uint64
3131
matches []pb.Match
3232
sendCh chan *pb.KVList
3333
subCloser *z.Closer
3434
// this will be atomic pointer which will be used to
3535
// track whether the subscriber is active or not
36-
active *uint64
36+
active *uint64
3737
}
3838

3939
type publisher struct {
@@ -126,8 +126,8 @@ func (p *publisher) newSubscriber(c *z.Closer, matches []pb.Match) subscriber {
126126
p.nextID++
127127
active := uint64(1)
128128
s := subscriber{
129-
active: &active,
130-
id: id,
129+
active: &active,
130+
id: id,
131131
matches: matches,
132132
sendCh: ch,
133133
subCloser: c,

publisher_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func TestPublisherDeadlock(t *testing.T) {
4040
var firstUpdate sync.WaitGroup
4141
firstUpdate.Add(1)
4242

43-
4443
var subDone sync.WaitGroup
4544
subDone.Add(1)
4645
go func() {
@@ -61,7 +60,7 @@ func TestPublisherDeadlock(t *testing.T) {
6160
return txn.SetEntry(e)
6261
})
6362
require.NoError(t, err)
64-
} ()
63+
}()
6564

6665
firstUpdate.Wait()
6766
req := int64(0)

stream_writer_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
func getSortedKVList(valueSize, listSize int) *z.Buffer {
3737
value := make([]byte, valueSize)
3838
y.Check2(rand.Read(value))
39-
buf := z.NewBuffer(10 << 20, "test")
39+
buf := z.NewBuffer(10<<20, "test")
4040
for i := 0; i < listSize; i++ {
4141
key := make([]byte, 8)
4242
binary.BigEndian.PutUint64(key, uint64(i))
@@ -175,7 +175,7 @@ func TestStreamWriter3(t *testing.T) {
175175
value := make([]byte, valueSize)
176176
y.Check2(rand.Read(value))
177177
counter := 0
178-
buf := z.NewBuffer(10 << 20, "test")
178+
buf := z.NewBuffer(10<<20, "test")
179179
defer buf.Release()
180180
for i := 0; i < noOfKeys; i++ {
181181
key := make([]byte, 8)
@@ -272,7 +272,7 @@ func TestStreamWriter4(t *testing.T) {
272272
require.NoError(t, err, "error while updating db")
273273
}
274274

275-
buf := z.NewBuffer(10 << 20, "test")
275+
buf := z.NewBuffer(10<<20, "test")
276276
defer buf.Release()
277277
KVToBuffer(&pb.KV{
278278
Key: []byte("key-1"),
@@ -297,7 +297,7 @@ func TestStreamWriter5(t *testing.T) {
297297
right[0] = 0xff
298298
copy(right[1:], []byte("break"))
299299

300-
buf := z.NewBuffer(10 << 20, "test")
300+
buf := z.NewBuffer(10<<20, "test")
301301
defer buf.Release()
302302
KVToBuffer(&pb.KV{
303303
Key: left,
@@ -336,7 +336,7 @@ func TestStreamWriter6(t *testing.T) {
336336
// will be written to level 6, we need to insert at least 1 mb of data.
337337
// Setting keycount below 32 would cause this test to fail.
338338
keyCount := 40
339-
buf := z.NewBuffer(10 << 20, "test")
339+
buf := z.NewBuffer(10<<20, "test")
340340
defer buf.Release()
341341
for i := range str {
342342
for j := 0; j < keyCount; j++ {
@@ -377,7 +377,7 @@ func TestStreamWriterCancel(t *testing.T) {
377377
runBadgerTest(t, &opt, func(t *testing.T, db *DB) {
378378
str := []string{"a", "a", "b", "b", "c", "c"}
379379
ver := 1
380-
buf := z.NewBuffer(10 << 20, "test")
380+
buf := z.NewBuffer(10<<20, "test")
381381
defer buf.Release()
382382
for i := range str {
383383
kv := &pb.KV{
@@ -411,7 +411,7 @@ func TestStreamDone(t *testing.T) {
411411
var val [10]byte
412412
rand.Read(val[:])
413413
for i := 0; i < 10; i++ {
414-
buf := z.NewBuffer(10 << 20, "test")
414+
buf := z.NewBuffer(10<<20, "test")
415415
defer buf.Release()
416416
kv1 := &pb.KV{
417417
Key: []byte(fmt.Sprintf("%d", i)),
@@ -452,7 +452,7 @@ func TestSendOnClosedStream(t *testing.T) {
452452

453453
var val [10]byte
454454
rand.Read(val[:])
455-
buf := z.NewBuffer(10 << 20, "test")
455+
buf := z.NewBuffer(10<<20, "test")
456456
defer buf.Release()
457457
kv1 := &pb.KV{
458458
Key: []byte(fmt.Sprintf("%d", 1)),
@@ -475,7 +475,7 @@ func TestSendOnClosedStream(t *testing.T) {
475475
require.NoError(t, db.Close())
476476
}()
477477
// Send once stream is closed.
478-
buf1 := z.NewBuffer(10 << 20, "test")
478+
buf1 := z.NewBuffer(10<<20, "test")
479479
defer buf1.Release()
480480
kv1 = &pb.KV{
481481
Key: []byte(fmt.Sprintf("%d", 2)),
@@ -502,7 +502,7 @@ func TestSendOnClosedStream2(t *testing.T) {
502502

503503
var val [10]byte
504504
rand.Read(val[:])
505-
buf := z.NewBuffer(10 << 20, "test")
505+
buf := z.NewBuffer(10<<20, "test")
506506
defer buf.Release()
507507
kv1 := &pb.KV{
508508
Key: []byte(fmt.Sprintf("%d", 1)),
@@ -549,7 +549,7 @@ func TestStreamWriterEncrypted(t *testing.T) {
549549
key := []byte("mykey")
550550
value := []byte("myvalue")
551551

552-
buf := z.NewBuffer(10 << 20, "test")
552+
buf := z.NewBuffer(10<<20, "test")
553553
defer buf.Release()
554554
KVToBuffer(&pb.KV{
555555
Key: key,

table/table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ func (t *Table) decompress(b *block) error {
809809
if sz, err := snappy.DecodedLen(b.data); err == nil {
810810
dst = z.Calloc(sz, "Table.Decompress")
811811
} else {
812-
dst = z.Calloc(len(b.data) * 4, "Table.Decompress") // Take a guess.
812+
dst = z.Calloc(len(b.data)*4, "Table.Decompress") // Take a guess.
813813
}
814814
b.data, err = snappy.Decode(dst, b.data)
815815
if err != nil {

txn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,9 @@ func (txn *Txn) ReadTs() uint64 {
757757
// to. Commit API internally runs Discard, but running it twice wouldn't cause
758758
// any issues.
759759
//
760-
// txn := db.NewTransaction(false)
761-
// defer txn.Discard()
762-
// // Call various APIs.
760+
// txn := db.NewTransaction(false)
761+
// defer txn.Discard()
762+
// // Call various APIs.
763763
func (db *DB) NewTransaction(update bool) *Txn {
764764
return db.newTransaction(update, false)
765765
}

y/file_dsync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !dragonfly && !freebsd && !windows && !plan9
12
// +build !dragonfly,!freebsd,!windows,!plan9
23

34
/*

y/file_nodsync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build dragonfly || freebsd || windows || plan9
12
// +build dragonfly freebsd windows plan9
23

34
/*

y/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,4 @@ func getFromMap(enabled bool, metric *expvar.Map, key string) expvar.Var {
166166
}
167167

168168
return metric.Get(key)
169-
}
169+
}

y/watermark.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ type mark struct {
5151

5252
// WaterMark is used to keep track of the minimum un-finished index. Typically, an index k becomes
5353
// finished or "done" according to a WaterMark once Done(k) has been called
54-
// 1. as many times as Begin(k) has, AND
55-
// 2. a positive number of times.
54+
// 1. as many times as Begin(k) has, AND
55+
// 2. a positive number of times.
5656
//
5757
// An index may also become "done" by calling SetDoneUntil at a time such that it is not
5858
// inter-mingled with Begin/Done calls.

0 commit comments

Comments
 (0)