Merge pull request #1286 from jaffee/remove-unused-code

Remove unused code
This commit is contained in:
Matthew Jaffee 2018-05-15 13:48:19 -05:00 committed by GitHub
commit d2853cda56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 43 additions and 262 deletions

View file

@ -233,7 +233,7 @@ func (c *RankCache) Recalculate() {
func (c *RankCache) invalidate() {
// Don't invalidate more than once every X seconds.
// TODO: consider making this configurable.
if time.Now().Sub(c.updateTime).Seconds() < 10 {
if time.Since(c.updateTime).Seconds() < 10 {
return
}
c.stats.Count("cache.invalidate", 1, 1.0)
@ -505,7 +505,7 @@ func NewNopCache() *NopCache {
func (c *NopCache) Add(id uint64, n uint64) {}
func (c *NopCache) BulkAdd(id uint64, n uint64) {}
func (c *NopCache) Get(id uint64) uint64 { return 0 }
func (c *NopCache) IDs() []uint64 { return make([]uint64, 0, 0) }
func (c *NopCache) IDs() []uint64 { return make([]uint64, 0) }
func (c *NopCache) Invalidate() {}
func (c *NopCache) Len() int { return 0 }

View file

@ -1111,6 +1111,9 @@ func (c *InternalHTTPClient) SendMessage(ctx context.Context, uri *URI, pb proto
u := uriPathToURL(uri, "/cluster/message")
req, err := http.NewRequest("POST", u.String(), bytes.NewReader(msg))
if err != nil {
return errors.Wrap(err, "making new request")
}
req.Header.Set("Content-Type", "application/x-protobuf")
req.Header.Set("User-Agent", "pilosa/"+Version)

View file

@ -541,16 +541,6 @@ func (c *Cluster) nodeByID(id string) *Node {
return nil
}
// nodeByURI returns a node reference by node URI.
func (c *Cluster) nodeByURI(uri URI) *Node {
for _, n := range c.Nodes {
if n.URI == uri {
return n
}
}
return nil
}
// nodePositionByID returns the position of the node in slice c.Nodes.
func (c *Cluster) nodePositionByID(nodeID string) int {
for i, n := range c.Nodes {
@ -622,9 +612,7 @@ type fragsByHost map[string][]frag
func (a fragsByHost) add(b fragsByHost) fragsByHost {
for k, v := range b {
for _, vv := range v {
a[k] = append(a[k], vv)
}
a[k] = append(a[k], v...)
}
return a
}
@ -1175,9 +1163,7 @@ func (c *Cluster) generateResizeJobByAction(nodeAction nodeAction) (*ResizeJob,
}
for id, sources := range fragSources {
for _, src := range sources {
multiIndex[id] = append(multiIndex[id], src)
}
multiIndex[id] = append(multiIndex[id], sources...)
}
}
@ -1299,10 +1285,8 @@ func (c *Cluster) FollowResizeInstruction(instr *internal.ResizeInstruction) err
// Write to local frame and always close reader.
if err := func() error {
defer rd.Close()
if _, err := frag.ReadFrom(rd); err != nil {
return err
}
return nil
_, err := frag.ReadFrom(rd)
return err
}(); err != nil {
return errors.Wrap(err, "copying remote slice")
}

View file

@ -85,6 +85,9 @@ func (d *DiagnosticsCollector) Flush() error {
return errors.Wrap(err, "encoding")
}
req, err := http.NewRequest("POST", d.host, bytes.NewReader(buf))
if err != nil {
return errors.Wrap(err, "making new request")
}
req.Header.Set("Content-Type", "application/json")
resp, err := d.client.Do(req)
if err != nil {
@ -99,6 +102,9 @@ func (d *DiagnosticsCollector) Flush() error {
func (d *DiagnosticsCollector) CheckVersion() error {
var rsp versionResponse
req, err := http.NewRequest("GET", d.VersionURL, nil)
if err != nil {
return errors.Wrap(err, "making request")
}
resp, err := d.client.Do(req)
if err != nil {
return errors.Wrap(err, "getting version")

View file

@ -122,7 +122,7 @@ func (e *Executor) Execute(ctx context.Context, index string, q *pql.Query, slic
for _, call := range q.Calls {
if call.SupportsInverse() && needsSlices {
// Fetch frame & row label based on argument.
frame, _ := call.Args["frame"].(string)
frame := call.Args["frame"].(string)
if frame == "" {
frame = DefaultFrame
}
@ -192,7 +192,7 @@ func (e *Executor) validateCallArgs(c *pql.Call) error {
case []int64, []uint64:
// noop
case []interface{}:
b := make([]int64, len(v), len(v))
b := make([]int64, len(v))
for i := range v {
b[i] = v[i].(int64)
}
@ -206,9 +206,9 @@ func (e *Executor) validateCallArgs(c *pql.Call) error {
// executeSum executes a Sum() call.
func (e *Executor) executeSum(ctx context.Context, index string, c *pql.Call, slices []uint64, opt *ExecOptions) (ValCount, error) {
if frame, _ := c.Args["frame"]; frame == "" {
if frame := c.Args["frame"]; frame == "" {
return ValCount{}, errors.New("Sum(): frame required")
} else if field, _ := c.Args["field"]; field == "" {
} else if field := c.Args["field"]; field == "" {
return ValCount{}, errors.New("Sum(): field required")
}
@ -241,9 +241,9 @@ func (e *Executor) executeSum(ctx context.Context, index string, c *pql.Call, sl
// executeFieldMin executes a Min() call.
func (e *Executor) executeFieldMin(ctx context.Context, index string, c *pql.Call, slices []uint64, opt *ExecOptions) (ValCount, error) {
if frame, _ := c.Args["frame"]; frame == "" {
if frame := c.Args["frame"]; frame == "" {
return ValCount{}, errors.New("Min(): frame required")
} else if field, _ := c.Args["field"]; field == "" {
} else if field := c.Args["field"]; field == "" {
return ValCount{}, errors.New("Min(): field required")
}
@ -276,9 +276,9 @@ func (e *Executor) executeFieldMin(ctx context.Context, index string, c *pql.Cal
// executeFieldMax executes a Max() call.
func (e *Executor) executeFieldMax(ctx context.Context, index string, c *pql.Call, slices []uint64, opt *ExecOptions) (ValCount, error) {
if frame, _ := c.Args["frame"]; frame == "" {
if frame := c.Args["frame"]; frame == "" {
return ValCount{}, errors.New("Max(): frame required")
} else if field, _ := c.Args["field"]; field == "" {
} else if field := c.Args["field"]; field == "" {
return ValCount{}, errors.New("Max(): field required")
}
@ -1554,7 +1554,7 @@ loop:
// If a mapping of slices to a node fails then the slices are resplit across
// secondary nodes and retried. This continues to occur until all nodes are exhausted.
func (e *Executor) mapReduce(ctx context.Context, index string, slices []uint64, c *pql.Call, opt *ExecOptions, mapFn mapFunc, reduceFn reduceFunc) (interface{}, error) {
ch := make(chan mapResponse, 0)
ch := make(chan mapResponse)
// Wrap context with a cancel to kill goroutines on exit.
ctx, cancel := context.WithCancel(ctx)

View file

@ -1013,7 +1013,7 @@ func (f *Fragment) Top(opt TopOptions) ([]Pair, error) {
}
//Pop first opt.N elements out of heap
r := make(Pairs, results.Len(), results.Len())
r := make(Pairs, results.Len())
x := results.Len()
i := 1
for results.Len() > 0 {

View file

@ -1179,8 +1179,8 @@ func BenchmarkFragment_FullSnapshot(b *testing.B) {
// Generate some intersecting data.
maxX := 1048576 / 2
sz := maxX
rows := make([]uint64, sz, sz)
cols := make([]uint64, sz, sz)
rows := make([]uint64, sz)
cols := make([]uint64, sz)
max := 0
for row := 0; row < 100; row++ {
@ -1215,8 +1215,8 @@ func BenchmarkFragment_Import(b *testing.B) {
defer f.Close()
maxX := 1048576 * 5 * 2
sz := maxX
rows := make([]uint64, sz, sz)
cols := make([]uint64, sz, sz)
rows := make([]uint64, sz)
cols := make([]uint64, sz)
i := 0
for row := 0; row < 100; row++ {
val := 1

View file

@ -29,7 +29,6 @@ import (
"strconv"
"strings"
"time"
"unicode"
"github.com/gogo/protobuf/proto"
"github.com/gorilla/mux"
@ -683,8 +682,6 @@ type getFrameFieldsResponse struct {
Fields []*Field `json:"fields,omitempty"`
}
type deleteFrameFieldRequest struct{}
type deleteFrameFieldResponse struct{}
// handleGetFrameViews handles GET /frame/views request.
@ -779,29 +776,6 @@ type postFrameAttrDiffResponse struct {
Attrs map[uint64]map[string]interface{} `json:"attrs"`
}
// readColumnAttrSets returns a list of column attribute objects by id.
func (h *Handler) readColumnAttrSets(index *Index, ids []uint64) ([]*ColumnAttrSet, error) {
if index == nil {
return nil, nil
}
a := make([]*ColumnAttrSet, 0, len(ids))
for _, id := range ids {
// Read attributes for column. Skip column if empty.
attrs, err := index.ColumnAttrStore().Attrs(id)
if err != nil {
return nil, err
} else if len(attrs) == 0 {
continue
}
// Append column with attributes.
a = append(a, &ColumnAttrSet{ID: id, Attrs: attrs})
}
return a, nil
}
// readQueryRequest parses an query parameters from r.
func (h *Handler) readQueryRequest(r *http.Request) (*QueryRequest, error) {
switch r.Header.Get("Content-Type") {
@ -855,21 +829,6 @@ func (h *Handler) readURLQueryRequest(r *http.Request) (*QueryRequest, error) {
}, nil
}
// validOptions return all attributes of an interface with lower first character.
func validOptions(v interface{}) map[string]bool {
validQuery := make(map[string]bool)
argsType := reflect.ValueOf(v).Type()
for i := 0; i < argsType.NumField(); i++ {
fieldName := argsType.Field(i).Name
chars := []rune(fieldName)
chars[0] = unicode.ToLower(chars[0])
fieldName = string(chars)
validQuery[fieldName] = true
}
return validQuery
}
// writeQueryResponse writes the response from the executor to w.
func (h *Handler) writeQueryResponse(w http.ResponseWriter, r *http.Request, resp *QueryResponse) error {
if strings.Contains(r.Header.Get("Accept"), "application/x-protobuf") {

View file

@ -492,7 +492,7 @@ func TestHandler_Query_Bitmap_Protobuf(t *testing.T) {
t.Fatalf("unexpected attr[0]: %s=%v", k, v)
} else if k, v := attrs[1].Key, attrs[1].IntValue; k != "c" || v != int64(1) {
t.Fatalf("unexpected attr[1]: %s=%v", k, v)
} else if k, v := attrs[2].Key, attrs[2].BoolValue; k != "d" || v != true {
} else if k, v := attrs[2].Key, attrs[2].BoolValue; k != "d" || !v {
t.Fatalf("unexpected attr[2]: %s=%v", k, v)
}
}
@ -551,7 +551,7 @@ func TestHandler_Query_Bitmap_ColumnAttrs_Protobuf(t *testing.T) {
t.Fatalf("unexpected attr[0]: %s=%v", k, v)
} else if k, v := attrs[1].Key, attrs[1].IntValue; k != "c" || v != int64(1) {
t.Fatalf("unexpected attr[1]: %s=%v", k, v)
} else if k, v := attrs[2].Key, attrs[2].BoolValue; k != "d" || v != true {
} else if k, v := attrs[2].Key, attrs[2].BoolValue; k != "d" || !v {
t.Fatalf("unexpected attr[2]: %s=%v", k, v)
}
@ -1076,6 +1076,9 @@ func TestHandler_Frame_GetFields(t *testing.T) {
t.Run("ErrFrameFieldNotAllowed", func(t *testing.T) {
idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{})
_, err := idx.CreateFrameIfNotExists("f1", pilosa.FrameOptions{})
if err != nil {
t.Fatalf("creating frame: %v", err)
}
resp, err := http.Get(s.URL + "/index/i/frame/f1/fields")
if err != nil {
@ -1222,104 +1225,6 @@ func TestHandler_Expvars(t *testing.T) {
}
}
var defaultBody = `
{
"frames":[
{
"name":"cab-type",
"options": {
"timeQuantum":"YMD",
"inverseEnabled":false,
"cacheType":"ranked"
}
},
{
"name":"add-ons",
"options": {
"timeQuantum":"YMD",
"inverseEnabled":false,
"cacheType":"ranked"
}
},
{
"name":"distance-miles",
"options": {
"timeQuantum":"YMD",
"cacheType":"ranked"
}
}
],
"fields":[
{
"name":"id",
"primaryKey":true
},
{
"name":"cabType",
"actions":[
{
"frame":"cab-type",
"valueDestination":"mapping",
"valueMap":{
"green":1,
"yellow":2
}
}
]
},
{
"name":"withPet",
"actions":[
{
"frame":"add-ons",
"valueDestination":"single-row-boolean",
"rowID":100
}
]
},
{
"name":"distanceMiles",
"actions":[
{
"frame":"distance-miles",
"valueDestination":"value-to-row"
}
]
},
{
"name":"noFrame",
"actions":[
{
"frame":"foo",
"valueDestination":"value-to-row"
}
]
},
{
"name":"null_value",
"actions":[
{
"frame":"add-ons",
"valueDestination":"value-to-row"
}
]
},
{
"name":"time_value",
"actions":[
{
"frame":"add-ons",
"valueDestination":"set-timestamp"
}
]
}
]
}`
func MustReadAll(r io.Reader) []byte {
buf, err := ioutil.ReadAll(r)
if err != nil {

View file

@ -75,7 +75,7 @@ type Holder struct {
func NewHolder() *Holder {
return &Holder{
indexes: make(map[string]*Index),
closing: make(chan struct{}, 0),
closing: make(chan struct{}),
opened: make(chan struct{}),

View file

@ -249,6 +249,9 @@ func TestIndex_InvalidName(t *testing.T) {
panic(err)
}
index, err := pilosa.NewIndex(path, "ABC")
if err == nil {
t.Fatalf("should have gotten an error on index name with caps")
}
if index != nil {
t.Fatalf("unexpected index name %v", index)
}

View file

@ -98,15 +98,6 @@ func encodeColumnAttrSets(a []*ColumnAttrSet) []*internal.ColumnAttrSet {
return other
}
// decodeColumnAttrSets converts a from its internal representation.
func decodeColumnAttrSets(a []*internal.ColumnAttrSet) []*ColumnAttrSet {
other := make([]*ColumnAttrSet, len(a))
for i := range a {
other[i] = decodeColumnAttrSet(a[i])
}
return other
}
// encodeColumnAttrSet converts set into its internal representation.
func encodeColumnAttrSet(set *ColumnAttrSet) *internal.ColumnAttrSet {
return &internal.ColumnAttrSet{
@ -115,29 +106,12 @@ func encodeColumnAttrSet(set *ColumnAttrSet) *internal.ColumnAttrSet {
}
}
// decodeColumnAttrSet converts b from its internal representation.
func decodeColumnAttrSet(pb *internal.ColumnAttrSet) *ColumnAttrSet {
set := &ColumnAttrSet{
ID: pb.ID,
}
if len(pb.Attrs) > 0 {
set.Attrs = make(map[string]interface{}, len(pb.Attrs))
for _, attr := range pb.Attrs {
k, v := decodeAttr(attr)
set.Attrs[k] = v
}
}
return set
}
// TimeFormat is the go-style time format used to parse string dates.
const TimeFormat = "2006-01-02T15:04"
// ValidateName ensures that the name is a valid format.
func ValidateName(name string) error {
if nameRegexp.Match([]byte(name)) == false {
if !nameRegexp.Match([]byte(name)) {
return ErrName
}
return nil

View file

@ -107,7 +107,6 @@ func TestStatsCount_TopN(t *testing.T) {
}
called = true
return
},
}
if _, err := e.Execute(context.Background(), "d", test.MustParse(`TopN(frame=f, n=2)`), nil, nil); err != nil {
@ -137,7 +136,6 @@ func TestStatsCount_Bitmap(t *testing.T) {
}
called = true
return
},
}
if _, err := e.Execute(context.Background(), "d", test.MustParse(`Bitmap(frame=f, row=0)`), nil, nil); err != nil {
@ -168,7 +166,6 @@ func TestStatsCount_SetBitmapAttrs(t *testing.T) {
t.Errorf("Expected SetBitmapAttrs, Results %s", name)
}
called = true
return
},
}
if _, err := e.Execute(context.Background(), "d", test.MustParse(`SetRowAttrs(row=10, frame=f, foo="bar")`), nil, nil); err != nil {
@ -200,7 +197,6 @@ func TestStatsCount_SetProfileAttrs(t *testing.T) {
}
called = true
return
},
}
if _, err := e.Execute(context.Background(), "d", test.MustParse(`SetColumnAttrs(col=10, frame=f, foo="bar")`), nil, nil); err != nil {
@ -225,7 +221,6 @@ func TestStatsCount_CreateIndex(t *testing.T) {
}
called = true
return
},
}
http.DefaultClient.Do(test.MustNewHTTPRequest("POST", s.URL+"/index/i", nil))
@ -254,7 +249,6 @@ func TestStatsCount_DeleteIndex(t *testing.T) {
}
called = true
return
},
}
http.DefaultClient.Do(test.MustNewHTTPRequest("DELETE", s.URL+"/index/i", strings.NewReader("")))
@ -286,7 +280,6 @@ func TestStatsCount_CreateFrame(t *testing.T) {
}
called = true
return
},
}
http.DefaultClient.Do(test.MustNewHTTPRequest("POST", s.URL+"/index/i/frame/f", nil))
@ -318,7 +311,6 @@ func TestStatsCount_DeleteFrame(t *testing.T) {
}
called = true
return
},
}
http.DefaultClient.Do(test.MustNewHTTPRequest("DELETE", s.URL+"/index/i/frame/f", strings.NewReader("")))
@ -335,17 +327,13 @@ type MockStats struct {
func (s *MockStats) Count(name string, value int64, rate float64) {
if s.mockCount != nil {
s.mockCount(name, value, rate)
return
}
return
}
func (s *MockStats) CountWithCustomTags(name string, value int64, rate float64, tags []string) {
if s.mockCountWithTags != nil {
s.mockCountWithTags(name, value, rate, tags)
return
}
return
}
func (c *MockStats) Tags() []string { return nil }

View file

@ -160,12 +160,6 @@ func MustParseTime(value string) time.Time {
return v
}
// MustParseTimePtr parses value using DefaultTimeLayout. Panic on error.
func MustParseTimePtr(value string) *time.Time {
v := MustParseTime(value)
return &v
}
// MustParseTimeQuantum parses v into a time quantum. Panic on error.
func MustParseTimeQuantum(v string) pilosa.TimeQuantum {
q, err := pilosa.ParseTimeQuantum(v)

26
uri.go
View file

@ -26,8 +26,8 @@ import (
)
var schemeRegexp = regexp.MustCompile("^[+a-z]+$")
var hostRegexp = regexp.MustCompile("^[0-9a-z.-]+$|^\\[[:0-9a-fA-F]+\\]$")
var addressRegexp = regexp.MustCompile("^(([+a-z]+):\\/\\/)?([0-9a-z.-]+|\\[[:0-9a-fA-F]+\\])?(:([0-9]+))?$")
var hostRegexp = regexp.MustCompile(`^[0-9a-z.-]+$|^\[[:0-9a-fA-F]+\]$`)
var addressRegexp = regexp.MustCompile(`^(([+a-z]+):\/\/)?([0-9a-z.-]+|\[[:0-9a-fA-F]+\])?(:([0-9]+))?$`)
// URI represents a Pilosa URI.
// A Pilosa URI consists of three parts:
@ -234,28 +234,6 @@ func decodeURI(i *internal.URI) URI {
}
}
func encodeURIs(a []URI) []*internal.URI {
if len(a) == 0 {
return nil
}
other := make([]*internal.URI, len(a))
for i := range a {
other[i] = encodeURI(a[i])
}
return other
}
func decodeURIs(a []*internal.URI) []URI {
if len(a) == 0 {
return nil
}
other := make([]URI, len(a))
for i := range a {
other[i] = decodeURI(a[i])
}
return other
}
// MarshalJSON marshals URI into a JSON-encoded byte slice.
func (u *URI) MarshalJSON() ([]byte, error) {
var output struct {

View file

@ -417,9 +417,5 @@ func (t *ClusterCluster) FollowResizeInstruction(instr *internal.ResizeInstructi
}
node := DecodeNode(instr.Coordinator)
if err := t.SendTo(node, complete); err != nil {
return err
}
return nil
return t.SendTo(node, complete)
}

View file

@ -433,12 +433,6 @@ func IsInverseView(name string) bool {
return strings.HasPrefix(name, ViewInverse)
}
type viewSlice []*View
func (p viewSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p viewSlice) Len() int { return len(p) }
func (p viewSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() }
// ViewInfo represents schema information for a view.
type ViewInfo struct {
Name string `json:"name"`

View file

@ -69,10 +69,7 @@ func (v *View) Reopen() error {
v.View = pilosa.NewView(path, v.Index(), v.Frame(), v.Name(), pilosa.DefaultCacheSize)
v.View.RowAttrStore = v.RowAttrStore
if err := v.Open(); err != nil {
return err
}
return nil
return v.Open()
}
// MustSetBits sets bits on a row. Panic on error.