From c810c97be60c6d255b4222bc6e628e12f1207d6c Mon Sep 17 00:00:00 2001 From: Jiquan Long Date: Mon, 17 Apr 2023 10:56:31 +0800 Subject: [PATCH] Optimize log trace (#23431) (#23432) Signed-off-by: longjiquan --- internal/rootcoord/broker.go | 13 ++++++++---- internal/rootcoord/meta_table.go | 12 +++++------ internal/rootcoord/root_coord.go | 36 ++++++++++++++++---------------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/internal/rootcoord/broker.go b/internal/rootcoord/broker.go index ff6c671687..85376f822f 100644 --- a/internal/rootcoord/broker.go +++ b/internal/rootcoord/broker.go @@ -78,7 +78,7 @@ func newServerBroker(s *Core) *ServerBroker { } func (b *ServerBroker) ReleaseCollection(ctx context.Context, collectionID UniqueID) error { - log.Info("releasing collection", zap.Int64("collection", collectionID)) + log.Ctx(ctx).Info("releasing collection", zap.Int64("collection", collectionID)) resp, err := b.s.queryCoord.ReleaseCollection(ctx, &querypb.ReleaseCollectionRequest{ Base: commonpbutil.NewMsgBase(commonpbutil.WithMsgType(commonpb.MsgType_ReleaseCollection)), @@ -93,7 +93,7 @@ func (b *ServerBroker) ReleaseCollection(ctx context.Context, collectionID Uniqu return fmt.Errorf("failed to release collection, code: %s, reason: %s", resp.GetErrorCode(), resp.GetReason()) } - log.Info("done to release collection", zap.Int64("collection", collectionID)) + log.Ctx(ctx).Info("done to release collection", zap.Int64("collection", collectionID)) return nil } @@ -121,7 +121,7 @@ func toKeyDataPairs(m map[string][]byte) []*commonpb.KeyDataPair { } func (b *ServerBroker) WatchChannels(ctx context.Context, info *watchInfo) error { - log.Info("watching channels", zap.Uint64("ts", info.ts), zap.Int64("collection", info.collectionID), zap.Strings("vChannels", info.vChannels)) + log.Ctx(ctx).Info("watching channels", zap.Uint64("ts", info.ts), zap.Int64("collection", info.collectionID), zap.Strings("vChannels", info.vChannels)) resp, err := b.s.dataCoord.WatchChannels(ctx, &datapb.WatchChannelsRequest{ CollectionID: info.collectionID, @@ -137,7 +137,7 @@ func (b *ServerBroker) WatchChannels(ctx context.Context, info *watchInfo) error return fmt.Errorf("failed to watch channels, code: %s, reason: %s", resp.GetStatus().GetErrorCode(), resp.GetStatus().GetReason()) } - log.Info("done to watch channels", zap.Uint64("ts", info.ts), zap.Int64("collection", info.collectionID), zap.Strings("vChannels", info.vChannels)) + log.Ctx(ctx).Info("done to watch channels", zap.Uint64("ts", info.ts), zap.Int64("collection", info.collectionID), zap.Strings("vChannels", info.vChannels)) return nil } @@ -222,6 +222,8 @@ func (b *ServerBroker) GetSegmentStates(ctx context.Context, req *datapb.GetSegm } func (b *ServerBroker) DropCollectionIndex(ctx context.Context, collID UniqueID, partIDs []UniqueID) error { + log.Ctx(ctx).Info("dropping collection index", zap.Int64("collection", collID), zap.Int64s("partitions", partIDs)) + rsp, err := b.s.indexCoord.DropIndex(ctx, &indexpb.DropIndexRequest{ CollectionID: collID, PartitionIDs: partIDs, @@ -234,6 +236,9 @@ func (b *ServerBroker) DropCollectionIndex(ctx context.Context, collID UniqueID, if rsp.ErrorCode != commonpb.ErrorCode_Success { return fmt.Errorf(rsp.Reason) } + + log.Ctx(ctx).Info("done to drop collection index", zap.Int64("collection", collID), zap.Int64s("partitions", partIDs)) + return nil } diff --git a/internal/rootcoord/meta_table.go b/internal/rootcoord/meta_table.go index ba576a08ba..ed6cb13968 100644 --- a/internal/rootcoord/meta_table.go +++ b/internal/rootcoord/meta_table.go @@ -166,7 +166,7 @@ func (mt *MetaTable) AddCollection(ctx context.Context, coll *model.Collection) } mt.collName2ID[coll.Name] = coll.CollectionID mt.collID2Meta[coll.CollectionID] = coll.Clone() - log.Info("add collection to meta table", zap.String("collection", coll.Name), + log.Ctx(ctx).Info("add collection to meta table", zap.String("collection", coll.Name), zap.Int64("id", coll.CollectionID), zap.Uint64("ts", coll.CreateTime)) return nil } @@ -194,7 +194,7 @@ func (mt *MetaTable) ChangeCollectionState(ctx context.Context, collectionID Uni metrics.RootCoordNumOfPartitions.WithLabelValues().Sub(float64(coll.GetPartitionNum(true))) } - log.Info("change collection state", zap.Int64("collection", collectionID), + log.Ctx(ctx).Info("change collection state", zap.Int64("collection", collectionID), zap.String("state", state.String()), zap.Uint64("ts", ts)) return nil @@ -255,7 +255,7 @@ func (mt *MetaTable) RemoveCollection(ctx context.Context, collectionID UniqueID mt.removeAllNamesIfMatchedInternal(collectionID, allNames) mt.removeCollectionByIDInternal(collectionID) - log.Info("remove collection", zap.String("name", name), zap.Int64("id", collectionID), zap.Strings("aliases", aliases)) + log.Ctx(ctx).Info("remove collection", zap.String("name", name), zap.Int64("id", collectionID), zap.Strings("aliases", aliases)) return nil } @@ -513,7 +513,7 @@ func (mt *MetaTable) AddPartition(ctx context.Context, partition *model.Partitio } mt.collID2Meta[partition.CollectionID].Partitions = append(mt.collID2Meta[partition.CollectionID].Partitions, partition.Clone()) - log.Info("add partition to meta table", + log.Ctx(ctx).Info("add partition to meta table", zap.Int64("collection", partition.CollectionID), zap.String("partition", partition.PartitionName), zap.Int64("partitionid", partition.PartitionID), zap.Uint64("ts", partition.PartitionCreatedTimestamp)) @@ -539,12 +539,12 @@ func (mt *MetaTable) ChangePartitionState(ctx context.Context, collectionID Uniq mt.collID2Meta[collectionID].Partitions[idx] = clone if state == pb.PartitionState_PartitionCreated { - log.Warn("[should not happen] change partition to created", + log.Ctx(ctx).Warn("[should not happen] change partition to created", zap.String("collection", coll.Name), zap.Int64("collection id", coll.CollectionID), zap.String("partition", clone.PartitionName), zap.Int64("partition id", clone.PartitionID)) } - log.Info("change partition state", zap.Int64("collection", collectionID), + log.Ctx(ctx).Info("change partition state", zap.Int64("collection", collectionID), zap.Int64("partition", partitionID), zap.String("state", state.String()), zap.Uint64("ts", ts)) diff --git a/internal/rootcoord/root_coord.go b/internal/rootcoord/root_coord.go index 6bd87c8922..0b30051446 100644 --- a/internal/rootcoord/root_coord.go +++ b/internal/rootcoord/root_coord.go @@ -798,7 +798,7 @@ func (c *Core) CreateCollection(ctx context.Context, in *milvuspb.CreateCollecti } if err := c.scheduler.AddTask(t); err != nil { - log.Ctx(ctx).Error("failed to enqueue request to create collection", zap.String("role", typeutil.RootCoordRole), + log.Ctx(ctx).Info("failed to enqueue request to create collection", zap.String("role", typeutil.RootCoordRole), zap.Error(err), zap.String("name", in.GetCollectionName()), zap.Int64("msgID", in.GetBase().GetMsgID())) @@ -807,7 +807,7 @@ func (c *Core) CreateCollection(ctx context.Context, in *milvuspb.CreateCollecti } if err := t.WaitToFinish(); err != nil { - log.Ctx(ctx).Error("failed to create collection", zap.String("role", typeutil.RootCoordRole), + log.Ctx(ctx).Info("failed to create collection", zap.String("role", typeutil.RootCoordRole), zap.Error(err), zap.String("name", in.GetCollectionName()), zap.Int64("msgID", in.GetBase().GetMsgID()), zap.Uint64("ts", t.GetTs())) @@ -848,7 +848,7 @@ func (c *Core) DropCollection(ctx context.Context, in *milvuspb.DropCollectionRe } if err := c.scheduler.AddTask(t); err != nil { - log.Ctx(ctx).Error("failed to enqueue request to drop collection", zap.String("role", typeutil.RootCoordRole), + log.Ctx(ctx).Info("failed to enqueue request to drop collection", zap.String("role", typeutil.RootCoordRole), zap.Error(err), zap.String("name", in.GetCollectionName()), zap.Int64("msgID", in.GetBase().GetMsgID())) @@ -857,7 +857,7 @@ func (c *Core) DropCollection(ctx context.Context, in *milvuspb.DropCollectionRe } if err := t.WaitToFinish(); err != nil { - log.Ctx(ctx).Error("failed to drop collection", zap.String("role", typeutil.RootCoordRole), + log.Ctx(ctx).Info("failed to drop collection", zap.String("role", typeutil.RootCoordRole), zap.Error(err), zap.String("name", in.GetCollectionName()), zap.Int64("msgID", in.GetBase().GetMsgID()), zap.Uint64("ts", t.GetTs())) @@ -901,7 +901,7 @@ func (c *Core) HasCollection(ctx context.Context, in *milvuspb.HasCollectionRequ } if err := c.scheduler.AddTask(t); err != nil { - log.Warn("failed to enqueue request to has collection", zap.Error(err)) + log.Info("failed to enqueue request to has collection", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.FailLabel).Inc() return &milvuspb.BoolResponse{ Status: failStatus(commonpb.ErrorCode_UnexpectedError, "HasCollection failed: "+err.Error()), @@ -910,7 +910,7 @@ func (c *Core) HasCollection(ctx context.Context, in *milvuspb.HasCollectionRequ } if err := t.WaitToFinish(); err != nil { - log.Warn("failed to has collection", zap.Error(err)) + log.Info("failed to has collection", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.FailLabel).Inc() return &milvuspb.BoolResponse{ Status: failStatus(commonpb.ErrorCode_UnexpectedError, "HasCollection failed: "+err.Error()), @@ -993,7 +993,7 @@ func (c *Core) describeCollectionImpl(ctx context.Context, in *milvuspb.Describe } if err := c.scheduler.AddTask(t); err != nil { - log.Warn("failed to enqueue request to describe collection", zap.Error(err)) + log.Info("failed to enqueue request to describe collection", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues("DescribeCollection", metrics.FailLabel).Inc() return &milvuspb.DescribeCollectionResponse{ // TODO: use commonpb.ErrorCode_CollectionNotExists. SDK use commonpb.ErrorCode_UnexpectedError now. @@ -1003,7 +1003,7 @@ func (c *Core) describeCollectionImpl(ctx context.Context, in *milvuspb.Describe } if err := t.WaitToFinish(); err != nil { - log.Warn("failed to describe collection", zap.Error(err)) + log.Info("failed to describe collection", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues("DescribeCollection", metrics.FailLabel).Inc() return &milvuspb.DescribeCollectionResponse{ // TODO: use commonpb.ErrorCode_CollectionNotExists. SDK use commonpb.ErrorCode_UnexpectedError now. @@ -1059,7 +1059,7 @@ func (c *Core) ShowCollections(ctx context.Context, in *milvuspb.ShowCollections } if err := c.scheduler.AddTask(t); err != nil { - log.Warn("failed to enqueue request to show collections", zap.Error(err)) + log.Info("failed to enqueue request to show collections", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.FailLabel).Inc() return &milvuspb.ShowCollectionsResponse{ Status: failStatus(commonpb.ErrorCode_UnexpectedError, "ShowCollections failed: "+err.Error()), @@ -1067,7 +1067,7 @@ func (c *Core) ShowCollections(ctx context.Context, in *milvuspb.ShowCollections } if err := t.WaitToFinish(); err != nil { - log.Warn("failed to show collections", zap.Error(err)) + log.Info("failed to show collections", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.FailLabel).Inc() return &milvuspb.ShowCollectionsResponse{ Status: failStatus(commonpb.ErrorCode_UnexpectedError, "ShowCollections failed: "+err.Error()), @@ -1155,7 +1155,7 @@ func (c *Core) CreatePartition(ctx context.Context, in *milvuspb.CreatePartition } if err := c.scheduler.AddTask(t); err != nil { - log.Ctx(ctx).Error("failed to enqueue request to create partition", zap.String("role", typeutil.RootCoordRole), + log.Ctx(ctx).Info("failed to enqueue request to create partition", zap.String("role", typeutil.RootCoordRole), zap.Error(err), zap.String("collection", in.GetCollectionName()), zap.String("partition", in.GetPartitionName()), zap.Int64("msgID", in.GetBase().GetMsgID())) @@ -1165,7 +1165,7 @@ func (c *Core) CreatePartition(ctx context.Context, in *milvuspb.CreatePartition } if err := t.WaitToFinish(); err != nil { - log.Ctx(ctx).Error("failed to create partition", zap.String("role", typeutil.RootCoordRole), + log.Ctx(ctx).Info("failed to create partition", zap.String("role", typeutil.RootCoordRole), zap.Error(err), zap.String("collection", in.GetCollectionName()), zap.String("partition", in.GetPartitionName()), zap.Int64("msgID", in.GetBase().GetMsgID()), zap.Uint64("ts", t.GetTs())) @@ -1207,7 +1207,7 @@ func (c *Core) DropPartition(ctx context.Context, in *milvuspb.DropPartitionRequ } if err := c.scheduler.AddTask(t); err != nil { - log.Ctx(ctx).Error("failed to enqueue request to drop partition", zap.String("role", typeutil.RootCoordRole), + log.Ctx(ctx).Info("failed to enqueue request to drop partition", zap.String("role", typeutil.RootCoordRole), zap.Error(err), zap.String("collection", in.GetCollectionName()), zap.String("partition", in.GetPartitionName()), zap.Int64("msgID", in.GetBase().GetMsgID())) @@ -1216,7 +1216,7 @@ func (c *Core) DropPartition(ctx context.Context, in *milvuspb.DropPartitionRequ return failStatus(commonpb.ErrorCode_UnexpectedError, err.Error()), nil } if err := t.WaitToFinish(); err != nil { - log.Ctx(ctx).Error("failed to drop partition", zap.String("role", typeutil.RootCoordRole), + log.Ctx(ctx).Info("failed to drop partition", zap.String("role", typeutil.RootCoordRole), zap.Error(err), zap.String("collection", in.GetCollectionName()), zap.String("partition", in.GetPartitionName()), zap.Int64("msgID", in.GetBase().GetMsgID()), zap.Uint64("ts", t.GetTs())) @@ -1261,7 +1261,7 @@ func (c *Core) HasPartition(ctx context.Context, in *milvuspb.HasPartitionReques } if err := c.scheduler.AddTask(t); err != nil { - log.Warn("failed to enqueue request to has partition", zap.Error(err)) + log.Info("failed to enqueue request to has partition", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.FailLabel).Inc() return &milvuspb.BoolResponse{ Status: failStatus(commonpb.ErrorCode_UnexpectedError, "HasPartition failed: "+err.Error()), @@ -1270,7 +1270,7 @@ func (c *Core) HasPartition(ctx context.Context, in *milvuspb.HasPartitionReques } if err := t.WaitToFinish(); err != nil { - log.Warn("failed to has partition", zap.Error(err)) + log.Info("failed to has partition", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.FailLabel).Inc() return &milvuspb.BoolResponse{ Status: failStatus(commonpb.ErrorCode_UnexpectedError, "HasPartition failed: "+err.Error()), @@ -1314,7 +1314,7 @@ func (c *Core) showPartitionsImpl(ctx context.Context, in *milvuspb.ShowPartitio } if err := c.scheduler.AddTask(t); err != nil { - log.Warn("failed to enqueue request to show partitions", zap.Error(err)) + log.Info("failed to enqueue request to show partitions", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.FailLabel).Inc() return &milvuspb.ShowPartitionsResponse{ Status: failStatus(commonpb.ErrorCode_UnexpectedError, "ShowPartitions failed: "+err.Error()), @@ -1323,7 +1323,7 @@ func (c *Core) showPartitionsImpl(ctx context.Context, in *milvuspb.ShowPartitio } if err := t.WaitToFinish(); err != nil { - log.Warn("failed to show partitions", zap.Error(err)) + log.Info("failed to show partitions", zap.Error(err)) metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.FailLabel).Inc() return &milvuspb.ShowPartitionsResponse{ Status: failStatus(commonpb.ErrorCode_UnexpectedError, "ShowPartitions failed: "+err.Error()),