Skip to content

Commit

Permalink
Add 'not supported' warning for legacy show segment-loaded command (#173
Browse files Browse the repository at this point in the history
)

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Jul 24, 2023
1 parent 6f8b716 commit 9986cdd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 42 deletions.
2 changes: 0 additions & 2 deletions states/etcd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ func ShowCommand(cli clientv3.KV, basePath string) *cobra.Command {

showCmd.AddCommand(
// v2.1 legacy commands
// show segment-loaded
show.SegmentLoadedCommand(cli, basePath),

// show querycoord-tasks
show.QueryCoordTasks(cli, basePath),
Expand Down
4 changes: 0 additions & 4 deletions states/etcd/show/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ func (rs *Aliases) PrintAs(format framework.Format) string {
return ""
}

func (rs *Aliases) Entities() any {
return rs.Data
}

func (rs *Aliases) PrintAlias(sb *strings.Builder, a *models.Alias) {
fmt.Printf("Collection ID: %d\tAlias Name: %s\tState: %s\n", a.CollectionID, a.Name, a.State.String())
}
74 changes: 38 additions & 36 deletions states/etcd/show/segment_loaded.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
package show

import (
"context"
"fmt"
"strings"

"github.com/cockroachdb/errors"
"github.com/milvus-io/birdwatcher/framework"
"github.com/milvus-io/birdwatcher/models"
"github.com/milvus-io/birdwatcher/proto/v2.0/querypb"
"github.com/milvus-io/birdwatcher/states/etcd/common"
"github.com/spf13/cobra"
clientv3 "go.etcd.io/etcd/client/v3"
etcdversion "github.com/milvus-io/birdwatcher/states/etcd/version"
)

// SegmentLoadedCommand returns show segment-loaded command.
func SegmentLoadedCommand(cli clientv3.KV, basePath string) *cobra.Command {
cmd := &cobra.Command{
Use: "segment-loaded",
Short: "display segment information from querycoord",
Aliases: []string{"segments-loaded"},
RunE: func(cmd *cobra.Command, args []string) error {
type SegmentLoadedParam struct {
framework.ParamBase `use:"show segment-loaded" desc:"display segment information from querycoordv1 meta" alias:"segments-loaded"`
CollectionID int64 `name:"collection" default:"0" desc:"collection id to filter with"`
SegmentID int64 `name:"segment" default:"0" desc:"segment id to filter with"`
}

collID, err := cmd.Flags().GetInt64("collection")
if err != nil {
return err
}
segmentID, err := cmd.Flags().GetInt64("segment")
if err != nil {
return err
}
func (c *ComponentShow) SegmentLoadedCommand(ctx context.Context, p *SegmentLoadedParam) (*LoadedSegments, error) {
if etcdversion.GetVersion() != models.LTEVersion2_1 {
return nil, errors.New("list segment-loaded from meta only support before 2.1.x, try use `show segment-loaded-grc` instead")
}
segments, err := common.ListLoadedSegments(c.client, c.basePath, func(info *querypb.SegmentInfo) bool {
return (p.CollectionID == 0 || info.CollectionID == p.CollectionID) &&
(p.SegmentID == 0 || info.SegmentID == p.SegmentID)
})
if err != nil {
return nil, errors.Wrap(err, "failed to list loaded segments")
}

segments, err := common.ListLoadedSegments(cli, basePath, func(info *querypb.SegmentInfo) bool {
return (collID == 0 || info.CollectionID == collID) &&
(segmentID == 0 || info.SegmentID == segmentID)
})
if err != nil {
fmt.Println("failed to list segments", err.Error())
return nil
}
return framework.NewListResult[LoadedSegments](segments), nil
}

for _, info := range segments {
fmt.Printf("Segment ID: %d LegacyNodeID: %d NodeIds: %v,DmlChannel: %s\n", info.SegmentID, info.NodeID, info.NodeIds, info.DmChannel)
fmt.Printf("%#v\n", info.GetIndexInfos())
}
type LoadedSegments struct {
framework.ListResultSet[querypb.SegmentInfo]
}

return nil
},
func (rs *LoadedSegments) PrintAs(format framework.Format) string {
switch format {
case framework.FormatDefault, framework.FormatPlain:
builder := &strings.Builder{}
for _, info := range rs.Data {
fmt.Fprintf(builder, "Segment ID: %d LegacyNodeID: %d NodeIds: %v,DmlChannel: %s\n", info.SegmentID, info.NodeID, info.NodeIds, info.DmChannel)
fmt.Fprintf(builder, "%#v\n", info.GetIndexInfos())
}
return builder.String()
default:
}
cmd.Flags().Int64("collection", 0, "collection id to filter with")
cmd.Flags().String("format", "line", "segment display format")
cmd.Flags().Bool("detail", false, "flags indicating whether pring detail binlog info")
cmd.Flags().Int64("segment", 0, "segment id to filter with")
return cmd
return ""
}

0 comments on commit 9986cdd

Please sign in to comment.