Skip to content

Commit

Permalink
Add the standard of golangci-lint
Browse files Browse the repository at this point in the history
Signed-off-by: cai.zhang <[email protected]>
  • Loading branch information
xiaocai2333 authored and yefu.chen committed Nov 12, 2020
1 parent 4a11a64 commit 1cd2fd9
Show file tree
Hide file tree
Showing 65 changed files with 909 additions and 1,444 deletions.
11 changes: 10 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ run:

linters-settings:
golint:
min-confidence: 0
min-confidence: 0.8

misspell:
locale: US
Expand All @@ -25,6 +25,15 @@ linters:
- ineffassign
- gosimple

issues:
exclude-use-default: false
exclude:
- should have a package comment
- should have comment
- should be of the form
- should not use dot imports
- which can be annoying to use
- AllocId
service:
golangci-lint-version: 1.27.0 # use the fixed version to not introduce new linters unexpectedly

3 changes: 2 additions & 1 deletion cmd/mock/master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"os/signal"
"syscall"

mockmaster "github.com/zilliztech/milvus-distributed/internal/master/mock"
"go.uber.org/zap"

mockmaster "github.com/zilliztech/milvus-distributed/internal/master/mock"
)

func main() {
Expand Down
2 changes: 2 additions & 0 deletions cmd/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

var yamlFile string
flag.StringVar(&yamlFile, "yaml", "", "yaml file")
flag.Parse()
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/protocolbuffers/protobuf v3.13.0+incompatible h1:omZA3Tuq+U2kJ2uMuqMR9c1VO5qLEgZ19m9878fXNtg=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
5 changes: 3 additions & 2 deletions internal/allocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type Allocator struct {
masterAddress string
masterConn *grpc.ClientConn
masterClient masterpb.MasterClient
countPerRpc uint32
countPerRPC uint32

tChan tickerChan
syncFunc func()
Expand All @@ -135,7 +135,8 @@ func (ta *Allocator) Start() error {

func (ta *Allocator) connectMaster() error {
log.Printf("Connected to master, master_addr=%s", ta.masterAddress)
ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
conn, err := grpc.DialContext(ctx, ta.masterAddress, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Printf("Connect to master failed, error= %v", err)
Expand Down
24 changes: 12 additions & 12 deletions internal/allocator/id_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,62 @@ import (

type UniqueID = typeutil.UniqueID

type IdAllocator struct {
type IDAllocator struct {
Allocator

idStart UniqueID
idEnd UniqueID
}

func NewIdAllocator(ctx context.Context) (*IdAllocator, error) {
func NewIDAllocator(ctx context.Context) (*IDAllocator, error) {
ctx1, cancel := context.WithCancel(ctx)
a := &IdAllocator{
a := &IDAllocator{
Allocator: Allocator{reqs: make(chan request, maxMergeRequests),
ctx: ctx1,
cancel: cancel,
},
}
a.tChan = &emptyTicker{}
a.Allocator.syncFunc = a.syncId
a.Allocator.syncFunc = a.syncID
a.Allocator.processFunc = a.processFunc
return a, nil
}

func (ta *IdAllocator) syncId() {
fmt.Println("syncId")
func (ta *IDAllocator) syncID() {
fmt.Println("syncID")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
req := &internalpb.IdRequest{
PeerId: 1,
Role: internalpb.PeerRole_Proxy,
Count: ta.countPerRpc,
Count: ta.countPerRPC,
}
resp, err := ta.masterClient.AllocId(ctx, req)

cancel()
if err != nil {
log.Panic("syncId Failed!!!!!")
log.Panic("syncID Failed!!!!!")
return
}
ta.idStart = resp.GetId()
ta.idEnd = ta.idStart + int64(resp.GetCount())

}

func (ta *IdAllocator) processFunc(req request) {
func (ta *IDAllocator) processFunc(req request) {
idRequest := req.(*idRequest)
idRequest.id = 1
fmt.Println("process Id")
fmt.Println("process ID")
}

func (ta *IdAllocator) AllocOne() (UniqueID, error) {
func (ta *IDAllocator) AllocOne() (UniqueID, error) {
ret, _, err := ta.Alloc(1)
if err != nil {
return 0, err
}
return ret, nil
}

func (ta *IdAllocator) Alloc(count uint32) (UniqueID, UniqueID, error) {
func (ta *IDAllocator) Alloc(count uint32) (UniqueID, UniqueID, error) {
req := &idRequest{baseRequest: baseRequest{done: make(chan error), valid: false}}

req.count = count
Expand Down
4 changes: 2 additions & 2 deletions internal/allocator/timestamp_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func (ta *TimestampAllocator) syncTs() {
req := &internalpb.TsoRequest{
PeerId: 1,
Role: internalpb.PeerRole_Proxy,
Count: ta.countPerRpc,
Count: ta.countPerRPC,
}
resp, err := ta.masterClient.AllocTimestamp(ctx, req)

cancel()
if err != nil {
log.Panic("syncId Failed!!!!!")
log.Panic("syncID Failed!!!!!")
return
}
ta.lastTsBegin = resp.GetTimestamp()
Expand Down
10 changes: 5 additions & 5 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type MasterConfig struct {
PulsarMoniterInterval int32
PulsarTopic string
SegmentThreshole float32
ProxyIdList []UniqueID
ProxyIDList []UniqueID
QueryNodeNum int
WriteNodeNum int
}
Expand Down Expand Up @@ -56,7 +56,7 @@ type PulsarConfig struct {

type ProxyConfig struct {
Timezone string `yaml:"timezone"`
ProxyId int `yaml:"proxy_id"`
ProxyID int `yaml:"proxy_id"`
NumReaderNodes int `yaml:"numReaderNodes"`
TosSaveInterval int `yaml:"tsoSaveInterval"`
TimeTickInterval int `yaml:"timeTickInterval"`
Expand Down Expand Up @@ -87,7 +87,7 @@ type ProxyConfig struct {
}

type Reader struct {
ClientId int
ClientID int
StopFlag int64
ReaderQueueSize int
SearchChanSize int
Expand All @@ -97,10 +97,10 @@ type Reader struct {
}

type Writer struct {
ClientId int
ClientID int
StopFlag int64
ReaderQueueSize int
SearchByIdChanSize int
SearchByIDChanSize int
Parallelism int
TopicStart int
TopicEnd int
Expand Down
36 changes: 24 additions & 12 deletions internal/kv/etcd_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func (kv *EtcdKV) Close() {
func (kv *EtcdKV) LoadWithPrefix(key string) ([]string, []string, error) {
key = path.Join(kv.rootPath, key)
log.Printf("LoadWithPrefix %s", key)
ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()
resp, err := kv.client.Get(ctx, key, clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortAscend))
if err != nil {
return nil, nil, err
Expand All @@ -50,7 +51,8 @@ func (kv *EtcdKV) LoadWithPrefix(key string) ([]string, []string, error) {

func (kv *EtcdKV) Load(key string) (string, error) {
key = path.Join(kv.rootPath, key)
ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()
resp, err := kv.client.Get(ctx, key)
if err != nil {
return "", err
Expand All @@ -64,11 +66,12 @@ func (kv *EtcdKV) Load(key string) (string, error) {

func (kv *EtcdKV) MultiLoad(keys []string) ([]string, error) {
ops := make([]clientv3.Op, 0, len(keys))
for _, key_load := range keys {
ops = append(ops, clientv3.OpGet(path.Join(kv.rootPath, key_load)))
for _, keyLoad := range keys {
ops = append(ops, clientv3.OpGet(path.Join(kv.rootPath, keyLoad)))
}

ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()
resp, err := kv.client.Txn(ctx).If().Then(ops...).Commit()
if err != nil {
return []string{}, err
Expand Down Expand Up @@ -96,7 +99,8 @@ func (kv *EtcdKV) MultiLoad(keys []string) ([]string, error) {

func (kv *EtcdKV) Save(key, value string) error {
key = path.Join(kv.rootPath, key)
ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()
_, err := kv.client.Put(ctx, key, value)
return err
}
Expand All @@ -107,14 +111,18 @@ func (kv *EtcdKV) MultiSave(kvs map[string]string) error {
ops = append(ops, clientv3.OpPut(path.Join(kv.rootPath, key), value))
}

ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()

_, err := kv.client.Txn(ctx).If().Then(ops...).Commit()
return err
}

func (kv *EtcdKV) Remove(key string) error {
key = path.Join(kv.rootPath, key)
ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()

_, err := kv.client.Delete(ctx, key)
return err
}
Expand All @@ -125,7 +133,9 @@ func (kv *EtcdKV) MultiRemove(keys []string) error {
ops = append(ops, clientv3.OpDelete(path.Join(kv.rootPath, key)))
}

ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()

_, err := kv.client.Txn(ctx).If().Then(ops...).Commit()
return err
}
Expand All @@ -136,12 +146,14 @@ func (kv *EtcdKV) MultiSaveAndRemove(saves map[string]string, removals []string)
ops = append(ops, clientv3.OpPut(path.Join(kv.rootPath, key), value))
}

for _, key_delete := range removals {
ops = append(ops, clientv3.OpDelete(path.Join(kv.rootPath, key_delete)))
for _, keyDelete := range removals {
ops = append(ops, clientv3.OpDelete(path.Join(kv.rootPath, keyDelete)))
}

log.Printf("MultiSaveAndRemove")
ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()

_, err := kv.client.Txn(ctx).If().Then(ops...).Commit()
return err
}
Expand Down
13 changes: 8 additions & 5 deletions internal/kv/etcd_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func TestEtcdKV_Load(t *testing.T) {
assert.Nil(t, err)
rootpath := "/etcd/test/root"
kv := NewEtcdKV(cli, rootpath)
ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()

defer kv.Close()
defer kv.client.Delete(ctx, rootpath, clientv3.WithPrefix())
Expand Down Expand Up @@ -67,7 +68,8 @@ func TestEtcdKV_MultiSave(t *testing.T) {
assert.Nil(t, err)
rootpath := "/etcd/test/root"
kv := NewEtcdKV(cli, rootpath)
ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()

defer kv.Close()
defer kv.client.Delete(ctx, rootpath, clientv3.WithPrefix())
Expand All @@ -93,7 +95,8 @@ func TestEtcdKV_Remove(t *testing.T) {
assert.Nil(t, err)
rootpath := "/etcd/test/root"
kv := NewEtcdKV(cli, rootpath)
ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)
ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()

defer kv.Close()
defer kv.client.Delete(ctx, rootpath, clientv3.WithPrefix())
Expand Down Expand Up @@ -159,8 +162,8 @@ func TestEtcdKV_MultiSaveAndRemove(t *testing.T) {
assert.Nil(t, err)
rootpath := "/etcd/test/root"
kv := NewEtcdKV(cli, rootpath)
ctx, _ := context.WithTimeout(context.TODO(), requestTimeout)

ctx, cancel := context.WithTimeout(context.TODO(), requestTimeout)
defer cancel()
defer kv.Close()
defer kv.client.Delete(ctx, rootpath, clientv3.WithPrefix())

Expand Down
2 changes: 1 addition & 1 deletion internal/kv/kv.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kv

type KVBase interface {
type Base interface {
Load(key string) (string, error)
MultiLoad(keys []string) ([]string, error)
LoadWithPrefix(key string) ([]string, []string, error)
Expand Down
Loading

0 comments on commit 1cd2fd9

Please sign in to comment.