diff --git a/Makefile b/Makefile index 790eaaf91..b3511b890 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ docker-test: docker run --rm -v $(PWD):/go/src/$(CLONE_URL) -w /go/src/$(CLONE_URL) golang:$(GO_VERSION) go test -tags='$(BUILD_TAGS)' $(TESTFLAGS) ./... metalinter: - gometalinter --vendor --disable-all --enable=gotype --enable=gotypex --enable=gofmt --enable=goimports --deadline=60s --exclude "^internal/.*\.pb\.go" ./... + gometalinter --vendor --disable-all --enable=gotype --enable=gotypex --enable=gofmt --enable=goimports --enable=unparam --deadline=60s --exclude "^internal/.*\.pb\.go" ./... ###################### # Build dependencies # diff --git a/api.go b/api.go index 5dc7181d2..afb0e2379 100644 --- a/api.go +++ b/api.go @@ -174,7 +174,7 @@ func (api *API) readColumnAttrSets(index *Index, ids []uint64) ([]*ColumnAttrSet } // CreateIndex makes a new Pilosa index. -func (api *API) CreateIndex(ctx context.Context, indexName string, options IndexOptions) (*Index, error) { +func (api *API) CreateIndex(_ context.Context, indexName string, options IndexOptions) (*Index, error) { if err := api.validate(apiCreateIndex); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -198,7 +198,7 @@ func (api *API) CreateIndex(ctx context.Context, indexName string, options Index } // Index retrieves the named index. -func (api *API) Index(ctx context.Context, indexName string) (*Index, error) { +func (api *API) Index(_ context.Context, indexName string) (*Index, error) { if err := api.validate(apiIndex); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -212,7 +212,7 @@ func (api *API) Index(ctx context.Context, indexName string) (*Index, error) { // DeleteIndex removes the named index. If the index is not found it does // nothing and returns no error. -func (api *API) DeleteIndex(ctx context.Context, indexName string) error { +func (api *API) DeleteIndex(_ context.Context, indexName string) error { if err := api.validate(apiDeleteIndex); err != nil { return errors.Wrap(err, "validating api method") } @@ -238,7 +238,7 @@ func (api *API) DeleteIndex(ctx context.Context, indexName string) error { // CreateField makes the named field in the named index with the given options. // This method currently only takes a single functional option, but that may be // changed in the future to support multiple options. -func (api *API) CreateField(ctx context.Context, indexName string, fieldName string, opts ...FieldOption) (*Field, error) { +func (api *API) CreateField(_ context.Context, indexName string, fieldName string, opts ...FieldOption) (*Field, error) { if err := api.validate(apiCreateField); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -280,7 +280,7 @@ func (api *API) CreateField(ctx context.Context, indexName string, fieldName str } // Field retrieves the named field. -func (api *API) Field(ctx context.Context, indexName, fieldName string) (*Field, error) { +func (api *API) Field(_ context.Context, indexName, fieldName string) (*Field, error) { if err := api.validate(apiField); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -295,7 +295,7 @@ func (api *API) Field(ctx context.Context, indexName, fieldName string) (*Field, // DeleteField removes the named field from the named index. If the index is not // found, an error is returned. If the field is not found, it is ignored and no // action is taken. -func (api *API) DeleteField(ctx context.Context, indexName string, fieldName string) error { +func (api *API) DeleteField(_ context.Context, indexName string, fieldName string) error { if err := api.validate(apiDeleteField); err != nil { return errors.Wrap(err, "validating api method") } @@ -327,7 +327,7 @@ func (api *API) DeleteField(ctx context.Context, indexName string, fieldName str // ExportCSV encodes the fragment designated by the index,field,shard as // CSV of the form , -func (api *API) ExportCSV(ctx context.Context, indexName string, fieldName string, shard uint64, w io.Writer) error { +func (api *API) ExportCSV(_ context.Context, indexName string, fieldName string, shard uint64, w io.Writer) error { if err := api.validate(apiExportCSV); err != nil { return errors.Wrap(err, "validating api method") } @@ -364,7 +364,7 @@ func (api *API) ExportCSV(ctx context.Context, indexName string, fieldName strin } // ShardNodes returns the node and all replicas which should contain a shard's data. -func (api *API) ShardNodes(ctx context.Context, indexName string, shard uint64) ([]*Node, error) { +func (api *API) ShardNodes(_ context.Context, indexName string, shard uint64) ([]*Node, error) { if err := api.validate(apiShardNodes); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -375,7 +375,7 @@ func (api *API) ShardNodes(ctx context.Context, indexName string, shard uint64) // FragmentBlockData is an endpoint for internal usage. It is not guaranteed to // return anything useful. Currently it returns protobuf encoded row and column // ids from a "block" which is a subdivision of a fragment. -func (api *API) FragmentBlockData(ctx context.Context, body io.Reader) ([]byte, error) { +func (api *API) FragmentBlockData(_ context.Context, body io.Reader) ([]byte, error) { if err := api.validate(apiFragmentBlockData); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -408,7 +408,7 @@ func (api *API) FragmentBlockData(ctx context.Context, body io.Reader) ([]byte, } // FragmentBlocks returns the checksums and block ids for all blocks in the specified fragment. -func (api *API) FragmentBlocks(ctx context.Context, indexName string, fieldName string, shard uint64) ([]FragmentBlock, error) { +func (api *API) FragmentBlocks(_ context.Context, indexName string, fieldName string, shard uint64) ([]FragmentBlock, error) { if err := api.validate(apiFragmentBlocks); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -426,7 +426,7 @@ func (api *API) FragmentBlocks(ctx context.Context, indexName string, fieldName // Hosts returns a list of the hosts in the cluster including their ID, // URL, and which is the coordinator. -func (api *API) Hosts(ctx context.Context) []*Node { +func (api *API) Hosts(_ context.Context) []*Node { return api.cluster.Nodes } @@ -437,7 +437,7 @@ func (api *API) Node() *Node { } // RecalculateCaches forces all TopN caches to be updated. Used mainly for integration tests. -func (api *API) RecalculateCaches(ctx context.Context) error { +func (api *API) RecalculateCaches(_ context.Context) error { if err := api.validate(apiRecalculateCaches); err != nil { return errors.Wrap(err, "validating api method") } @@ -452,7 +452,7 @@ func (api *API) RecalculateCaches(ctx context.Context) error { // PostClusterMessage is for internal use. It decodes a protobuf message out of // the body and forwards it to the BroadcastHandler. -func (api *API) ClusterMessage(ctx context.Context, reqBody io.Reader) error { +func (api *API) ClusterMessage(_ context.Context, reqBody io.Reader) error { if err := api.validate(apiClusterMessage); err != nil { return errors.Wrap(err, "validating api method") } @@ -479,12 +479,12 @@ func (api *API) ClusterMessage(ctx context.Context, reqBody io.Reader) error { // Schema returns information about each index in Pilosa including which fields // they contain. -func (api *API) Schema(ctx context.Context) []*IndexInfo { +func (api *API) Schema(_ context.Context) []*IndexInfo { return api.holder.limitedSchema() } // Views returns the views in the given field. -func (api *API) Views(ctx context.Context, indexName string, fieldName string) ([]*view, error) { +func (api *API) Views(_ context.Context, indexName string, fieldName string) ([]*view, error) { if err := api.validate(apiViews); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -501,7 +501,7 @@ func (api *API) Views(ctx context.Context, indexName string, fieldName string) ( } // DeleteView removes the given view. -func (api *API) DeleteView(ctx context.Context, indexName string, fieldName string, viewName string) error { +func (api *API) DeleteView(_ context.Context, indexName string, fieldName string, viewName string) error { if err := api.validate(apiDeleteView); err != nil { return errors.Wrap(err, "validating api method") } @@ -535,7 +535,7 @@ func (api *API) DeleteView(ctx context.Context, indexName string, fieldName stri } // IndexAttrDiff -func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { +func (api *API) IndexAttrDiff(_ context.Context, indexName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { if err := api.validate(apiIndexAttrDiff); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -569,7 +569,7 @@ func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []At return attrs, nil } -func (api *API) FieldAttrDiff(ctx context.Context, indexName string, fieldName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { +func (api *API) FieldAttrDiff(_ context.Context, indexName string, fieldName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { if err := api.validate(apiFieldAttrDiff); err != nil { return nil, errors.Wrap(err, "validating api method") } @@ -604,12 +604,12 @@ func (api *API) FieldAttrDiff(ctx context.Context, indexName string, fieldName s } // Import bulk imports data into a particular index,field,shard. -func (api *API) Import(ctx context.Context, req *ImportRequest) error { +func (api *API) Import(_ context.Context, req *ImportRequest) error { if err := api.validate(apiImport); err != nil { return errors.Wrap(err, "validating api method") } - _, field, err := api.indexField(req.Index, req.Field, req.Shard) + field, err := api.indexField(req.Index, req.Field, req.Shard) if err != nil { return errors.Wrap(err, "getting field") } @@ -633,12 +633,12 @@ func (api *API) Import(ctx context.Context, req *ImportRequest) error { } // ImportValue bulk imports values into a particular field. -func (api *API) ImportValue(ctx context.Context, req *ImportValueRequest) error { +func (api *API) ImportValue(_ context.Context, req *ImportValueRequest) error { if err := api.validate(apiImportValue); err != nil { return errors.Wrap(err, "validating api method") } - _, field, err := api.indexField(req.Index, req.Field, req.Shard) + field, err := api.indexField(req.Index, req.Field, req.Shard) if err != nil { return errors.Wrap(err, "getting field") } @@ -651,7 +651,7 @@ func (api *API) ImportValue(ctx context.Context, req *ImportValueRequest) error } // MaxShards returns the maximum shard number for each index in a map. -func (api *API) MaxShards(ctx context.Context) map[string]uint64 { +func (api *API) MaxShards(_ context.Context) map[string]uint64 { return api.holder.maxShards() } @@ -673,11 +673,11 @@ func (api *API) LongQueryTime() time.Duration { return api.cluster.longQueryTime } -func (api *API) indexField(indexName string, fieldName string, shard uint64) (*Index, *Field, error) { +func (api *API) indexField(indexName string, fieldName string, shard uint64) (*Field, error) { // Validate that this handler owns the shard. if !api.cluster.ownsShard(api.Node().ID, indexName, shard) { api.server.logger.Printf("node %s does not own shard %d of index %s", api.Node().ID, shard, indexName) - return nil, nil, ErrClusterDoesNotOwnShard + return nil, ErrClusterDoesNotOwnShard } // Find the Index. @@ -685,20 +685,20 @@ func (api *API) indexField(indexName string, fieldName string, shard uint64) (*I index := api.holder.Index(indexName) if index == nil { api.server.logger.Printf("fragment error: index=%s, field=%s, shard=%d, err=%s", indexName, fieldName, shard, ErrIndexNotFound.Error()) - return nil, nil, newNotFoundError(ErrIndexNotFound) + return nil, newNotFoundError(ErrIndexNotFound) } // Retrieve field. field := index.Field(fieldName) if field == nil { api.server.logger.Printf("field error: index=%s, field=%s, shard=%d, err=%s", indexName, fieldName, shard, ErrFieldNotFound.Error()) - return nil, nil, ErrFieldNotFound + return nil, ErrFieldNotFound } - return index, field, nil + return field, nil } // SetCoordinator makes a new Node the cluster coordinator. -func (api *API) SetCoordinator(ctx context.Context, id string) (oldNode, newNode *Node, err error) { +func (api *API) SetCoordinator(_ context.Context, id string) (oldNode, newNode *Node, err error) { if err := api.validate(apiSetCoordinator); err != nil { return nil, nil, errors.Wrap(err, "validating api method") } diff --git a/boltdb/attrstore.go b/boltdb/attrstore.go index 1a9ddcf6e..423abcc36 100644 --- a/boltdb/attrstore.go +++ b/boltdb/attrstore.go @@ -412,7 +412,7 @@ type blockCursor struct { } // newBlockCursor returns a new block cursor that wraps cur using n sized blocks. -func newBlockCursor(c *bolt.Cursor, n int) blockCursor { +func newBlockCursor(c *bolt.Cursor, n int) blockCursor { // nolint: unparam cur := blockCursor{ cur: c, n: uint64(n), diff --git a/cluster.go b/cluster.go index a36b2c92e..6699a5e56 100644 --- a/cluster.go +++ b/cluster.go @@ -282,7 +282,7 @@ func (c *cluster) setCoordinator(n *Node) error { // changing the corresponding node's IsCoordinator value // to true, and sets all other nodes to false. Returns true if the value // changed. -func (c *cluster) updateCoordinator(n *Node) bool { +func (c *cluster) updateCoordinator(n *Node) bool { // nolint: unparam c.mu.Lock() defer c.mu.Unlock() return c.unprotectedUpdateCoordinator(n) @@ -416,7 +416,7 @@ func (c *cluster) setState(state string) { } } -func (c *cluster) setNodeState(state string) error { +func (c *cluster) setNodeState(state string) error { // nolint: unparam if c.isCoordinator() { return c.receiveNodeState(c.Node.ID, state) } diff --git a/cmd/root.go b/cmd/root.go index c3d5ca1bb..fd55cbcef 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -86,7 +86,7 @@ Build Time: ` + pilosa.BuildTime + "\n", // setAllConfig looks for environment variables which are capitalized versions // of the flag names with dashes replaced by underscores, and prefixed with // envPrefix plus an underscore. -func setAllConfig(v *viper.Viper, flags *pflag.FlagSet, envPrefix string) error { +func setAllConfig(v *viper.Viper, flags *pflag.FlagSet, envPrefix string) error { // nolint: unparam // add cmd line flag def to viper err := v.BindPFlags(flags) if err != nil { diff --git a/ctl/check.go b/ctl/check.go index 04f947eb4..b1389b6ee 100644 --- a/ctl/check.go +++ b/ctl/check.go @@ -44,7 +44,7 @@ func NewCheckCommand(stdin io.Reader, stdout, stderr io.Writer) *CheckCommand { } // Run executes the check command. -func (cmd *CheckCommand) Run(ctx context.Context) error { +func (cmd *CheckCommand) Run(_ context.Context) error { for _, path := range cmd.Paths { switch filepath.Ext(path) { case "": diff --git a/ctl/config.go b/ctl/config.go index 7277f74ea..bb349c274 100644 --- a/ctl/config.go +++ b/ctl/config.go @@ -38,7 +38,7 @@ func NewConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *ConfigCommand } // Run prints out the default config. -func (cmd *ConfigCommand) Run(ctx context.Context) error { +func (cmd *ConfigCommand) Run(_ context.Context) error { buf, err := toml.Marshal(*cmd.Config) if err != nil { return err diff --git a/ctl/generate_config.go b/ctl/generate_config.go index a9429ec80..0e59ce097 100644 --- a/ctl/generate_config.go +++ b/ctl/generate_config.go @@ -38,7 +38,7 @@ func NewGenerateConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *Genera } // Run prints out the default config. -func (cmd *GenerateConfigCommand) Run(ctx context.Context) error { +func (cmd *GenerateConfigCommand) Run(_ context.Context) error { conf := server.NewConfig() ret, err := toml.Marshal(*conf) if err != nil { diff --git a/ctl/inspect.go b/ctl/inspect.go index 0c38c3fb5..c0676f8da 100644 --- a/ctl/inspect.go +++ b/ctl/inspect.go @@ -46,7 +46,7 @@ func NewInspectCommand(stdin io.Reader, stdout, stderr io.Writer) *InspectComman } // Run executes the inspect command. -func (cmd *InspectCommand) Run(ctx context.Context) error { +func (cmd *InspectCommand) Run(_ context.Context) error { // Open file handle. f, err := os.Open(cmd.Path) if err != nil { diff --git a/diagnostics.go b/diagnostics.go index 9649a6505..eb30a5916 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -57,7 +57,7 @@ type diagnosticsCollector struct { } // newDiagnosticsCollector returns a new DiagnosticsCollector given an addr in the format "hostname:port". -func newDiagnosticsCollector(host string) *diagnosticsCollector { +func newDiagnosticsCollector(host string) *diagnosticsCollector { // nolint: unparam return &diagnosticsCollector{ host: host, VersionURL: defaultVersionCheckURL, diff --git a/executor.go b/executor.go index b56001c7a..542ca56b5 100644 --- a/executor.go +++ b/executor.go @@ -665,7 +665,7 @@ func (e *executor) executeDifferenceShard(ctx context.Context, index string, c * return other, nil } -func (e *executor) executeBitmapShard(ctx context.Context, index string, c *pql.Call, shard uint64) (*Row, error) { +func (e *executor) executeBitmapShard(_ context.Context, index string, c *pql.Call, shard uint64) (*Row, error) { // Fetch column label from index. idx := e.Holder.Index(index) if idx == nil { @@ -793,7 +793,7 @@ func (e *executor) executeRangeShard(ctx context.Context, index string, c *pql.C } // executeBSIGroupRangeShard executes a range(bsiGroup) call for a local shard. -func (e *executor) executeBSIGroupRangeShard(ctx context.Context, index string, c *pql.Call, shard uint64) (*Row, error) { +func (e *executor) executeBSIGroupRangeShard(_ context.Context, index string, c *pql.Call, shard uint64) (*Row, error) { // Only one conditional should be present. if len(c.Args) == 0 { return nil, errors.New("Range(): condition required") @@ -1048,7 +1048,7 @@ func (e *executor) executeClearBitField(ctx context.Context, index string, c *pq } // Forward call to remote node otherwise. - if res, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil, opt); err != nil { + if res, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil); err != nil { return false, err } else { ret = res[0].(bool) @@ -1140,7 +1140,7 @@ func (e *executor) executeSetBitField(ctx context.Context, index string, c *pql. } // Forward call to remote node otherwise. - if res, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil, opt); err != nil { + if res, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil); err != nil { return false, err } else { ret = res[0].(bool) @@ -1172,7 +1172,7 @@ func (e *executor) executeSetValueField(ctx context.Context, index string, c *pq } // Forward call to remote node otherwise. - if res, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil, opt); err != nil { + if res, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil); err != nil { return false, err } else { ret = res[0].(bool) @@ -1223,7 +1223,7 @@ func (e *executor) executeSetRowAttrs(ctx context.Context, index string, c *pql. resp := make(chan error, len(nodes)) for _, node := range nodes { go func(node *Node) { - _, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil, opt) + _, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil) resp <- err }(node) } @@ -1309,7 +1309,7 @@ func (e *executor) executeBulkSetRowAttrs(ctx context.Context, index string, cal resp := make(chan error, len(nodes)) for _, node := range nodes { go func(node *Node) { - _, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: calls}, nil, opt) + _, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: calls}, nil) resp <- err }(node) } @@ -1358,7 +1358,7 @@ func (e *executor) executeSetColumnAttrs(ctx context.Context, index string, c *p resp := make(chan error, len(nodes)) for _, node := range nodes { go func(node *Node) { - _, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil, opt) + _, err := e.remoteExec(ctx, node, index, &pql.Query{Calls: []*pql.Call{c}}, nil) resp <- err }(node) } @@ -1374,7 +1374,7 @@ func (e *executor) executeSetColumnAttrs(ctx context.Context, index string, c *p } // exec executes a PQL query remotely for a set of shards on a node. -func (e *executor) remoteExec(ctx context.Context, node *Node, index string, q *pql.Query, shards []uint64, opt *execOptions) (results []interface{}, err error) { +func (e *executor) remoteExec(ctx context.Context, node *Node, index string, q *pql.Query, shards []uint64) (results []interface{}, err error) { // Encode request object. pbreq := &QueryRequest{ Query: q.String(), @@ -1487,7 +1487,7 @@ func (e *executor) mapper(ctx context.Context, ch chan mapResponse, nodes []*Nod if n.ID == e.Node.ID { resp.result, resp.err = e.mapperLocal(ctx, nodeShards, mapFn, reduceFn) } else if !opt.Remote { - results, err := e.remoteExec(ctx, n, index, &pql.Query{Calls: []*pql.Call{c}}, nodeShards, opt) + results, err := e.remoteExec(ctx, n, index, &pql.Query{Calls: []*pql.Call{c}}, nodeShards) if len(results) > 0 { resp.result = results[0] } diff --git a/fragment.go b/fragment.go index 6bfa9c4fd..835c1abe8 100644 --- a/fragment.go +++ b/fragment.go @@ -520,7 +520,7 @@ func (f *fragment) setValue(columnID uint64, bitDepth uint, value uint64) (chang } // importSetValue is a more efficient SetValue just for imports. -func (f *fragment) importSetValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { +func (f *fragment) importSetValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { // nolint: unparam for i := uint(0); i < bitDepth; i++ { if value&(1<= v { return i