-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'not supported' warning for legacy show segment-loaded command (#173
) Signed-off-by: Congqi Xia <[email protected]>
- Loading branch information
Showing
3 changed files
with
38 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" | ||
} |