Skip to content

Commit

Permalink
chore(*): enable prealloc & predel linters (#395)
Browse files Browse the repository at this point in the history
开启 prealloc、predeclared

Signed-off-by: Soren Yang <[email protected]>
  • Loading branch information
lsytj0413 authored Dec 4, 2023
1 parent 7e9e938 commit 11f8547
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ linters:
# - nilnil
# - noctx
- nolintlint
# - prealloc
# - predeclared
- prealloc
- predeclared
- promlinter
# - reassign
- rowserrcheck
Expand Down
4 changes: 2 additions & 2 deletions cmd/client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"

"github.com/streamnative/oxia/cmd/client/common"
"github.com/streamnative/oxia/cmd/client/delete"
"github.com/streamnative/oxia/cmd/client/del"
"github.com/streamnative/oxia/cmd/client/get"
"github.com/streamnative/oxia/cmd/client/list"
"github.com/streamnative/oxia/cmd/client/notifications"
Expand All @@ -46,7 +46,7 @@ func init() {
Cmd.PersistentFlags().DurationVar(&common.Config.RequestTimeout, "request-timeout", oxia.DefaultRequestTimeout, "Requests timeout")

Cmd.AddCommand(put.Cmd)
Cmd.AddCommand(delete.Cmd)
Cmd.AddCommand(del.Cmd)
Cmd.AddCommand(get.Cmd)
Cmd.AddCommand(list.Cmd)
Cmd.AddCommand(notifications.Cmd)
Expand Down
6 changes: 3 additions & 3 deletions cmd/client/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/streamnative/oxia/cmd/client/delete"
"github.com/streamnative/oxia/cmd/client/del"
"github.com/streamnative/oxia/cmd/client/get"
"github.com/streamnative/oxia/cmd/client/list"
"github.com/streamnative/oxia/cmd/client/put"
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestClientCmd(t *testing.T) {
"\\{\\}",
"^$",
},
{"delete-range-with-expected", []string{"delete", "--key-min", "q", "--key-max", "s", "-e", "0"}, "", delete.ErrExpectedVersionInconsistent,
{"delete-range-with-expected", []string{"delete", "--key-min", "q", "--key-max", "s", "-e", "0"}, "", del.ErrExpectedVersionInconsistent,
".*",
"Error: inconsistent flags; zero or all keys must have an expected version",
},
Expand All @@ -182,7 +182,7 @@ func TestClientCmd(t *testing.T) {
put.Config.Reset()
get.Config.Reset()
list.Config.Reset()
delete.Config.Reset()
del.Config.Reset()

stdin.WriteString(test.stdin)
Cmd.SetArgs(append([]string{"-a", serviceAddress}, test.args...))
Expand Down
2 changes: 1 addition & 1 deletion cmd/client/delete/cmd.go → cmd/client/del/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package delete
package del

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package delete
package del

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion common/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
// DoWithLabels attaches the labels to the current go-routine Pprof context,
// for the duration of the call to f.
func DoWithLabels(labels map[string]string, f func()) {
var l []string
l := make([]string, 0, len(labels)*2)
for k, v := range labels {
l = append(l, k, v)
}
Expand Down
2 changes: 1 addition & 1 deletion coordinator/impl/cluster_rebalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func getServerRanking(shardsPerServer map[model.ServerAddress]common.Set[int64])
}

func getFirstEntry(m map[model.ServerAddress]common.Set[int64]) (model.ServerAddress, common.Set[int64]) {
var keys []model.ServerAddress
keys := make([]model.ServerAddress, 0, len(m))
for k := range m {
keys = append(keys, k)
}
Expand Down
6 changes: 3 additions & 3 deletions coordinator/impl/shard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,14 +791,14 @@ func mergeLists[T any](lists ...[]T) []T {
return res
}

func replaceInList(list []model.ServerAddress, old, new model.ServerAddress) []model.ServerAddress {
func replaceInList(list []model.ServerAddress, oldServerAddress, newServerAddress model.ServerAddress) []model.ServerAddress {
var res []model.ServerAddress
for _, item := range list {
if item.Public != old.Public && item.Internal != old.Internal {
if item.Public != oldServerAddress.Public && item.Internal != oldServerAddress.Internal {
res = append(res, item)
}
}

res = append(res, new)
res = append(res, newServerAddress)
return res
}
8 changes: 4 additions & 4 deletions oxia/internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ func (m *Metrics) DecoratePut(put model.PutCall) model.PutCall {
return put
}

func (m *Metrics) DecorateDelete(delete model.DeleteCall) model.DeleteCall {
callback := delete.Callback
func (m *Metrics) DecorateDelete(deleteCall model.DeleteCall) model.DeleteCall {
callback := deleteCall.Callback
metricContext := m.metricContextFunc("delete")
delete.Callback = func(response *proto.DeleteResponse, err error) {
deleteCall.Callback = func(response *proto.DeleteResponse, err error) {
callback(response, err)
ctx, start, _attrs := metricContext(err)
m.opTime.Record(ctx, m.sinceFunc(start), _attrs)
}
return delete
return deleteCall
}

func (m *Metrics) DecorateDeleteRange(deleteRange model.DeleteRangeCall) model.DeleteRangeCall {
Expand Down
6 changes: 3 additions & 3 deletions server/wal/wal_rw_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ReadWriteSegment interface {

Truncate(lastSafeOffset int64) error

HasSpace(len int) bool
HasSpace(l int) bool

Flush() error
}
Expand Down Expand Up @@ -121,8 +121,8 @@ func (ms *readWriteSegment) Read(offset int64) ([]byte, error) {
return entry, nil
}

func (ms *readWriteSegment) HasSpace(len int) bool {
return ms.currentFileOffset+4+uint32(len) <= ms.segmentSize
func (ms *readWriteSegment) HasSpace(l int) bool {
return ms.currentFileOffset+4+uint32(l) <= ms.segmentSize
}

func (ms *readWriteSegment) Append(offset int64, data []byte) error {
Expand Down

0 comments on commit 11f8547

Please sign in to comment.