From e9523063b58a357322baaf4451a598f9a814d235 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Fri, 20 Jul 2018 10:33:29 -0500 Subject: [PATCH] Fix linter issues: unused --- Makefile | 1 + boltdb/attrstore.go | 38 +---------------------- cluster.go | 7 ----- field.go | 72 ------------------------------------------- http/handler.go | 2 -- lru/lru.go | 4 +-- server/server_test.go | 10 ------ translate.go | 6 ---- view.go | 14 --------- 9 files changed, 4 insertions(+), 150 deletions(-) diff --git a/Makefile b/Makefile index 2f44a5f51..d0013ae02 100644 --- a/Makefile +++ b/Makefile @@ -125,6 +125,7 @@ gometalinter: require-gometalinter --enable=misspell \ --enable=nakedret \ --enable=unparam \ + --enable=unused \ --enable=vet \ --exclude "^internal/.*\.pb\.go" \ --exclude "^pql/pql.peg.go" \ diff --git a/boltdb/attrstore.go b/boltdb/attrstore.go index 09514360a..ec31c3f20 100644 --- a/boltdb/attrstore.go +++ b/boltdb/attrstore.go @@ -190,7 +190,7 @@ func (s *attrStore) SetBulkAttrs(m map[uint64]map[string]interface{}) error { for id := range m { ids = append(ids, id) } - sort.Sort(uint64Slice(ids)) + sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] }) // Update attributes for each id. for _, id := range ids { @@ -357,42 +357,6 @@ func mapContains(m, subset map[string]interface{}) bool { return true } -// uint64Slice represents a sortable slice of uint64 numbers. -type uint64Slice []uint64 - -func (p uint64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } -func (p uint64Slice) Len() int { return len(p) } -func (p uint64Slice) Less(i, j int) bool { return p[i] < p[j] } - -// merge combines p and other to a unique sorted set of values. -// p and other must both have unique sets and be sorted. -func (p uint64Slice) merge(other []uint64) []uint64 { - ret := make([]uint64, 0, len(p)) - - i, j := 0, 0 - for i < len(p) && j < len(other) { - a, b := p[i], other[j] - if a == b { - ret = append(ret, a) - i, j = i+1, j+1 - } else if a < b { - ret = append(ret, a) - i++ - } else { - ret = append(ret, b) - j++ - } - } - - if i < len(p) { - ret = append(ret, p[i:]...) - } else if j < len(other) { - ret = append(ret, other[j:]...) - } - - return ret -} - // blockCursor represents a cursor for iterating over blocks of a bolt bucket. type blockCursor struct { cur *bolt.Cursor diff --git a/cluster.go b/cluster.go index ff8042b87..fcc4425c9 100644 --- a/cluster.go +++ b/cluster.go @@ -569,13 +569,6 @@ func fragsDiff(a, b []frag) []frag { type fragsByHost map[string][]frag -func (a fragsByHost) add(b fragsByHost) fragsByHost { - for k, v := range b { - a[k] = append(a[k], v...) - } - return a -} - type viewsByField map[string][]string func (a viewsByField) addView(field, view string) { diff --git a/field.go b/field.go index b34d15c32..c72095661 100644 --- a/field.go +++ b/field.go @@ -514,43 +514,6 @@ func (f *Field) addBSIGroup(bsig *bsiGroup) error { return nil } -// deleteBSIGroupAndView deletes an existing bsiGroup on the schema. -func (f *Field) deleteBSIGroupAndView(name string) error { - f.mu.Lock() - defer f.mu.Unlock() - - // Remove bsiGroup. - if err := f.deleteBSIGroup(name); err != nil { - return err - } - - // Remove views. - viewName := viewBSIGroupPrefix + name - if view := f.viewMap[viewName]; view != nil { - delete(f.viewMap, viewName) - - if err := view.close(); err != nil { - return errors.Wrap(err, "closing view") - } else if err := os.RemoveAll(view.path); err != nil { - return errors.Wrap(err, "deleting directory") - } - } - - return nil -} - -// deleteBSIGroup removes a single bsiGroup from bsiGroups. -func (f *Field) deleteBSIGroup(name string) error { - for i, bsig := range f.bsiGroups { - if bsig.Name == name { - copy(f.bsiGroups[i:], f.bsiGroups[i+1:]) - f.bsiGroups, f.bsiGroups[len(f.bsiGroups)-1] = f.bsiGroups[:len(f.bsiGroups)-1], nil - return nil - } - } - return ErrBSIGroupNotFound -} - // TimeQuantum returns the time quantum for the field. func (f *Field) TimeQuantum() TimeQuantum { f.mu.Lock() @@ -619,18 +582,6 @@ func (f *Field) views() []*view { return other } -// viewNames returns a list of all views (as a string) in the field. -func (f *Field) viewNames() []string { - f.mu.Lock() - defer f.mu.Unlock() - - other := make([]string, 0, len(f.viewMap)) - for viewName := range f.viewMap { - other = append(other, viewName) - } - return other -} - // recalculateCaches recalculates caches on every view in the field. func (f *Field) recalculateCaches() { for _, view := range f.views() { @@ -979,29 +930,6 @@ func (f *Field) Range(name string, op pql.Token, predicate int64) (*Row, error) return view.rangeOp(op, bsig.BitDepth(), baseValue) } -func (f *Field) rangeBetween(name string, predicateMin, predicateMax int64) (*Row, error) { - // Retrieve and validate bsiGroup. - bsig := f.bsiGroup(name) - if bsig == nil { - return nil, ErrBSIGroupNotFound - } else if predicateMin > predicateMax { - return nil, ErrInvalidBetweenValue - } - - // Retrieve bsiGroup's view. - view := f.view(viewBSIGroupPrefix + name) - if view == nil { - return nil, nil - } - - baseValueMin, baseValueMax, outOfRange := bsig.baseValueBetween(predicateMin, predicateMax) - if outOfRange { - return NewRow(), nil - } - - return view.rangeBetween(bsig.BitDepth(), baseValueMin, baseValueMax) -} - // Import bulk imports data. func (f *Field) Import(rowIDs, columnIDs []uint64, timestamps []*time.Time) error { // Determine quantum if timestamps are set. diff --git a/http/handler.go b/http/handler.go index 8e0fcb709..3d5d328d9 100644 --- a/http/handler.go +++ b/http/handler.go @@ -51,8 +51,6 @@ type Handler struct { api *pilosa.API - allowedOrigins []string - ln net.Listener closeTimeout time.Duration diff --git a/lru/lru.go b/lru/lru.go index 86450690b..8ab4b9cd9 100644 --- a/lru/lru.go +++ b/lru/lru.go @@ -83,7 +83,7 @@ func (c *Cache) Get(key Key) (value interface{}, ok bool) { } // remove removes the provided key from the cache. -func (c *Cache) remove(key Key) { +func (c *Cache) remove(key Key) { // nolint: unused if c.cache == nil { return } @@ -121,7 +121,7 @@ func (c *Cache) Len() int { } // clear purges all stored items from the cache. -func (c *Cache) clear() { +func (c *Cache) clear() { // nolint: unused if c.OnEvicted != nil { for _, e := range c.cache { kv := e.Value.(*entry) diff --git a/server/server_test.go b/server/server_test.go index d0d3c7282..2c222984d 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -18,7 +18,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "math/rand" "reflect" "sort" @@ -253,15 +252,6 @@ func TestConfig_Parse_DataDir(t *testing.T) { } } -// tempMkdir makes a temporary directory -func tempMkdir(t *testing.T) string { - dir, err := ioutil.TempDir("", "pilosatemp") - if err != nil { - t.Fatalf("failed to create test directory: %s", err) - } - return dir -} - func TestMain_RecalculateHashes(t *testing.T) { const clusterSize = 5 cluster := test.MustRunCluster(t, clusterSize) diff --git a/translate.go b/translate.go index 580c08221..5ab089b1d 100644 --- a/translate.go +++ b/translate.go @@ -875,12 +875,6 @@ type elem struct { hash uint64 } -func (e *elem) reset() { - e.offset = 0 - e.id = 0 - e.hash = 0 -} - func hashKey(key []byte) uint64 { h := xxhash.Sum64(key) if h == 0 { diff --git a/view.go b/view.go index e53ac8970..d46947cc6 100644 --- a/view.go +++ b/view.go @@ -413,20 +413,6 @@ func (v *view) rangeOp(op pql.Token, bitDepth uint, predicate uint64) (*Row, err return r, nil } -// rangeBetween returns bitmaps with a field value encoding matching any -// value between predicateMin and predicateMax. -func (v *view) rangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) { - r := NewRow() - for _, frag := range v.allFragments() { - other, err := frag.rangeBetween(bitDepth, predicateMin, predicateMax) - if err != nil { - return nil, err - } - r = r.Union(other) - } - return r, nil -} - // ViewInfo represents schema information for a view. type ViewInfo struct { Name string `json:"name"`