-
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: Add
repair legacy-collection-remnant
command (#270)
See also milvus-io/milvus#33608 Command removes collection with no field to fix the bug in previously mentioned issue Signed-off-by: Congqi Xia <[email protected]>
- Loading branch information
Showing
4 changed files
with
90 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package repair | ||
|
||
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" | ||
) | ||
|
||
type CollectionLegacyDroppedParams struct { | ||
framework.ParamBase `use:"repair legacy-collection-remnant"` | ||
CollectionID int64 `name:""` | ||
Run bool `name:"run" default:"false" desc:"whether to remove legacy collection meta, default set to \"false\" to dry run"` | ||
} | ||
|
||
func (c *ComponentRepair) CollectionLegacyDroppedCommand(ctx context.Context, p *CollectionLegacyDroppedParams) error { | ||
collections, err := common.ListCollectionsVersion(ctx, c.client, c.basePath, etcdversion.GetVersion(), func(coll *models.Collection) bool { | ||
fmt.Println(coll.Key()) | ||
return coll.DBID == 0 && len(coll.Schema.Fields) == 0 && (p.CollectionID == 0 || p.CollectionID == coll.ID) | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
var removed int | ||
for _, collection := range collections { | ||
fmt.Printf("collection [%d]%s is suspect of legacy collection remnant\n", collection.ID, collection.Schema.Name) | ||
if p.Run { | ||
key := collection.Key() | ||
fmt.Printf("start to remove remnant meta for %s, key:%s\n", collection.Schema.Name, key) | ||
_, err := c.client.Delete(ctx, collection.Key()) | ||
if err != nil { | ||
fmt.Printf("failed to remove %s, error: %s\n", key, err.Error()) | ||
continue | ||
} | ||
fmt.Println("Removal done!") | ||
removed++ | ||
} | ||
} | ||
if len(collections) == 0 { | ||
fmt.Println("no suspect found") | ||
} else if removed > 0 { | ||
fmt.Println("Remnant meta removed, please restart rootcoord/mixtcord to check") | ||
} | ||
|
||
return nil | ||
} |
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,20 @@ | ||
package repair | ||
|
||
import ( | ||
"github.com/milvus-io/birdwatcher/configs" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
type ComponentRepair struct { | ||
client clientv3.KV | ||
config *configs.Config | ||
basePath string | ||
} | ||
|
||
func NewComponent(cli clientv3.KV, config *configs.Config, basePath string) *ComponentRepair { | ||
return &ComponentRepair{ | ||
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