MCPcopy
hub / github.com/dgraph-io/dgraph / needsVectorIndexEdgesRebuild

Method needsVectorIndexEdgesRebuild

posting/index.go:1642–1692  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1640}
1641
1642func (rb *IndexRebuild) needsVectorIndexEdgesRebuild() indexOp {
1643 x.AssertTruef(rb.CurrentSchema != nil, "Current schema cannot be nil.")
1644
1645 // If old schema is nil, treat it as an empty schema. Copy it to avoid
1646 // overwriting it in rb.
1647 old := rb.OldSchema
1648 if old == nil {
1649 old = &pb.SchemaUpdate{}
1650 }
1651
1652 currIndex := rb.CurrentSchema.Directive == pb.SchemaUpdate_INDEX &&
1653 rb.CurrentSchema.ValueType == pb.Posting_VFLOAT
1654 prevIndex := old.Directive == pb.SchemaUpdate_INDEX &&
1655 old.ValueType == pb.Posting_VFLOAT
1656
1657 prevFactoryNames := make(map[string]struct{})
1658 prevFactories := make(map[string]*pb.VectorIndexSpec)
1659 for _, t := range old.IndexSpecs {
1660 spec, err := tok.GetFactoryCreateSpecFromSpec(t)
1661 x.AssertTruef(err == nil, "Error while building index spec %s", err)
1662 name := spec.Name()
1663
1664 prevFactoryNames[name] = struct{}{}
1665 prevFactories[name] = t
1666 }
1667
1668 currFactoryNames := make(map[string]struct{})
1669 currFactories := make(map[string]*pb.VectorIndexSpec)
1670 for _, t := range rb.CurrentSchema.IndexSpecs {
1671 spec, err := tok.GetFactoryCreateSpecFromSpec(t)
1672 x.AssertTruef(err == nil, "Error while building index spec %s", err)
1673 name := spec.Name()
1674
1675 currFactoryNames[name] = struct{}{}
1676 currFactories[name] = t
1677 }
1678
1679 newFactoryNames, deletedFactoryNames := x.Diff(currFactoryNames, prevFactoryNames)
1680
1681 // If the schema directive did not change, return indexNoop.
1682 if currIndex == prevIndex && len(newFactoryNames) == 0 && len(deletedFactoryNames) == 0 {
1683 return indexNoop
1684 }
1685
1686 // If the current schema requires an index, index should be rebuilt.
1687 if currIndex || len(newFactoryNames) != 0 {
1688 return indexRebuild
1689 }
1690 // Otherwise, index should only be deleted.
1691 return indexDelete
1692}
1693
1694// This needs to be moved to the implementation of vector-indexer API
1695func prefixesToDropVectorIndexEdges(ctx context.Context, rb *IndexRebuild) [][]byte {

Callers 1

Calls 4

AssertTruefFunction · 0.92
DiffFunction · 0.92
NameMethod · 0.65

Tested by

no test coverage detected