MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / populateMutationMap

Function populateMutationMap

worker/mutation.go:690–746  ·  view source on GitHub ↗

populateMutationMap populates a map from group id to the mutation that should be sent to that group.

(src *pb.Mutations)

Source from the content-addressed store, hash-verified

688// populateMutationMap populates a map from group id to the mutation that
689// should be sent to that group.
690func populateMutationMap(src *pb.Mutations) (map[uint32]*pb.Mutations, error) {
691 mm := make(map[uint32]*pb.Mutations)
692 for _, edge := range src.Edges {
693 gid, err := groups().BelongsTo(edge.Attr)
694 if err != nil {
695 return nil, err
696 }
697
698 mu := mm[gid]
699 if mu == nil {
700 mu = &pb.Mutations{GroupId: gid}
701 mm[gid] = mu
702 }
703 mu.Edges = append(mu.Edges, edge)
704 mu.Metadata = src.Metadata
705 }
706
707 for _, schema := range src.Schema {
708 gid, err := groups().BelongsTo(schema.Predicate)
709 if err != nil {
710 return nil, err
711 }
712
713 mu := mm[gid]
714 if mu == nil {
715 mu = &pb.Mutations{GroupId: gid}
716 mm[gid] = mu
717 }
718 mu.Schema = append(mu.Schema, schema)
719 }
720
721 if src.DropOp > 0 {
722 for _, gid := range groups().KnownGroups() {
723 mu := mm[gid]
724 if mu == nil {
725 mu = &pb.Mutations{GroupId: gid}
726 mm[gid] = mu
727 }
728 mu.DropOp = src.DropOp
729 mu.DropValue = src.DropValue
730 }
731 }
732
733 // Type definitions are sent to all groups.
734 if len(src.Types) > 0 {
735 for _, gid := range groups().KnownGroups() {
736 mu := mm[gid]
737 if mu == nil {
738 mu = &pb.Mutations{GroupId: gid}
739 mm[gid] = mu
740 }
741 mu.Types = src.Types
742 }
743 }
744
745 return mm, nil
746}
747

Callers 2

TestPopulateMutationMapFunction · 0.85
MutateOverNetworkFunction · 0.85

Calls 3

groupsFunction · 0.85
BelongsToMethod · 0.80
KnownGroupsMethod · 0.45

Tested by 1

TestPopulateMutationMapFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…