Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore: fix restore index bug in type check #512

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions core/restore/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,13 @@ func (ct *CollectionTask) createIndex(ctx context.Context) error {
ct.logger.Info("skip restore index")
return nil
}
ct.logger.Info("start restore index")

vectorFields := make(map[string]struct{})
for _, field := range ct.task.GetCollBackup().GetSchema().GetFields() {
typStr, ok := schemapb.DataType_name[int32(field.DataType)]
if ok {
return fmt.Errorf("restore_collection: failed to get field type: %s", typStr)
if !ok {
return fmt.Errorf("restore_collection: invalid field data type %d", field.DataType)
}

if strings.HasSuffix(strings.ToLower(typStr), "vector") {
Expand All @@ -388,16 +389,58 @@ func (ct *CollectionTask) createIndex(ctx context.Context) error {
}

indexes := ct.task.GetCollBackup().GetIndexInfos()
var vectorIndexes, scalarIndexes []*backuppb.IndexInfo
for _, index := range indexes {
log.Info("source index", zap.String("index_name", index.GetIndexName()),
if _, ok := vectorFields[index.GetFieldName()]; ok {
vectorIndexes = append(vectorIndexes, index)
} else {
scalarIndexes = append(scalarIndexes, index)
}
}

if err := ct.restoreVectorFieldIdx(ctx, vectorIndexes); err != nil {
return fmt.Errorf("restore_collection: restore vector field index: %w", err)
}
if err := ct.restoreScalarFieldIdx(ctx, scalarIndexes); err != nil {
return fmt.Errorf("restore_collection: restore scalar field index: %w", err)
}

return nil
}

func (ct *CollectionTask) restoreScalarFieldIdx(ctx context.Context, indexes []*backuppb.IndexInfo) error {
for _, index := range indexes {
ct.logger.Info("source index",
zap.String("indexName", index.GetIndexName()),
zap.Any("params", index.GetParams()))

opt := client.CreateIndexInput{
DB: ct.task.GetTargetDbName(),
CollectionName: ct.task.GetTargetCollectionName(),
FieldName: index.GetFieldName(),
IndexName: index.GetIndexName(),
Params: index.GetParams(),
}
if err := ct.grpcCli.CreateIndex(ctx, opt); err != nil {
return fmt.Errorf("restore_collection: restore scalar idx %s: %w", index.GetIndexName(), err)
}
}

return nil
}

func (ct *CollectionTask) restoreVectorFieldIdx(ctx context.Context, indexes []*backuppb.IndexInfo) error {
for _, index := range indexes {
ct.logger.Info("source index",
zap.String("indexName", index.GetIndexName()),
zap.Any("params", index.GetParams()))

params := make(map[string]string)
if _, ok := vectorFields[index.GetFieldName()]; ok && ct.task.GetUseAutoIndex() {
log.Info("use auto index")
if ct.task.GetUseAutoIndex() {
ct.logger.Info("use auto index", zap.String("fieldName", index.GetFieldName()))
params = map[string]string{"index_type": "AUTOINDEX", "metric_type": index.GetParams()["metric_type"]}
} else {
log.Info("use source index")
ct.logger.Info("use source index", zap.String("fieldName", index.GetFieldName()))
params = index.GetParams()
if params["index_type"] == "marisa-trie" {
params["index_type"] = "Trie"
Expand All @@ -412,7 +455,7 @@ func (ct *CollectionTask) createIndex(ctx context.Context) error {
Params: params,
}
if err := ct.grpcCli.CreateIndex(ctx, opt); err != nil {
return fmt.Errorf("restore_collection: failed to create index %s: %w", index.GetIndexName(), err)
return fmt.Errorf("restore_collection: restore vec idx %s: %w", index.GetIndexName(), err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/uber/jaeger-client-go v2.30.0+incompatible
go.uber.org/atomic v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
golang.org/x/oauth2 v0.24.0
golang.org/x/sync v0.10.0
golang.org/x/time v0.8.0
Expand Down Expand Up @@ -119,7 +120,6 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.12.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
Expand Down
Loading