From ab21115d54bd7a00a875803678117aee50554a7c Mon Sep 17 00:00:00 2001 From: sunby Date: Mon, 8 Mar 2021 15:25:55 +0800 Subject: [PATCH] Init rand.Seed Signed-off-by: sunby --- internal/datanode/data_node.go | 3 ++- internal/dataservice/server.go | 2 ++ internal/indexnode/indexnode.go | 2 ++ internal/indexservice/indexservice.go | 2 ++ internal/proxyservice/node_info.go | 2 -- internal/querynode/query_node.go | 3 +++ internal/queryservice/queryservice.go | 2 ++ 7 files changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/datanode/data_node.go b/internal/datanode/data_node.go index 0a61f7da2b..8cd5b9fe21 100644 --- a/internal/datanode/data_node.go +++ b/internal/datanode/data_node.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "math/rand" "sync/atomic" "time" @@ -49,7 +50,7 @@ type DataNode struct { } func NewDataNode(ctx context.Context, factory msgstream.Factory) *DataNode { - + rand.Seed(time.Now().UnixNano()) ctx2, cancel2 := context.WithCancel(ctx) node := &DataNode{ ctx: ctx2, diff --git a/internal/dataservice/server.go b/internal/dataservice/server.go index 9a09ad91c0..5300fe2309 100644 --- a/internal/dataservice/server.go +++ b/internal/dataservice/server.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math/rand" "path" "strconv" "strings" @@ -63,6 +64,7 @@ type Server struct { } func CreateServer(ctx context.Context, factory msgstream.Factory) (*Server, error) { + rand.Seed(time.Now().UnixNano()) ch := make(chan struct{}) s := &Server{ ctx: ctx, diff --git a/internal/indexnode/indexnode.go b/internal/indexnode/indexnode.go index 44d679428e..e0cc5bad6f 100644 --- a/internal/indexnode/indexnode.go +++ b/internal/indexnode/indexnode.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "log" + "math/rand" "time" "github.com/opentracing/opentracing-go" @@ -49,6 +50,7 @@ type IndexNode struct { } func NewIndexNode(ctx context.Context) (*IndexNode, error) { + rand.Seed(time.Now().UnixNano()) ctx1, cancel := context.WithCancel(ctx) b := &IndexNode{ loopCtx: ctx1, diff --git a/internal/indexservice/indexservice.go b/internal/indexservice/indexservice.go index 6e9c4d99a9..d70048cdc7 100644 --- a/internal/indexservice/indexservice.go +++ b/internal/indexservice/indexservice.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "log" + "math/rand" "sync" "time" @@ -58,6 +59,7 @@ type UniqueID = typeutil.UniqueID type Timestamp = typeutil.Timestamp func NewIndexService(ctx context.Context) (*IndexService, error) { + rand.Seed(time.Now().UnixNano()) ctx1, cancel := context.WithCancel(ctx) i := &IndexService{ loopCtx: ctx1, diff --git a/internal/proxyservice/node_info.go b/internal/proxyservice/node_info.go index c151324b2e..a135542708 100644 --- a/internal/proxyservice/node_info.go +++ b/internal/proxyservice/node_info.go @@ -7,7 +7,6 @@ import ( "math/rand" "strconv" "sync" - "time" grpcproxynodeclient "github.com/zilliztech/milvus-distributed/internal/distributed/proxynode/client" "github.com/zilliztech/milvus-distributed/internal/types" @@ -28,7 +27,6 @@ type GlobalNodeInfoTable struct { } func (table *GlobalNodeInfoTable) randomPick() UniqueID { - rand.Seed(time.Now().UnixNano()) l := len(table.nodeIDs) choice := rand.Intn(l) return table.nodeIDs[choice] diff --git a/internal/querynode/query_node.go b/internal/querynode/query_node.go index a663f0d3fc..05a421841d 100644 --- a/internal/querynode/query_node.go +++ b/internal/querynode/query_node.go @@ -15,8 +15,10 @@ import "C" import ( "context" "fmt" + "math/rand" "strings" "sync/atomic" + "time" "github.com/zilliztech/milvus-distributed/internal/types" @@ -62,6 +64,7 @@ type QueryNode struct { } func NewQueryNode(ctx context.Context, queryNodeID UniqueID, factory msgstream.Factory) *QueryNode { + rand.Seed(time.Now().UnixNano()) ctx1, cancel := context.WithCancel(ctx) node := &QueryNode{ queryNodeLoopCtx: ctx1, diff --git a/internal/queryservice/queryservice.go b/internal/queryservice/queryservice.go index dd6d25ebe6..0b908b8423 100644 --- a/internal/queryservice/queryservice.go +++ b/internal/queryservice/queryservice.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "math/rand" "sort" "strconv" "sync" @@ -642,6 +643,7 @@ func (qs *QueryService) GetSegmentInfo(ctx context.Context, req *querypb.Segment } func NewQueryService(ctx context.Context, factory msgstream.Factory) (*QueryService, error) { + rand.Seed(time.Now().UnixNano()) nodes := make(map[int64]*queryNodeInfo) queryChannels := make([]*queryChannelInfo, 0) ctx1, cancel := context.WithCancel(ctx)