-
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.
enhance: Support
set collection consistency-level
command (#323)
Add command to update collection default consistency level Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
- Loading branch information
Showing
5 changed files
with
92 additions
and
20 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package set | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/cockroachdb/errors" | ||
|
||
"github.com/milvus-io/birdwatcher/framework" | ||
"github.com/milvus-io/birdwatcher/models" | ||
commonpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/commonpb" | ||
etcdpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/etcdpb" | ||
"github.com/milvus-io/birdwatcher/states/etcd/common" | ||
etcdversion "github.com/milvus-io/birdwatcher/states/etcd/version" | ||
) | ||
|
||
type CollectionConsistencyLevelParam struct { | ||
framework.ParamBase `use:"set collection consistency-level" desc:"set collection default consistency level"` | ||
CollectionID int64 `name:"collection" default:"0" desc:"collection id to update"` | ||
ConsistencyLevel string `name:"consistency-level" default:"" desc:"Consistency Level to set"` | ||
Run bool `name:"run" default:"false"` | ||
} | ||
|
||
func (c *ComponentSet) CollectionConsistencyLevelCommand(ctx context.Context, p *CollectionConsistencyLevelParam) error { | ||
levelVal, ok := commonpbv2.ConsistencyLevel_value[p.ConsistencyLevel] | ||
if !ok { | ||
return errors.Newf(`consistency level string "%s" is not valid`, p.ConsistencyLevel) | ||
} | ||
|
||
consistencyLevel := commonpbv2.ConsistencyLevel(levelVal) | ||
collection, err := common.GetCollectionByIDVersion(ctx, c.client, c.basePath, etcdversion.GetVersion(), p.CollectionID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if collection.ConsistencyLevel == models.ConsistencyLevel(consistencyLevel) { | ||
fmt.Printf("collection consistency level is already %s\n", p.ConsistencyLevel) | ||
return nil | ||
} | ||
|
||
return common.UpdateCollection(ctx, c.client, collection.Key(), func(coll *etcdpbv2.CollectionInfo) { | ||
coll.ConsistencyLevel = consistencyLevel | ||
}, p.Run) | ||
} |
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,21 @@ | ||
package set | ||
|
||
import ( | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
|
||
"github.com/milvus-io/birdwatcher/configs" | ||
) | ||
|
||
type ComponentSet struct { | ||
client clientv3.KV | ||
config *configs.Config | ||
basePath string | ||
} | ||
|
||
func NewComponent(cli clientv3.KV, config *configs.Config, basePath string) *ComponentSet { | ||
return &ComponentSet{ | ||
client: cli, | ||
config: config, | ||
basePath: basePath, | ||
} | ||
} |
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