Skip to content

[Bug]: repair index_metric_type writes an empty value to etcd if proto.Marshal fails, instead of aborting #515

Description

@lokeshramchand-ctrl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions