Skip to content

Commit

Permalink
update golangci config and cleanup repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mangalaman93 committed Aug 30, 2023
1 parent bdcf5e9 commit 695238b
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 78 deletions.
17 changes: 0 additions & 17 deletions .deepsource.toml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CODEOWNERS info: https://help.github.com/en/articles/about-code-owners
# Owners are automatically requested for review for PRs that changes code
# that they own.
* @akon-dey @nosql22 @joshua-goldstein @skrdgraph
* @joshua-goldstein @mangalaman93 @harshil-goel
4 changes: 2 additions & 2 deletions .github/workflows/ci-aqua-security-trivy-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- synchronize
- ready_for_review
branches:
- main
- main
schedule:
- cron: "0 * * * *"
jobs:
Expand All @@ -24,7 +24,7 @@ jobs:
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-ristretto-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: ci-ristretto-tests
on:
push:
branches:
- main
- main
pull_request_target:
branches:
- main
- main
schedule:
- cron: "30 * * * *"
jobs:
Expand Down
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.17.11
1.19
40 changes: 28 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
run:
tests: false
skip-dirs:
- contrib
- sim
skip-files:

linters-settings:
lll:
line-length: 120
staticcheck:
checks:
- all
- '-SA1019' # it is okay to use math/rand at times.
gosec:
excludes: # these are not relevant for us right now
- G101
- G107
- G108
- G110
- G112
- G114
- G201
- G204
- G306
- G402
- G404

