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)
| 120 | // addToSchemaMap groups the predicates by group id, if list of predicates is |
| 121 | // empty then it adds all known groups |
| 122 | func 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 |
no test coverage detected