Current Behavior
states/etcd/repair/index_metric.go:
func writeRepairedIndex(cli kv.MetaKV, basePath string, index *indexpb.FieldIndex) error {
p := path.Join(basePath, fmt.Sprintf("field-index/%d/%d", index.IndexInfo.CollectionID, index.IndexInfo.IndexID))
bs, err := proto.Marshal(index)
if err != nil {
fmt.Println("failed to marshal segment info", err.Error())
}
err = cli.Save(context.Background(), p, string(bs))
return err
}
There's no return after the marshal error is printed, so cli.Save runs anyway with whatever bs happens to be (empty on failure). If Save succeeds, the function returns nil, so the CLI reports success while it just overwrote the index metadata with an empty value.
Expected Behavior
A marshal failure should abort the write and return the error, not fall through to Save.
Steps To Reproduce
Call writeRepairedIndex with an index whose fields contain an invalid UTF-8 string in a proto3 string field (or any other input that makes proto.Marshal fail), and check the etcd key afterward. It gets set to an empty string and the function returns nil.
Environment
Any birdwatcher build, repair index_metric_type command.
Anything else?
The same pattern (fall through to Save after printing a marshal error instead of returning) also exists in writeRepairedSegment in states/etcd/repair/segment.go. That one is currently unreachable since its caller, RepairSegmentCommand, has its body fully commented out and just returns nil, but it's worth fixing at the same time if that command ever gets finished.
Current Behavior
states/etcd/repair/index_metric.go:There's no
returnafter the marshal error is printed, socli.Saveruns anyway with whateverbshappens to be (empty on failure). IfSavesucceeds, the function returnsnil, so the CLI reports success while it just overwrote the index metadata with an empty value.Expected Behavior
A marshal failure should abort the write and return the error, not fall through to
Save.Steps To Reproduce
Call
writeRepairedIndexwith an index whose fields contain an invalid UTF-8 string in a proto3 string field (or any other input that makesproto.Marshalfail), and check the etcd key afterward. It gets set to an empty string and the function returnsnil.Environment
Any birdwatcher build,
repair index_metric_typecommand.Anything else?
The same pattern (fall through to
Saveafter printing a marshal error instead of returning) also exists inwriteRepairedSegmentinstates/etcd/repair/segment.go. That one is currently unreachable since its caller,RepairSegmentCommand, has its body fully commented out and just returnsnil, but it's worth fixing at the same time if that command ever gets finished.