linters:
disable-all: true
enable:
#- errcheck
#- ineffassign
- gas
#- gofmt
#- golint
#- gosimple
#- govet
- errcheck
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- lll
#- varcheck
#- unused
- staticcheck
- unconvert
- unused
2 changes: 1 addition & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ func TestDropUpdates(t *testing.T) {
var err error
handler := func(_ interface{}, value interface{}) {
v := value.(string)
lastEvictedSet, err = strconv.ParseInt(string(v), 10, 32)
lastEvictedSet, err = strconv.ParseInt(v, 10, 32)
require.NoError(t, err)

_, ok := droppedMap[int(lastEvictedSet)]
Expand Down
2 changes: 0 additions & 2 deletions contrib/demo/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"runtime"
"unsafe"

"github.com/dgraph-io/ristretto/z"
"github.com/dustin/go-humanize"
Expand All @@ -14,7 +13,6 @@ type node struct {
next *node
}

var nodeSz = int(unsafe.Sizeof(node{}))
var alloc *z.Allocator

func printNode(n *node) {
Expand Down
3 changes: 2 additions & 1 deletion contrib/demo/node_allocator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build jemalloc && allocator
// +build jemalloc,allocator

package main
Expand All @@ -10,7 +11,7 @@ import (

// Defined in node.go.
func init() {
alloc = z.NewAllocator(10 << 20, "demo")
alloc = z.NewAllocator(10<<20, "demo")
}

func newNode(val int) *node {
Expand Down
1 change: 1 addition & 0 deletions contrib/demo/node_golang.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !jemalloc
// +build !jemalloc

package main
Expand Down
1 change: 1 addition & 0 deletions contrib/demo/node_jemalloc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build jemalloc && !allocator
// +build jemalloc,!allocator

package main
Expand Down
15 changes: 10 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
module github.com/dgraph-io/ristretto

go 1.12
go 1.19

require (
github.com/cespare/xxhash/v2 v2.1.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2
github.com/dustin/go-humanize v1.0.0
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13
github.com/dustin/go-humanize v1.0.1
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.4.0
golang.org/x/sys v0.0.0-20221010170243-090e33056c14
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.11.0
)

require (
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
22 changes: 10 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 h1:k5II8e6QD8mITdi+okbbmR/cIyEbeXLBhy5Ha4nevyc=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 4 additions & 3 deletions policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const (
// policy is the interface encapsulating eviction/admission behavior.
//
// TODO: remove this interface and just rename defaultPolicy to policy, as we
// are probably only going to use/implement/maintain one policy.
//
// are probably only going to use/implement/maintain one policy.
type policy interface {
ringConsumer
// Add attempts to Add the key-cost pair to the Policy. It returns a slice
Expand Down Expand Up @@ -223,7 +224,7 @@ func (p *defaultPolicy) Del(key uint64) {

func (p *defaultPolicy) Cap() int64 {
p.Lock()
capacity := int64(p.evict.getMaxCost() - p.evict.used)
capacity := p.evict.getMaxCost() - p.evict.used
p.Unlock()
return capacity
}
Expand Down Expand Up @@ -346,7 +347,7 @@ func (p *sampledLFU) updateIfHas(key uint64, cost int64) bool {
p.metrics.add(keyUpdate, key, 1)
if prev > cost {
diff := prev - cost
p.metrics.add(costAdd, key, ^uint64(uint64(diff)-1))
p.metrics.add(costAdd, key, ^uint64(diff-1))
} else if cost > prev {
diff := cost - prev
p.metrics.add(costAdd, key, uint64(diff))
Expand Down
2 changes: 1 addition & 1 deletion sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func newCmRow(numCounters int64) cmRow {
}

func (r cmRow) get(n uint64) byte {
return byte(r[n/2]>>((n&1)*4)) & 0x0f
return (r[n/2] >> ((n & 1) * 4)) & 0x0f
}

func (r cmRow) increment(n uint64) {
Expand Down
1 change: 1 addition & 0 deletions z/bbloom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestM_NumberOfWrongs(t *testing.T) {
cnt++
}
}
//nolint:lll
fmt.Printf("Bloomfilter New(7* 2**16, 7) (-> size=%v bit): \n Check for 'false positives': %v wrong positive 'Has' results on 2**16 entries => %v %%\n", len(bf.bitset)<<6, cnt, float64(cnt)/float64(n))

}
Expand Down
2 changes: 2 additions & 0 deletions z/btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ func (t *Tree) split(pid uint64) node {
// shareWithSiblingXXX is unused for now. The idea is to move some keys to
// sibling when a node is full. But, I don't see any special benefits in our
// access pattern. It doesn't result in better occupancy ratios.
//
//nolint:unused
func (t *Tree) shareWithSiblingXXX(n node, idx int) bool {
if idx == 0 {
return false
Expand Down
5 changes: 2 additions & 3 deletions z/btree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package z

import (
"fmt"
"io/ioutil"
"math"
"math/rand"
"os"
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestTree(t *testing.T) {
}

func TestTreePersistent(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(dir)
path := filepath.Join(dir, "tree.buf")
Expand Down Expand Up @@ -439,7 +438,7 @@ func BenchmarkSearch(b *testing.B) {

jumpBy := []int{8, 16, 32, 64, 128, 196, 255}
for _, sz := range jumpBy {
f, err := ioutil.TempFile(".", "tree")
f, err := os.CreateTemp(".", "tree")
require.NoError(b, err)

mf, err := OpenMmapFileUsing(f, pageSize, true)
Expand Down
5 changes: 2 additions & 3 deletions z/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package z
import (
"encoding/binary"
"fmt"
"io/ioutil"
"log"
"os"
"sort"
Expand Down Expand Up @@ -92,7 +91,7 @@ func NewBufferTmp(dir string, capacity int) (*Buffer, error) {
if dir == "" {
dir = tmpDir
}
file, err := ioutil.TempFile(dir, "buffer")
file, err := os.CreateTemp(dir, "buffer")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -200,7 +199,7 @@ func (b *Buffer) Grow(n int) {
// If autoMmap gets triggered, copy the slice over to an mmaped file.
if b.autoMmapAfter > 0 && b.curSz > b.autoMmapAfter {
b.bufType = UseMmap
file, err := ioutil.TempFile(b.autoMmapDir, "")
file, err := os.CreateTemp(b.autoMmapDir, "")
if err != nil {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions z/calloc_64bit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.

//go:build amd64 || arm64 || arm64be || ppc64 || ppc64le || mips64 || mips64le || riscv64 || s390x || sparc64
// +build amd64 arm64 arm64be ppc64 ppc64le mips64 mips64le riscv64 s390x sparc64

package z
Expand Down
3 changes: 2 additions & 1 deletion z/calloc_nojemalloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.

//go:build !jemalloc || !cgo
// +build !jemalloc !cgo

package z
Expand Down Expand Up @@ -34,4 +35,4 @@ func StatsPrint() {

// ReadMemStats doesn't do anything since all the memory is being managed
// by the Go runtime.
func ReadMemStats(_ *MemStats) { return }
func ReadMemStats(_ *MemStats) {}
4 changes: 3 additions & 1 deletion z/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ func OpenMmapFileUsing(fd *os.File, sz int, writable bool) (*MmapFile, error) {

if fileSize == 0 {
dir, _ := filepath.Split(filename)
go SyncDir(dir)
if err := SyncDir(dir); err != nil {
return nil, err
}
}
return &MmapFile{
Data: buf,
Expand Down
1 change: 1 addition & 0 deletions z/file_default.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux

/*
Expand Down
1 change: 1 addition & 0 deletions z/mremap_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !arm64
// +build !arm64

/*
Expand Down
3 changes: 3 additions & 0 deletions z/rtutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import (
)

// NanoTime returns the current time in nanoseconds from a monotonic clock.
//
//go:linkname NanoTime runtime.nanotime
func NanoTime() int64

// CPUTicks is a faster alternative to NanoTime to measure time duration.
//
//go:linkname CPUTicks runtime.cputicks
func CPUTicks() int64

Expand Down Expand Up @@ -60,6 +62,7 @@ func MemHashString(str string) uint64 {
}

// FastRand is a fast thread local random function.
//
//go:linkname FastRand runtime.fastrand
func FastRand() uint32

Expand Down
Loading

0 comments on commit 695238b

Please sign in to comment.