From 405b3cd932bcb4b622d3560d4863488c9f1fbf27 Mon Sep 17 00:00:00 2001 From: Xiangyu Wang Date: Tue, 14 Dec 2021 15:31:07 +0800 Subject: [PATCH] Use the same lint rules with golint in revive (#13324) Signed-off-by: Xiangyu Wang --- .golangci.yml | 8 -------- internal/datacoord/channel_store.go | 2 +- internal/datacoord/meta.go | 4 ++-- internal/datacoord/segment_manager_test.go | 2 +- internal/datacoord/server_test.go | 2 +- internal/datanode/data_sync_service_test.go | 4 ++-- internal/datanode/flow_graph_insert_buffer_node.go | 4 ++-- internal/datanode/flush_task.go | 2 +- internal/datanode/segment_replica.go | 6 +++--- internal/indexcoord/index_coord.go | 6 +++--- internal/indexcoord/priority_queue.go | 2 +- internal/msgstream/mq_msgstream.go | 2 +- internal/proxy/task.go | 6 +++--- internal/querycoord/query_coord.go | 6 +++--- internal/querycoord/task_scheduler.go | 2 +- internal/querynode/query_collection.go | 6 +++--- internal/querynode/reduce_test.go | 2 +- internal/querynode/segment_test.go | 2 +- internal/rootcoord/meta_table.go | 2 +- internal/rootcoord/root_coord.go | 2 +- internal/rootcoord/root_coord_test.go | 2 +- internal/storage/binlog_writer.go | 2 +- internal/storage/vector_chunk_manager_test.go | 2 +- internal/util/distance/calc_distance.go | 8 ++++---- internal/util/distance/calc_distance_test.go | 4 ++-- internal/util/flowgraph/input_node_test.go | 2 +- internal/util/flowgraph/message_test.go | 2 +- internal/util/funcutil/func.go | 2 +- internal/util/funcutil/random.go | 2 +- internal/util/rocksmq/server/rocksmq/rocksmq_impl.go | 2 +- internal/util/rocksmq/server/rocksmq/rocksmq_impl_test.go | 8 ++++---- internal/util/rocksmq/server/rocksmq/rocksmq_retention.go | 8 ++++---- .../util/rocksmq/server/rocksmq/rocksmq_retention_test.go | 2 +- internal/util/sessionutil/session_util_test.go | 4 ++-- internal/util/typeutil/hash_test.go | 4 ++-- 35 files changed, 59 insertions(+), 67 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 9385e3c67c..28d085859c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,14 +11,6 @@ linters-settings: misspell: locale: US - revive: - ignore-generated-header: true - severity: warning - confidence: 0.8 - rules: - - name: context-as-argument - severity: warning - linters: disable-all: true enable: diff --git a/internal/datacoord/channel_store.go b/internal/datacoord/channel_store.go index 3ff4edad50..15366e96fd 100644 --- a/internal/datacoord/channel_store.go +++ b/internal/datacoord/channel_store.go @@ -35,7 +35,7 @@ const ( maxOperationsPerTxn = 128 ) -var errUnknownOpType error = errors.New("unknown operation type") +var errUnknownOpType = errors.New("unknown operation type") // ChannelOpType type alias uses int8 stands for Channel operation type type ChannelOpType int8 diff --git a/internal/datacoord/meta.go b/internal/datacoord/meta.go index 15bf00f333..5490e1bb2e 100644 --- a/internal/datacoord/meta.go +++ b/internal/datacoord/meta.go @@ -142,7 +142,7 @@ func (m *meta) GetSegmentsChanPart(selector SegmentInfoSelector) []*chanPartSegm func (m *meta) GetNumRowsOfCollection(collectionID UniqueID) int64 { m.RLock() defer m.RUnlock() - var ret int64 = 0 + var ret int64 segments := m.segments.GetSegments() for _, segment := range segments { if isSegmentHealthy(segment) && segment.GetCollectionID() == collectionID { @@ -595,7 +595,7 @@ func (m *meta) GetSegmentsIDOfPartition(collectionID, partitionID UniqueID) []Un func (m *meta) GetNumRowsOfPartition(collectionID UniqueID, partitionID UniqueID) int64 { m.RLock() defer m.RUnlock() - var ret int64 = 0 + var ret int64 segments := m.segments.GetSegments() for _, segment := range segments { if isSegmentHealthy(segment) && segment.CollectionID == collectionID && segment.PartitionID == partitionID { diff --git a/internal/datacoord/segment_manager_test.go b/internal/datacoord/segment_manager_test.go index 188e94a2c1..91aaee18aa 100644 --- a/internal/datacoord/segment_manager_test.go +++ b/internal/datacoord/segment_manager_test.go @@ -468,7 +468,7 @@ func TestAllocationPool(t *testing.T) { }) t.Run("put nil", func(t *testing.T) { - var allo *Allocation = nil + var allo *Allocation allocPool = sync.Pool{ New: func() interface{} { return &Allocation{} diff --git a/internal/datacoord/server_test.go b/internal/datacoord/server_test.go index 6c957f79d4..6f013643ed 100644 --- a/internal/datacoord/server_test.go +++ b/internal/datacoord/server_test.go @@ -1997,7 +1997,7 @@ func TestOptions(t *testing.T) { }) t.Run("SetDataNodeCreator", func(t *testing.T) { var target int64 - var val int64 = rand.Int63() + var val = rand.Int63() opt := SetDataNodeCreator(func(context.Context, string) (types.DataNode, error) { target = val return nil, nil diff --git a/internal/datanode/data_sync_service_test.go b/internal/datanode/data_sync_service_test.go index 33a2fbbd2c..0cf89711a6 100644 --- a/internal/datanode/data_sync_service_test.go +++ b/internal/datanode/data_sync_service_test.go @@ -342,12 +342,12 @@ func TestBytesReader(t *testing.T) { // Bytes Reader is able to recording the position rawDataReader := bytes.NewReader(rawData) - var fvector []float32 = make([]float32, 2) + var fvector = make([]float32, 2) err := binary.Read(rawDataReader, common.Endian, &fvector) assert.Nil(t, err) assert.ElementsMatch(t, fvector, []float32{1, 2}) - var bvector []byte = make([]byte, 4) + var bvector = make([]byte, 4) err = binary.Read(rawDataReader, common.Endian, &bvector) assert.Nil(t, err) assert.ElementsMatch(t, bvector, []byte{255, 255, 255, 0}) diff --git a/internal/datanode/flow_graph_insert_buffer_node.go b/internal/datanode/flow_graph_insert_buffer_node.go index a428d5b5f0..6df4a5a971 100644 --- a/internal/datanode/flow_graph_insert_buffer_node.go +++ b/internal/datanode/flow_graph_insert_buffer_node.go @@ -503,7 +503,7 @@ func (ibNode *insertBufferNode) bufferInsertMsg(msg *msgstream.InsertMsg, endPos fieldData := idata.Data[field.FieldID].(*storage.FloatVectorFieldData) for _, r := range blobReaders { - var v []float32 = make([]float32, dim) + var v = make([]float32, dim) readBinary(r, &v, field.DataType) @@ -535,7 +535,7 @@ func (ibNode *insertBufferNode) bufferInsertMsg(msg *msgstream.InsertMsg, endPos fieldData := idata.Data[field.FieldID].(*storage.BinaryVectorFieldData) for _, r := range blobReaders { - var v []byte = make([]byte, dim/8) + var v = make([]byte, dim/8) readBinary(r, &v, field.DataType) fieldData.Data = append(fieldData.Data, v...) diff --git a/internal/datanode/flush_task.go b/internal/datanode/flush_task.go index b347c3d1df..1a5047d0b5 100644 --- a/internal/datanode/flush_task.go +++ b/internal/datanode/flush_task.go @@ -168,7 +168,7 @@ func (t *flushTaskRunner) waitFinish(notifyFunc notifyMetaFunc, postFunc taskPos <-t.startSignal pack := t.getFlushPack() - var postInjection postInjectionFunc = nil + var postInjection postInjectionFunc select { case injection := <-t.injectSignal: // notify injected diff --git a/internal/datanode/segment_replica.go b/internal/datanode/segment_replica.go index b57e99774c..3bbff3752a 100644 --- a/internal/datanode/segment_replica.go +++ b/internal/datanode/segment_replica.go @@ -170,7 +170,7 @@ func (replica *SegmentReplica) segmentFlushed(segID UniqueID) { } func (replica *SegmentReplica) new2NormalSegment(segID UniqueID) { - var seg Segment = *replica.newSegments[segID] + var seg = *replica.newSegments[segID] seg.isNew.Store(false) replica.normalSegments[segID] = &seg @@ -179,7 +179,7 @@ func (replica *SegmentReplica) new2NormalSegment(segID UniqueID) { } func (replica *SegmentReplica) new2FlushedSegment(segID UniqueID) { - var seg Segment = *replica.newSegments[segID] + var seg = *replica.newSegments[segID] seg.isNew.Store(false) seg.isFlushed.Store(true) @@ -191,7 +191,7 @@ func (replica *SegmentReplica) new2FlushedSegment(segID UniqueID) { // normal2FlushedSegment transfers a segment from *normal* to *flushed* by changing *isFlushed* // flag into true, and mv the segment from normalSegments map to flushedSegments map. func (replica *SegmentReplica) normal2FlushedSegment(segID UniqueID) { - var seg Segment = *replica.normalSegments[segID] + var seg = *replica.normalSegments[segID] seg.isFlushed.Store(true) replica.flushedSegments[segID] = &seg diff --git a/internal/indexcoord/index_coord.go b/internal/indexcoord/index_coord.go index 968f3d6157..5a70935447 100644 --- a/internal/indexcoord/index_coord.go +++ b/internal/indexcoord/index_coord.go @@ -131,7 +131,7 @@ func (i *IndexCoord) Register() error { // Init initializes the IndexCoord component. func (i *IndexCoord) Init() error { - var initErr error = nil + var initErr error Params.InitOnce() i.initOnce.Do(func() { log.Debug("IndexCoord", zap.Strings("etcd endpoints", Params.EtcdEndpoints)) @@ -233,7 +233,7 @@ func (i *IndexCoord) Init() error { // Start starts the IndexCoord component. func (i *IndexCoord) Start() error { - var startErr error = nil + var startErr error i.startOnce.Do(func() { i.loopWg.Add(1) go i.tsLoop() @@ -532,7 +532,7 @@ func (i *IndexCoord) GetIndexFilePaths(ctx context.Context, req *indexpb.GetInde log.Debug("IndexCoord GetIndexFilePaths", zap.Int64s("IndexBuildIds", req.IndexBuildIDs)) sp, _ := trace.StartSpanFromContextWithOperationName(ctx, "IndexCoord-BuildIndex") defer sp.Finish() - var indexPaths []*indexpb.IndexFilePathInfo = nil + var indexPaths []*indexpb.IndexFilePathInfo for _, indexID := range req.IndexBuildIDs { indexPathInfo, err := i.metaTable.GetIndexFilePathInfo(indexID) diff --git a/internal/indexcoord/priority_queue.go b/internal/indexcoord/priority_queue.go index e84cf147b0..4b06be03ab 100644 --- a/internal/indexcoord/priority_queue.go +++ b/internal/indexcoord/priority_queue.go @@ -97,7 +97,7 @@ func (pq *PriorityQueue) CheckExist(nodeID UniqueID) bool { } func (pq *PriorityQueue) getItemByKey(key UniqueID) interface{} { - var ret interface{} = nil + var ret interface{} for _, item := range pq.items { if item.key == key { ret = item diff --git a/internal/msgstream/mq_msgstream.go b/internal/msgstream/mq_msgstream.go index 058b380e8f..14b01649fc 100644 --- a/internal/msgstream/mq_msgstream.go +++ b/internal/msgstream/mq_msgstream.go @@ -915,7 +915,7 @@ func (ms *MqTtMsgStream) consumeToTtMsg(consumer mqclient.Consumer) { // return true only when all channels reach same timetick func (ms *MqTtMsgStream) allChanReachSameTtMsg(chanTtMsgSync map[mqclient.Consumer]bool) (Timestamp, bool) { tsMap := make(map[Timestamp]int) - var maxTime Timestamp = 0 + var maxTime Timestamp for _, t := range ms.chanTtMsgTime { tsMap[t]++ if t > maxTime { diff --git a/internal/proxy/task.go b/internal/proxy/task.go index 96d4f425a9..9792911053 100644 --- a/internal/proxy/task.go +++ b/internal/proxy/task.go @@ -1147,7 +1147,7 @@ func (cct *createCollectionTask) PreExecute(ctx context.Context) error { } if field.DataType == schemapb.DataType_FloatVector || field.DataType == schemapb.DataType_BinaryVector { exist := false - var dim int64 = 0 + var dim int64 for _, param := range field.TypeParams { if param.Key == "dim" { exist = true @@ -1798,7 +1798,7 @@ func reduceSearchResultData(searchResultData []*schemapb.SearchResultData, nq in //printSearchResultData(sData, strconv.FormatInt(int64(i), 10)) } - var skipDupCnt int64 = 0 + var skipDupCnt int64 var realTopK int64 = -1 for i := int64(0); i < nq; i++ { offsets := make([]int64, len(searchResultData)) @@ -2283,7 +2283,7 @@ func (qt *queryTask) Execute(ctx context.Context) error { func mergeRetrieveResults(retrieveResults []*internalpb.RetrieveResults) (*milvuspb.QueryResults, error) { var ret *milvuspb.QueryResults - var skipDupCnt int64 = 0 + var skipDupCnt int64 var idSet = make(map[int64]struct{}) // merge results and remove duplicates diff --git a/internal/querycoord/query_coord.go b/internal/querycoord/query_coord.go index 4a568231d3..bdc9a90306 100644 --- a/internal/querycoord/query_coord.go +++ b/internal/querycoord/query_coord.go @@ -115,7 +115,7 @@ func (qc *QueryCoord) Init() error { qc.kvClient = etcdKV return nil } - var initError error = nil + var initError error qc.initOnce.Do(func() { log.Debug("query coordinator try to connect etcd") initError = retry.Do(qc.loopCtx, connectEtcdFn, retry.Attempts(300)) @@ -493,7 +493,7 @@ func (qc *QueryCoord) loadBalanceSegmentLoop() { memoryInsufficient := false loadBalanceTasks := make([]*loadBalanceTask, 0) for { - var selectedSegmentInfo *querypb.SegmentInfo = nil + var selectedSegmentInfo *querypb.SegmentInfo sort.Slice(onlineNodeIDs, func(i, j int) bool { return nodeID2MemUsageRate[onlineNodeIDs[i]] > nodeID2MemUsageRate[onlineNodeIDs[j]] }) @@ -579,7 +579,7 @@ func chooseSegmentToBalance(sourceNodeID int64, dstNodeID int64, nodeID2MemUsageRate map[int64]float64) (*querypb.SegmentInfo, error) { memoryInsufficient := true minMemDiffPercentage := 1.0 - var selectedSegmentInfo *querypb.SegmentInfo = nil + var selectedSegmentInfo *querypb.SegmentInfo for _, info := range segmentInfos { dstNodeMemUsageAfterBalance := nodeID2MemUsage[dstNodeID] + uint64(info.MemSize) dstNodeMemUsageRateAfterBalance := float64(dstNodeMemUsageAfterBalance) / float64(nodeID2TotalMem[dstNodeID]) diff --git a/internal/querycoord/task_scheduler.go b/internal/querycoord/task_scheduler.go index 229b7f775b..6b0f48aafa 100644 --- a/internal/querycoord/task_scheduler.go +++ b/internal/querycoord/task_scheduler.go @@ -238,7 +238,7 @@ func (scheduler *TaskScheduler) reloadFromKV() error { triggerTasks[taskID].setState(state) } - var doneTriggerTask task = nil + var doneTriggerTask task for _, t := range triggerTasks { if t.getState() == taskDone { doneTriggerTask = t diff --git a/internal/querynode/query_collection.go b/internal/querynode/query_collection.go index 4ea64a47f9..470b051cea 100644 --- a/internal/querynode/query_collection.go +++ b/internal/querynode/query_collection.go @@ -1087,7 +1087,7 @@ func (q *queryCollection) search(msg queryMsg) error { } numSegment := int64(len(searchResults)) - var marshaledHits *MarshaledHits = nil + var marshaledHits *MarshaledHits err = reduceSearchResultsAndFillData(plan, searchResults, numSegment) sp.LogFields(oplog.String("statistical time", "reduceSearchResults end")) if err != nil { @@ -1106,7 +1106,7 @@ func (q *queryCollection) search(msg queryMsg) error { } tr.Record(fmt.Sprintf("reduce result done, msgID = %d", searchMsg.ID())) - var offset int64 = 0 + var offset int64 for index := range searchRequests { hitBlobSizePeerQuery, err := marshaledHits.hitBlobSizeInGroup(int64(index)) if err != nil { @@ -1309,7 +1309,7 @@ func (q *queryCollection) retrieve(msg queryMsg) error { func mergeRetrieveResults(retrieveResults []*segcorepb.RetrieveResults) (*segcorepb.RetrieveResults, error) { var ret *segcorepb.RetrieveResults - var skipDupCnt int64 = 0 + var skipDupCnt int64 var idSet = make(map[int64]struct{}) // merge results and remove duplicates diff --git a/internal/querynode/reduce_test.go b/internal/querynode/reduce_test.go index adfbda9cad..9907eb4ee1 100644 --- a/internal/querynode/reduce_test.go +++ b/internal/querynode/reduce_test.go @@ -90,7 +90,7 @@ func TestReduce_AllFunc(t *testing.T) { hitsBlob, err := marshaledHits.getHitsBlob() assert.Nil(t, err) - var offset int64 = 0 + var offset int64 for index := range placeholderGroups { hitBolbSizePeerQuery, err := marshaledHits.hitBlobSizeInGroup(int64(index)) assert.Nil(t, err) diff --git a/internal/querynode/segment_test.go b/internal/querynode/segment_test.go index 225f81ab69..935a88c0ca 100644 --- a/internal/querynode/segment_test.go +++ b/internal/querynode/segment_test.go @@ -540,7 +540,7 @@ func TestSegment_segmentSearch(t *testing.T) { hitsBlob, err := marshaledHits.getHitsBlob() assert.NoError(t, err) - var placeHolderOffset int64 = 0 + var placeHolderOffset int64 for index := range placeholderGroups { hitBlobSizePeerQuery, err := marshaledHits.hitBlobSizeInGroup(int64(index)) assert.NoError(t, err) diff --git a/internal/rootcoord/meta_table.go b/internal/rootcoord/meta_table.go index 60be002904..dfe4f1ce6c 100644 --- a/internal/rootcoord/meta_table.go +++ b/internal/rootcoord/meta_table.go @@ -1052,7 +1052,7 @@ func (mt *MetaTable) GetNotIndexedSegments(collName string, fieldName string, id return nil, fieldSchema, err } - var dupIdx typeutil.UniqueID = 0 + var dupIdx typeutil.UniqueID for _, f := range collMeta.FieldIndexes { if info, ok := mt.indexID2Meta[f.IndexID]; ok { if info.IndexName == idxInfo.IndexName { diff --git a/internal/rootcoord/root_coord.go b/internal/rootcoord/root_coord.go index 8669c79251..ffe683707d 100644 --- a/internal/rootcoord/root_coord.go +++ b/internal/rootcoord/root_coord.go @@ -923,7 +923,7 @@ func (c *Core) Register() error { // Init initialize routine func (c *Core) Init() error { - var initError error = nil + var initError error if c.kvBaseCreate == nil { c.kvBaseCreate = func(root string) (kv.TxnKV, error) { return etcdkv.NewEtcdKV(Params.EtcdEndpoints, root) diff --git a/internal/rootcoord/root_coord_test.go b/internal/rootcoord/root_coord_test.go index 3aa106b8d2..2224b300bb 100644 --- a/internal/rootcoord/root_coord_test.go +++ b/internal/rootcoord/root_coord_test.go @@ -612,7 +612,7 @@ func TestRootCoord(t *testing.T) { err = core.Init() assert.Nil(t, err) - var localTSO uint64 = 0 + var localTSO uint64 localTSOLock := sync.RWMutex{} core.TSOAllocator = func(c uint32) (uint64, error) { localTSOLock.Lock() diff --git a/internal/storage/binlog_writer.go b/internal/storage/binlog_writer.go index 555c83d13a..d3dbbdbb6c 100644 --- a/internal/storage/binlog_writer.go +++ b/internal/storage/binlog_writer.go @@ -95,7 +95,7 @@ func (writer *baseBinlogWriter) Finish() error { return fmt.Errorf("invalid start/end timestamp") } - var offset int32 = 0 + var offset int32 writer.buffer = new(bytes.Buffer) if err := binary.Write(writer.buffer, common.Endian, int32(MagicNumber)); err != nil { return err diff --git a/internal/storage/vector_chunk_manager_test.go b/internal/storage/vector_chunk_manager_test.go index 1533004bcc..a6302a71bf 100644 --- a/internal/storage/vector_chunk_manager_test.go +++ b/internal/storage/vector_chunk_manager_test.go @@ -155,7 +155,7 @@ func buildVectorChunkManager(t *testing.T, localPath string, localCacheEnable bo } var Params paramtable.BaseTable -var localPath string = "/tmp/milvus/test_data" +var localPath = "/tmp/milvus/test_data" func TestMain(m *testing.M) { Params.Init() diff --git a/internal/util/distance/calc_distance.go b/internal/util/distance/calc_distance.go index 9861aec340..227ce0253a 100644 --- a/internal/util/distance/calc_distance.go +++ b/internal/util/distance/calc_distance.go @@ -62,7 +62,7 @@ func ValidateFloatArrayLength(dim int64, length int) error { // CalcL2 returns the Euclidean distance of input vectors func CalcL2(dim int64, left []float32, lIndex int64, right []float32, rIndex int64) float32 { - var sum float32 = 0.0 + var sum float32 lFrom := lIndex * dim rFrom := rIndex * dim for i := int64(0); i < dim; i++ { @@ -75,7 +75,7 @@ func CalcL2(dim int64, left []float32, lIndex int64, right []float32, rIndex int // CalcIP returns the inner product distance of input vectors func CalcIP(dim int64, left []float32, lIndex int64, right []float32, rIndex int64) float32 { - var sum float32 = 0.0 + var sum float32 lFrom := lIndex * dim rFrom := rIndex * dim for i := int64(0); i < dim; i++ { @@ -187,9 +187,9 @@ func CalcHamming(dim int64, left []byte, lIndex int64, right []byte, rIndex int6 lFrom := lIndex * numBytes rFrom := rIndex * numBytes - var hamming int32 = 0 + var hamming int32 for i := int64(0); i < numBytes; i++ { - var xor uint8 = left[lFrom+i] ^ right[rFrom+i] + var xor = left[lFrom+i] ^ right[rFrom+i] // The dimension "dim" may not be an integer multiple of 8 // For example: diff --git a/internal/util/distance/calc_distance_test.go b/internal/util/distance/calc_distance_test.go index cf4a99cf2a..b51f61d623 100644 --- a/internal/util/distance/calc_distance_test.go +++ b/internal/util/distance/calc_distance_test.go @@ -62,7 +62,7 @@ func DistanceL2(left, right []float32) float32 { if len(left) != len(right) { panic("array dimension not equal") } - var sum float32 = 0.0 + var sum float32 for i := 0; i < len(left); i++ { gap := left[i] - right[i] sum += gap * gap @@ -75,7 +75,7 @@ func DistanceIP(left, right []float32) float32 { if len(left) != len(right) { panic("array dimension not equal") } - var sum float32 = 0.0 + var sum float32 for i := 0; i < len(left); i++ { sum += left[i] * right[i] } diff --git a/internal/util/flowgraph/input_node_test.go b/internal/util/flowgraph/input_node_test.go index 74cd25c1f2..56191ec9da 100644 --- a/internal/util/flowgraph/input_node_test.go +++ b/internal/util/flowgraph/input_node_test.go @@ -60,7 +60,7 @@ func TestInputNode(t *testing.T) { func Test_NewInputNode(t *testing.T) { nodeName := "input_node" - var maxQueueLength int32 = 0 + var maxQueueLength int32 var maxParallelism int32 = 100 node := NewInputNode(nil, nodeName, maxQueueLength, maxParallelism) assert.NotNil(t, node) diff --git a/internal/util/flowgraph/message_test.go b/internal/util/flowgraph/message_test.go index 618f9224c4..7d0b8c41b3 100644 --- a/internal/util/flowgraph/message_test.go +++ b/internal/util/flowgraph/message_test.go @@ -95,7 +95,7 @@ func TestMsgStreamMsg(t *testing.T) { Ctx: context.TODO(), } - var timestampMin Timestamp = 0 + var timestampMin Timestamp var timestampMax Timestamp = 100 streamMsg := &MsgStreamMsg{ tsMessages: messages, diff --git a/internal/util/funcutil/func.go b/internal/util/funcutil/func.go index a65d291b05..3e211adb36 100644 --- a/internal/util/funcutil/func.go +++ b/internal/util/funcutil/func.go @@ -143,7 +143,7 @@ func GetPulsarConfig(protocol, ip, port, url string, args ...int64) (map[string] } var attempt uint = 10 - var interval time.Duration = time.Second + var interval = time.Second if len(args) > 0 && args[0] > 0 { attempt = uint(args[0]) } diff --git a/internal/util/funcutil/random.go b/internal/util/funcutil/random.go index f75905fc7d..d2a77fbf45 100644 --- a/internal/util/funcutil/random.go +++ b/internal/util/funcutil/random.go @@ -17,7 +17,7 @@ import ( "time" ) -var r *rand.Rand = nil +var r *rand.Rand func init() { r = rand.New(rand.NewSource(time.Now().UnixNano())) diff --git a/internal/util/rocksmq/server/rocksmq/rocksmq_impl.go b/internal/util/rocksmq/server/rocksmq/rocksmq_impl.go index 14b7edc90c..02bf3412ba 100644 --- a/internal/util/rocksmq/server/rocksmq/rocksmq_impl.go +++ b/internal/util/rocksmq/server/rocksmq/rocksmq_impl.go @@ -144,7 +144,7 @@ func getNowTs(idAllocator allocator.GIDAllocator) (int64, error) { return nowTs.Unix(), err } -var topicMu sync.Map = sync.Map{} +var topicMu = sync.Map{} type rocksmq struct { store *gorocksdb.DB diff --git a/internal/util/rocksmq/server/rocksmq/rocksmq_impl_test.go b/internal/util/rocksmq/server/rocksmq/rocksmq_impl_test.go index 4e1e963816..a9ed6dbb06 100644 --- a/internal/util/rocksmq/server/rocksmq/rocksmq_impl_test.go +++ b/internal/util/rocksmq/server/rocksmq/rocksmq_impl_test.go @@ -32,10 +32,10 @@ import ( ) var Params paramtable.BaseTable -var rmqPath string = "/tmp/rocksmq" -var kvPathSuffix string = "_kv" -var dbPathSuffix string = "_db" -var metaPathSuffix string = "_meta" +var rmqPath = "/tmp/rocksmq" +var kvPathSuffix = "_kv" +var dbPathSuffix = "_db" +var metaPathSuffix = "_meta" func InitIDAllocator(kvPath string) *allocator.GlobalIDAllocator { rocksdbKV, err := rocksdbkv.NewRocksdbKV(kvPath) diff --git a/internal/util/rocksmq/server/rocksmq/rocksmq_retention.go b/internal/util/rocksmq/server/rocksmq/rocksmq_retention.go index 58e704eaa1..689f8f9c51 100644 --- a/internal/util/rocksmq/server/rocksmq/rocksmq_retention.go +++ b/internal/util/rocksmq/server/rocksmq/rocksmq_retention.go @@ -135,10 +135,10 @@ func (ri *retentionInfo) Stop() { // 4. delete message by range of page id; func (ri *retentionInfo) expiredCleanUp(topic string) error { log.Debug("Timeticker triggers an expiredCleanUp task for topic: " + topic) - var deletedAckedSize int64 = 0 - var startID UniqueID = 0 - var pageStartID UniqueID = 0 - var pageEndID UniqueID = 0 + var deletedAckedSize int64 + var startID UniqueID + var pageStartID UniqueID + var pageEndID UniqueID var err error fixedAckedTsKey, _ := constructKey(AckedTsTitle, topic) diff --git a/internal/util/rocksmq/server/rocksmq/rocksmq_retention_test.go b/internal/util/rocksmq/server/rocksmq/rocksmq_retention_test.go index d54688c786..a347d202e0 100644 --- a/internal/util/rocksmq/server/rocksmq/rocksmq_retention_test.go +++ b/internal/util/rocksmq/server/rocksmq/rocksmq_retention_test.go @@ -25,7 +25,7 @@ import ( "go.uber.org/zap" ) -var retentionPath string = "/tmp/rmq_retention/" +var retentionPath = "/tmp/rmq_retention/" func TestMain(m *testing.M) { err := os.MkdirAll(retentionPath, os.ModePerm) diff --git a/internal/util/sessionutil/session_util_test.go b/internal/util/sessionutil/session_util_test.go index 5b6fc2457f..252229839d 100644 --- a/internal/util/sessionutil/session_util_test.go +++ b/internal/util/sessionutil/session_util_test.go @@ -43,7 +43,7 @@ func TestGetServerIDConcurrently(t *testing.T) { defer etcdKV.RemoveWithPrefix("") var wg sync.WaitGroup - var muList sync.Mutex = sync.Mutex{} + var muList = sync.Mutex{} s := NewSession(ctx, metaRoot, etcdEndpoints) res := make([]int64, 0) @@ -114,7 +114,7 @@ func TestUpdateSessions(t *testing.T) { defer etcdKV.RemoveWithPrefix("") var wg sync.WaitGroup - var muList sync.Mutex = sync.Mutex{} + var muList = sync.Mutex{} s := NewSession(ctx, metaRoot, etcdEndpoints) diff --git a/internal/util/typeutil/hash_test.go b/internal/util/typeutil/hash_test.go index 08c4dd6260..3f27ca99f7 100644 --- a/internal/util/typeutil/hash_test.go +++ b/internal/util/typeutil/hash_test.go @@ -21,7 +21,7 @@ import ( func TestUint64(t *testing.T) { var i int64 = -1 - var u uint64 = uint64(i) + var u = uint64(i) t.Log(i) t.Log(u) } @@ -48,7 +48,7 @@ func TestHash32_Uint64(t *testing.T) { } func TestHash32_String(t *testing.T) { - var u string = "ok" + var u = "ok" h, err := Hash32String(u) assert.Nil(t, err)