diff --git a/edgraph/server.go b/edgraph/server.go index f5f3e51bfad..c7c6cb8fb90 100644 --- a/edgraph/server.go +++ b/edgraph/server.go @@ -246,6 +246,7 @@ func validateAlterOperation(ctx context.Context, op *api.Operation) error { if !isMutationAllowed(ctx) { return errors.Errorf("No mutations allowed by server.") } + if _, err := hasAdminAuth(ctx, "Alter"); err != nil { glog.Warningf("Alter denied with error: %v\n", err) return err @@ -1579,7 +1580,7 @@ func parseRequest(ctx context.Context, qc *queryContext) error { // parsing mutations qc.gmuList = make([]*dql.Mutation, 0, len(qc.req.Mutations)) for _, mu := range qc.req.Mutations { - gmu, err := parseMutationObject(mu, qc) + gmu, err := ParseMutationObject(mu, qc.graphql) if err != nil { return err } @@ -1930,12 +1931,12 @@ func hasPoormansAuth(ctx context.Context) error { return nil } -// parseMutationObject tries to consolidate fields of the api.Mutation into the +// ParseMutationObject tries to consolidate fields of the api.Mutation into the // corresponding field of the returned dql.Mutation. For example, the 3 fields, // api.Mutation#SetJson, api.Mutation#SetNquads and api.Mutation#Set are consolidated into the // dql.Mutation.Set field. Similarly the 3 fields api.Mutation#DeleteJson, api.Mutation#DelNquads // and api.Mutation#Del are merged into the dql.Mutation#Del field. -func parseMutationObject(mu *api.Mutation, qc *queryContext) (*dql.Mutation, error) { +func ParseMutationObject(mu *api.Mutation, isGraphql bool) (*dql.Mutation, error) { res := &dql.Mutation{Cond: mu.Cond} if len(mu.SetJson) > 0 { @@ -1979,7 +1980,7 @@ func parseMutationObject(mu *api.Mutation, qc *queryContext) (*dql.Mutation, err return nil, err } - if err := validateNQuads(res.Set, res.Del, qc); err != nil { + if err := validateNQuads(res.Set, res.Del, isGraphql); err != nil { return nil, err } return res, nil @@ -2015,8 +2016,7 @@ func validateForGraphql(nq *api.NQuad, isGraphql bool) error { return nil } -func validateNQuads(set, del []*api.NQuad, qc *queryContext) error { - +func validateNQuads(set, del []*api.NQuad, isGraphql bool) error { for _, nq := range set { if err := validatePredName(nq.Predicate); err != nil { return err @@ -2031,7 +2031,7 @@ func validateNQuads(set, del []*api.NQuad, qc *queryContext) error { if err := validateKeys(nq); err != nil { return errors.Wrapf(err, "key error: %+v", nq) } - if err := validateForGraphql(nq, qc.graphql); err != nil { + if err := validateForGraphql(nq, isGraphql); err != nil { return err } } @@ -2046,7 +2046,7 @@ func validateNQuads(set, del []*api.NQuad, qc *queryContext) error { if nq.Subject == x.Star || (nq.Predicate == x.Star && !ostar) { return errors.Errorf("Only valid wildcard delete patterns are 'S * *' and 'S P *': %v", nq) } - if err := validateForGraphql(nq, qc.graphql); err != nil { + if err := validateForGraphql(nq, isGraphql); err != nil { return err } // NOTE: we dont validateKeys() with delete to let users fix existing mistakes diff --git a/query/mutation.go b/query/mutation.go index 78846babb90..7fe7d54145a 100644 --- a/query/mutation.go +++ b/query/mutation.go @@ -151,12 +151,8 @@ func verifyUid(ctx context.Context, uid uint64) error { } } -// AssignUids tries to assign unique ids to each identity in the subjects and objects in the -// format of _:xxx. An identity, e.g. _:a, will only be assigned one uid regardless how many times -// it shows up in the subjects or objects -func AssignUids(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64, error) { +func ExtractBlankUIDs(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64, error) { newUids := make(map[string]uint64) - num := &pb.Num{} var err error for _, gmu := range gmuList { for _, nq := range gmu.Set { @@ -192,8 +188,19 @@ func AssignUids(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64 } } - num.Val = uint64(len(newUids)) - num.Type = pb.Num_UID + return newUids, nil +} + +// AssignUids tries to assign unique ids to each identity in the subjects and objects in the +// format of _:xxx. An identity, e.g. _:a, will only be assigned one uid regardless how many times +// it shows up in the subjects or objects +func AssignUids(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64, error) { + newUids, err := ExtractBlankUIDs(ctx, gmuList) + if err != nil { + return newUids, err + } + + num := &pb.Num{Val: uint64(len(newUids)), Type: pb.Num_UID} if int(num.Val) > 0 { var res *pb.AssignedIds // TODO: Optimize later by prefetching. Also consolidate all the UID requests into a single diff --git a/worker/server_state.go b/worker/server_state.go index d61d4817cd7..0e8ec5b0967 100644 --- a/worker/server_state.go +++ b/worker/server_state.go @@ -77,7 +77,7 @@ func InitServerState() { State.FinishCh = make(chan struct{}) State.needTs = make(chan tsReq, 100) - State.initStorage() + State.InitStorage() go State.fillTimestampRequests() groupId, err := x.ReadGroupIdFile(Config.PostingDir) @@ -103,7 +103,7 @@ func setBadgerOptions(opt badger.Options) badger.Options { return opt } -func (s *ServerState) initStorage() { +func (s *ServerState) InitStorage() { var err error if x.WorkerConfig.EncryptionKey != nil {