-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Congqi Xia <[email protected]>
- Loading branch information
Showing
4 changed files
with
151 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package models | ||
|
||
import ( | ||
etcdpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/etcdpb" | ||
) | ||
|
||
type Alias struct { | ||
Name string | ||
CollectionID int64 | ||
State AliasState | ||
CreateTS uint64 | ||
DBID int64 | ||
|
||
key string | ||
} | ||
|
||
func NewAlias(info *etcdpbv2.AliasInfo, key string) *Alias { | ||
a := &Alias{ | ||
Name: info.GetAliasName(), | ||
CollectionID: info.GetCollectionId(), | ||
State: AliasState(info.GetState()), | ||
CreateTS: info.GetCreatedTime(), | ||
DBID: info.GetDbId(), | ||
} | ||
return a | ||
} | ||
|
||
type AliasState int32 | ||
|
||
const ( | ||
AliasStateAliasCreated AliasState = 0 | ||
AliasStateAliasCreating AliasState = 1 | ||
AliasStateAliasDropping AliasState = 2 | ||
AliasStateAliasDropped AliasState = 3 | ||
) | ||
|
||
var AliasStateName = map[int32]string{ | ||
0: "AliasCreated", | ||
1: "AliasCreating", | ||
2: "AliasDropping", | ||
3: "AliasDropped", | ||
} | ||
|
||
var AliasStateValue = map[string]int32{ | ||
"AliasCreated": 0, | ||
"AliasCreating": 1, | ||
"AliasDropping": 2, | ||
"AliasDropped": 3, | ||
} | ||
|
||
func (x AliasState) String() string { | ||
return EnumName(AliasStateName, int32(x)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"path" | ||
|
||
"github.com/milvus-io/birdwatcher/models" | ||
etcdpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/etcdpb" | ||
"github.com/samber/lo" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
const ( | ||
// AliasPrefixBefore210 is the legacy meta prefix for milvus before 2.2.0 | ||
AliasPrefixBefore210 = `root-coord/collection-alias` | ||
|
||
// AliasPrefixWithoutDB is the meta prefix for alias before database. | ||
AliasPrefixWithoutDB = `root-coord/aliases` | ||
|
||
// AliasPrefixDB iis the meta prefix for alias with database feature | ||
AliasPrefixDB = `root-coord/database/alias` | ||
) | ||
|
||
func ListAliasVersion(ctx context.Context, cli clientv3.KV, basePath string, version string, filters ...func(*models.Alias) bool) ([]*models.Alias, error) { | ||
prefixes := []string{ | ||
path.Join(basePath, AliasPrefixWithoutDB), | ||
path.Join(basePath, AliasPrefixDB), | ||
} | ||
|
||
switch version { | ||
case models.GTEVersion2_2: | ||
var result []*models.Alias | ||
for _, prefix := range prefixes { | ||
infos, keys, err := ListProtoObjects[etcdpbv2.AliasInfo](ctx, cli, prefix) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
result = append(result, lo.FilterMap(infos, func(info etcdpbv2.AliasInfo, idx int) (*models.Alias, bool) { | ||
value := models.NewAlias(&info, keys[idx]) | ||
for _, filter := range filters { | ||
if !filter(value) { | ||
return nil, false | ||
} | ||
} | ||
return value, true | ||
})...) | ||
} | ||
|
||
return result, nil | ||
default: | ||
return nil, errors.New("not supported version") | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package show | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/milvus-io/birdwatcher/framework" | ||
"github.com/milvus-io/birdwatcher/models" | ||
"github.com/milvus-io/birdwatcher/states/etcd/common" | ||
etcdversion "github.com/milvus-io/birdwatcher/states/etcd/version" | ||
"github.com/samber/lo" | ||
) | ||
|
||
type AliasParam struct { | ||
framework.ParamBase `use:"show alias" desc:"list alias meta info" alias:"aliases"` | ||
DBID int64 `name:"dbid" default:"-1" desc:"database id to filter with"` | ||
} | ||
|
||
// AliasCommand implements `show alias` command. | ||
func (c *ComponentShow) AliasCommand(ctx context.Context, p *AliasParam) error { | ||
aliases, err := common.ListAliasVersion(ctx, c.client, c.basePath, etcdversion.GetVersion(), func(a *models.Alias) bool { | ||
return p.DBID == -1 || p.DBID == a.DBID | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
for dbid, aliases := range lo.GroupBy(aliases, func(a *models.Alias) int64 { return a.DBID }) { | ||
fmt.Println("==========================") | ||
fmt.Println("Database ID: ", dbid) | ||
for _, alias := range aliases { | ||
c.PrintAlias(alias) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *ComponentShow) PrintAlias(a *models.Alias) { | ||
fmt.Printf("Collection ID: %d\tAlias Name: %s\tState: %s\n", a.CollectionID, a.Name, a.State.String()) | ||
} |
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