Skip to content

Commit

Permalink
fix: remove polluting google log library
Browse files Browse the repository at this point in the history
For more context please see discussion https://discuss.dgraph.io/t/ristretto-0-1-0-pollutes-the-flags-namespace/14561

By reverting hypermodeinc#263 not only is the number of dependencies this library has greatly reduced, but projects using this library will not unavoidably panic.
  • Loading branch information
aeneasr committed Jan 20, 2022
1 parent 297c39e commit 2cc906e
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 43 deletions.
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
10 changes: 5 additions & 5 deletions contrib/memtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package main
import "C"
import (
"fmt"
"log"
"math/rand"
"net/http"
_ "net/http/pprof"
Expand All @@ -33,7 +34,6 @@ import (

"github.com/dgraph-io/ristretto/z"
"github.com/dustin/go-humanize"
"github.com/golang/glog"
)

type S struct {
Expand Down Expand Up @@ -67,7 +67,7 @@ func newS(sz int) *S {
s.val = Calloc(sz)
copy(s.val, fill)
if s.next != nil {
glog.Fatalf("news.next must be nil: %p", s.next)
log.Fatalf("news.next must be nil: %p", s.next)
}
return s
}
Expand All @@ -87,7 +87,7 @@ func (s *S) allocateNext(sz int) {

func (s *S) deallocNext() {
if s.next == nil {
glog.Fatal("next should not be nil")
log.Fatal("next should not be nil")
}
next := s.next
s.next = next.next
Expand Down Expand Up @@ -161,13 +161,13 @@ func main() {
}()
go func() {
if err := http.ListenAndServe("0.0.0.0:8080", nil); err != nil {
glog.Fatalf("Error: %v", err)
log.Fatalf("Error: %v", err)
}
}()

viaLL()
if left := NumAllocBytes(); left != 0 {
glog.Fatalf("Unable to deallocate all memory: %v\n", left)
log.Fatalf("Unable to deallocate all memory: %v\n", left)
}
runtime.GC()
fmt.Println("Done. Reduced to zero memory usage.")
Expand Down
8 changes: 4 additions & 4 deletions contrib/memtest/nojemalloc.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//+build !jemalloc
//go:build !jemalloc
// +build !jemalloc

package main

// #include <stdlib.h>
import "C"
import (
"log"
"reflect"
"sync/atomic"
"unsafe"

"github.com/golang/glog"
)

func Calloc(size int) []byte {
Expand Down Expand Up @@ -42,5 +42,5 @@ func NumAllocBytes() int64 { return atomic.LoadInt64(&numbytes) }
func check() {}

func init() {
glog.Infof("USING CALLOC")
log.Print("USING CALLOC")
}
10 changes: 6 additions & 4 deletions contrib/memtest/withjemalloc.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//+build jemalloc
//go:build jemalloc
// +build jemalloc

package main

import (
"log"

"github.com/dgraph-io/ristretto/z"
"github.com/golang/glog"
)

func Calloc(size int) []byte { return z.Calloc(size, "memtest") }
Expand All @@ -13,7 +15,7 @@ func NumAllocBytes() int64 { return z.NumAllocBytes() }

func check() {
if buf := z.CallocNoRef(1, "memtest"); len(buf) == 0 {
glog.Fatalf("Not using manual memory management. Compile with jemalloc.")
log.Fatalf("Not using manual memory management. Compile with jemalloc.")
} else {
z.Free(buf)
}
Expand All @@ -22,5 +24,5 @@ func check() {
}

func init() {
glog.Infof("USING JEMALLOC")
log.Infof("USING JEMALLOC")
}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ go 1.12

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/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f
)
13 changes: 5 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
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 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
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/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
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=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 3 additions & 4 deletions z/bbloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ package z
import (
"bytes"
"encoding/json"
"log"
"math"
"unsafe"

"github.com/golang/glog"
)

// helper
Expand Down Expand Up @@ -60,7 +59,7 @@ func NewBloomFilter(params ...float64) (bloomfilter *Bloom) {
entries, locs = uint64(params[0]), uint64(params[1])
}
} else {
glog.Fatal("usage: New(float64(number_of_entries), float64(number_of_hashlocations))" +
log.Fatal("usage: New(float64(number_of_entries), float64(number_of_hashlocations))" +
" i.e. New(float64(1000), float64(3)) or New(float64(number_of_entries)," +
" float64(number_of_hashlocations)) i.e. New(float64(1000), float64(0.03))")
}
Expand Down Expand Up @@ -205,7 +204,7 @@ func (bl Bloom) JSONMarshal() []byte {
}
data, err := json.Marshal(bloomImEx)
if err != nil {
glog.Fatal("json.Marshal failed: ", err)
log.Fatal("json.Marshal failed: ", err)
}
return data
}
6 changes: 3 additions & 3 deletions z/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"encoding/binary"
"fmt"
"io/ioutil"
"log"
"os"
"sort"
"sync/atomic"

"github.com/golang/glog"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -346,12 +346,12 @@ func (s *sortHelper) sortSmall(start, end int) {

func assert(b bool) {
if !b {
glog.Fatalf("%+v", errors.Errorf("Assertion failure"))
log.Fatalf("%+v", errors.Errorf("Assertion failure"))
}
}
func check(err error) {
if err != nil {
glog.Fatalf("%+v", err)
log.Fatalf("%+v", err)
}
}
func check2(_ interface{}, err error) {
Expand Down
3 changes: 2 additions & 1 deletion z/calloc_jemalloc.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
// +build jemalloc

package z
Expand Down Expand Up @@ -161,7 +162,7 @@ func fetchStat(s string) uint64 {
unsafe.Pointer(&out), // Variable to store the output.
(*C.size_t)(unsafe.Pointer(&sz)), // Size of the output variable.
nil, // Input variable used to set a value.
0) // Size of the input variable.
0) // Size of the input variable.
return out
}

Expand Down
18 changes: 9 additions & 9 deletions z/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package z

import (
"fmt"
"log"
"os"
"os/user"
"path/filepath"
Expand All @@ -10,7 +11,6 @@ import (
"strings"
"time"

"github.com/golang/glog"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -109,7 +109,7 @@ type SuperFlag struct {
func NewSuperFlag(flag string) *SuperFlag {
sf, err := newSuperFlagImpl(flag)
if err != nil {
glog.Fatal(err)
log.Fatal(err)
}
return sf
}
Expand All @@ -136,7 +136,7 @@ func (sf *SuperFlag) String() string {
func (sf *SuperFlag) MergeAndCheckDefault(flag string) *SuperFlag {
sf, err := sf.MergeWithDefault(flag)
if err != nil {
glog.Fatal(err)
log.Fatal(err)
}
return sf
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func (sf *SuperFlag) GetBool(opt string) bool {
err = errors.Wrapf(err,
"Unable to parse %s as bool for key: %s. Options: %s\n",
val, opt, sf)
glog.Fatalf("%+v", err)
log.Fatalf("%+v", err)
}
return b
}
Expand All @@ -222,7 +222,7 @@ func (sf *SuperFlag) GetFloat64(opt string) float64 {
err = errors.Wrapf(err,
"Unable to parse %s as float64 for key: %s. Options: %s\n",
val, opt, sf)
glog.Fatalf("%+v", err)
log.Fatalf("%+v", err)
}
return f
}
Expand All @@ -237,7 +237,7 @@ func (sf *SuperFlag) GetInt64(opt string) int64 {
err = errors.Wrapf(err,
"Unable to parse %s as int64 for key: %s. Options: %s\n",
val, opt, sf)
glog.Fatalf("%+v", err)
log.Fatalf("%+v", err)
}
return i
}
Expand All @@ -252,7 +252,7 @@ func (sf *SuperFlag) GetUint64(opt string) uint64 {
err = errors.Wrapf(err,
"Unable to parse %s as uint64 for key: %s. Options: %s\n",
val, opt, sf)
glog.Fatalf("%+v", err)
log.Fatalf("%+v", err)
}
return u
}
Expand All @@ -267,7 +267,7 @@ func (sf *SuperFlag) GetUint32(opt string) uint32 {
err = errors.Wrapf(err,
"Unable to parse %s as uint32 for key: %s. Options: %s\n",
val, opt, sf)
glog.Fatalf("%+v", err)
log.Fatalf("%+v", err)
}
return uint32(u)
}
Expand All @@ -283,7 +283,7 @@ func (sf *SuperFlag) GetPath(opt string) string {
p := sf.GetString(opt)
path, err := expandPath(p)
if err != nil {
glog.Fatalf("Failed to get path: %+v", err)
log.Fatalf("Failed to get path: %+v", err)
}
return path
}
Expand Down
3 changes: 2 additions & 1 deletion z/simd/search.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !amd64
// +build !amd64

/*
Expand All @@ -20,7 +21,7 @@ package simd

// Search uses the Clever search to find the correct key.
func Search(xs []uint64, k uint64) int16 {
if len(xs) < 8 || (len(xs) % 8 != 0) {
if len(xs) < 8 || (len(xs)%8 != 0) {
return Naive(xs, k)
}
var twos, pk [4]uint64
Expand Down

0 comments on commit 2cc906e

Please sign in to comment.