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

Function addToSchemaMap

worker/schema.go:122–158  ·  view source on GitHub ↗

addToSchemaMap groups the predicates by group id, if list of predicates is empty then it adds all known groups

(schemaMap map[uint32]*pb.SchemaRequest, schema *pb.SchemaRequest)

Source from the content-addressed store, hash-verified

120// addToSchemaMap groups the predicates by group id, if list of predicates is
121// empty then it adds all known groups
122func addToSchemaMap(schemaMap map[uint32]*pb.SchemaRequest, schema *pb.SchemaRequest) error {
123 for _, attr := range schema.Predicates {
124 gid, err := groups().BelongsToReadOnly(attr, 0)
125 if err != nil {
126 return err
127 }
128 if gid == 0 {
129 continue
130 }
131
132 s := schemaMap[gid]
133 if s == nil {
134 s = &pb.SchemaRequest{GroupId: gid}
135 s.Fields = schema.Fields
136 schemaMap[gid] = s
137 }
138 s.Predicates = append(s.Predicates, attr)
139 }
140 if len(schema.Predicates) > 0 {
141 return nil
142 }
143 // TODO: Janardhan - node shouldn't serve any request until membership
144 // information is synced, should we fail health check till then ?
145 gids := groups().KnownGroups()
146 for _, gid := range gids {
147 if gid == 0 {
148 continue
149 }
150 s := schemaMap[gid]
151 if s == nil {
152 s = &pb.SchemaRequest{GroupId: gid}
153 s.Fields = schema.Fields
154 schemaMap[gid] = s
155 }
156 }
157 return nil
158}
159
160// If the current node serves the group serve the schema or forward
161// to relevant node

Callers 1

GetSchemaOverNetworkFunction · 0.85

Calls 3

groupsFunction · 0.85
BelongsToReadOnlyMethod · 0.80
KnownGroupsMethod · 0.45

Tested by

no test coverage detected