From 213db490bd3a2ff32b1c1b4e3dc30ae1df6837d7 Mon Sep 17 00:00:00 2001 From: yah01 Date: Wed, 30 Aug 2023 10:24:29 +0800 Subject: [PATCH] Use pointer receiver for large struct (#26668) Signed-off-by: yah01 --- internal/datacoord/segment_manager.go | 2 +- internal/distributed/proxy/httpserver/wrap_request.go | 8 ++++---- internal/metastore/model/alias.go | 6 +++--- internal/metastore/model/collection.go | 8 ++++---- internal/metastore/model/database.go | 6 +++--- internal/metastore/model/field.go | 6 +++--- internal/metastore/model/partition.go | 6 +++--- internal/proxy/client_info.go | 6 +++--- internal/querycoordv2/balance/balance.go | 4 ++-- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/internal/datacoord/segment_manager.go b/internal/datacoord/segment_manager.go index b30b145235..0d87fc2113 100644 --- a/internal/datacoord/segment_manager.go +++ b/internal/datacoord/segment_manager.go @@ -93,7 +93,7 @@ type Allocation struct { ExpireTime Timestamp } -func (alloc Allocation) String() string { +func (alloc *Allocation) String() string { t, _ := tsoutil.ParseTS(alloc.ExpireTime) return fmt.Sprintf("SegmentID: %d, NumOfRows: %d, ExpireTime: %v", alloc.SegmentID, alloc.NumOfRows, t) } diff --git a/internal/distributed/proxy/httpserver/wrap_request.go b/internal/distributed/proxy/httpserver/wrap_request.go index 75c8ee415f..b9d463731c 100644 --- a/internal/distributed/proxy/httpserver/wrap_request.go +++ b/internal/distributed/proxy/httpserver/wrap_request.go @@ -77,7 +77,7 @@ type FieldData struct { } // AsSchemapb converts the FieldData to schemapb.FieldData -func (f FieldData) AsSchemapb() (*schemapb.FieldData, error) { +func (f *FieldData) AsSchemapb() (*schemapb.FieldData, error) { // is scarlar ret := schemapb.FieldData{ Type: f.Type, @@ -319,16 +319,16 @@ type VectorsArray struct { IDs *VectorIDs `json:"ids,omitempty"` } -func (v VectorsArray) isIDs() bool { +func (v *VectorsArray) isIDs() bool { return v.IDs != nil } -func (v VectorsArray) isBinaryVector() bool { +func (v *VectorsArray) isBinaryVector() bool { return v.IDs == nil && len(v.BinaryVectors) > 0 } // AsPbVectorArray convert as milvuspb.VectorArray -func (v VectorsArray) AsPbVectorArray() *milvuspb.VectorsArray { +func (v *VectorsArray) AsPbVectorArray() *milvuspb.VectorsArray { ret := &milvuspb.VectorsArray{} switch { case v.isIDs(): diff --git a/internal/metastore/model/alias.go b/internal/metastore/model/alias.go index 4e13b7aac0..1291410896 100644 --- a/internal/metastore/model/alias.go +++ b/internal/metastore/model/alias.go @@ -10,11 +10,11 @@ type Alias struct { DbID int64 } -func (a Alias) Available() bool { +func (a *Alias) Available() bool { return a.State == pb.AliasState_AliasCreated } -func (a Alias) Clone() *Alias { +func (a *Alias) Clone() *Alias { return &Alias{ Name: a.Name, CollectionID: a.CollectionID, @@ -24,7 +24,7 @@ func (a Alias) Clone() *Alias { } } -func (a Alias) Equal(other Alias) bool { +func (a *Alias) Equal(other Alias) bool { return a.Name == other.Name && a.CollectionID == other.CollectionID && a.DbID == other.DbID diff --git a/internal/metastore/model/collection.go b/internal/metastore/model/collection.go index d4fca0f7b2..5b03ad1976 100644 --- a/internal/metastore/model/collection.go +++ b/internal/metastore/model/collection.go @@ -29,11 +29,11 @@ type Collection struct { EnableDynamicField bool } -func (c Collection) Available() bool { +func (c *Collection) Available() bool { return c.State == pb.CollectionState_CollectionCreated } -func (c Collection) Clone() *Collection { +func (c *Collection) Clone() *Collection { return &Collection{ TenantID: c.TenantID, DBID: c.DBID, @@ -56,14 +56,14 @@ func (c Collection) Clone() *Collection { } } -func (c Collection) GetPartitionNum(filterUnavailable bool) int { +func (c *Collection) GetPartitionNum(filterUnavailable bool) int { if !filterUnavailable { return len(c.Partitions) } return lo.CountBy(c.Partitions, func(p *Partition) bool { return p.Available() }) } -func (c Collection) Equal(other Collection) bool { +func (c *Collection) Equal(other Collection) bool { return c.TenantID == other.TenantID && c.DBID == other.DBID && CheckPartitionsEqual(c.Partitions, other.Partitions) && diff --git a/internal/metastore/model/database.go b/internal/metastore/model/database.go index 871cfe80d3..d18af54283 100644 --- a/internal/metastore/model/database.go +++ b/internal/metastore/model/database.go @@ -28,11 +28,11 @@ func NewDefaultDatabase() *Database { return NewDatabase(util.DefaultDBID, util.DefaultDBName, pb.DatabaseState_DatabaseCreated) } -func (c Database) Available() bool { +func (c *Database) Available() bool { return c.State == pb.DatabaseState_DatabaseCreated } -func (c Database) Clone() *Database { +func (c *Database) Clone() *Database { return &Database{ TenantID: c.TenantID, ID: c.ID, @@ -42,7 +42,7 @@ func (c Database) Clone() *Database { } } -func (c Database) Equal(other Database) bool { +func (c *Database) Equal(other Database) bool { return c.TenantID == other.TenantID && c.Name == other.Name && c.ID == other.ID && diff --git a/internal/metastore/model/field.go b/internal/metastore/model/field.go index 9b75413274..029bc825b7 100644 --- a/internal/metastore/model/field.go +++ b/internal/metastore/model/field.go @@ -22,11 +22,11 @@ type Field struct { DefaultValue *schemapb.ValueField } -func (f Field) Available() bool { +func (f *Field) Available() bool { return f.State == schemapb.FieldState_FieldCreated } -func (f Field) Clone() *Field { +func (f *Field) Clone() *Field { return &Field{ FieldID: f.FieldID, Name: f.Name, @@ -56,7 +56,7 @@ func checkParamsEqual(paramsA, paramsB []*commonpb.KeyValuePair) bool { return A.Equal(paramsB) } -func (f Field) Equal(other Field) bool { +func (f *Field) Equal(other Field) bool { return f.FieldID == other.FieldID && f.Name == other.Name && f.IsPrimaryKey == other.IsPrimaryKey && diff --git a/internal/metastore/model/partition.go b/internal/metastore/model/partition.go index e23e34f19d..4fda387ec4 100644 --- a/internal/metastore/model/partition.go +++ b/internal/metastore/model/partition.go @@ -14,11 +14,11 @@ type Partition struct { State pb.PartitionState } -func (p Partition) Available() bool { +func (p *Partition) Available() bool { return p.State == pb.PartitionState_PartitionCreated } -func (p Partition) Clone() *Partition { +func (p *Partition) Clone() *Partition { return &Partition{ PartitionID: p.PartitionID, PartitionName: p.PartitionName, @@ -37,7 +37,7 @@ func ClonePartitions(partitions []*Partition) []*Partition { return clone } -func (p Partition) Equal(other Partition) bool { +func (p *Partition) Equal(other Partition) bool { return p.PartitionName == other.PartitionName } diff --git a/internal/proxy/client_info.go b/internal/proxy/client_info.go index 5ba874a581..a6bfcecffd 100644 --- a/internal/proxy/client_info.go +++ b/internal/proxy/client_info.go @@ -31,7 +31,7 @@ func getLoggerOfClientInfo(info *commonpb.ClientInfo) []zap.Field { return fields } -func (c clientInfo) getLogger() []zap.Field { +func (c *clientInfo) getLogger() []zap.Field { fields := getLoggerOfClientInfo(c.ClientInfo) fields = append(fields, zap.Int64("identifier", c.identifier), @@ -40,10 +40,10 @@ func (c clientInfo) getLogger() []zap.Field { return fields } -func (c clientInfo) ctxLogRegister(ctx context.Context) { +func (c *clientInfo) ctxLogRegister(ctx context.Context) { log.Ctx(ctx).Info("client register", c.getLogger()...) } -func (c clientInfo) logDeregister() { +func (c *clientInfo) logDeregister() { log.Info("client deregister", c.getLogger()...) } diff --git a/internal/querycoordv2/balance/balance.go b/internal/querycoordv2/balance/balance.go index c853d00f6d..20a15e9c66 100644 --- a/internal/querycoordv2/balance/balance.go +++ b/internal/querycoordv2/balance/balance.go @@ -32,7 +32,7 @@ type SegmentAssignPlan struct { To int64 } -func (segPlan SegmentAssignPlan) ToString() string { +func (segPlan *SegmentAssignPlan) ToString() string { return fmt.Sprintf("SegmentPlan:[collectionID: %d, replicaID: %d, segmentID: %d, from: %d, to: %d]\n", segPlan.Segment.CollectionID, segPlan.ReplicaID, segPlan.Segment.ID, segPlan.From, segPlan.To) } @@ -44,7 +44,7 @@ type ChannelAssignPlan struct { To int64 } -func (chanPlan ChannelAssignPlan) ToString() string { +func (chanPlan *ChannelAssignPlan) ToString() string { return fmt.Sprintf("ChannelPlan:[collectionID: %d, channel: %s, replicaID: %d, from: %d, to: %d]\n", chanPlan.Channel.CollectionID, chanPlan.Channel.ChannelName, chanPlan.ReplicaID, chanPlan.From, chanPlan.To) }