Skip to content

Commit 4d4d800

Browse files
committed
Expose APIs that can be used outside Dgraph
1 parent 8231fae commit 4d4d800

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

dgraphtest/local_cluster.go

-5
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,6 @@ func (c *LocalCluster) containerHealthCheck(url func(c *LocalCluster) (string, e
556556
for i := 0; i < 60; i++ {
557557
time.Sleep(waitDurBeforeRetry)
558558

559-
endpoint, err = url(c)
560-
if err != nil {
561-
return errors.Wrap(err, "error getting health URL")
562-
}
563-
564559
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
565560
if err != nil {
566561
log.Printf("[WARNING] error building req for endpoint [%v], err: [%v]", endpoint, err)

edgraph/server.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func validateAlterOperation(ctx context.Context, op *api.Operation) error {
246246
if !isMutationAllowed(ctx) {
247247
return errors.Errorf("No mutations allowed by server.")
248248
}
249+
249250
if _, err := hasAdminAuth(ctx, "Alter"); err != nil {
250251
glog.Warningf("Alter denied with error: %v\n", err)
251252
return err
@@ -1579,7 +1580,7 @@ func parseRequest(ctx context.Context, qc *queryContext) error {
15791580
// parsing mutations
15801581
qc.gmuList = make([]*dql.Mutation, 0, len(qc.req.Mutations))
15811582
for _, mu := range qc.req.Mutations {
1582-
gmu, err := parseMutationObject(mu, qc)
1583+
gmu, err := ParseMutationObject(mu, qc.graphql)
15831584
if err != nil {
15841585
return err
15851586
}
@@ -1930,12 +1931,12 @@ func hasPoormansAuth(ctx context.Context) error {
19301931
return nil
19311932
}
19321933

1933-
// parseMutationObject tries to consolidate fields of the api.Mutation into the
1934+
// ParseMutationObject tries to consolidate fields of the api.Mutation into the
19341935
// corresponding field of the returned dql.Mutation. For example, the 3 fields,
19351936
// api.Mutation#SetJson, api.Mutation#SetNquads and api.Mutation#Set are consolidated into the
19361937
// dql.Mutation.Set field. Similarly the 3 fields api.Mutation#DeleteJson, api.Mutation#DelNquads
19371938
// and api.Mutation#Del are merged into the dql.Mutation#Del field.
1938-
func parseMutationObject(mu *api.Mutation, qc *queryContext) (*dql.Mutation, error) {
1939+
func ParseMutationObject(mu *api.Mutation, isGraphql bool) (*dql.Mutation, error) {
19391940
res := &dql.Mutation{Cond: mu.Cond}
19401941

19411942
if len(mu.SetJson) > 0 {
@@ -1979,7 +1980,7 @@ func parseMutationObject(mu *api.Mutation, qc *queryContext) (*dql.Mutation, err
19791980
return nil, err
19801981
}
19811982

1982-
if err := validateNQuads(res.Set, res.Del, qc); err != nil {
1983+
if err := validateNQuads(res.Set, res.Del, isGraphql); err != nil {
19831984
return nil, err
19841985
}
19851986
return res, nil
@@ -2015,8 +2016,7 @@ func validateForGraphql(nq *api.NQuad, isGraphql bool) error {
20152016
return nil
20162017
}
20172018

2018-
func validateNQuads(set, del []*api.NQuad, qc *queryContext) error {
2019-
2019+
func validateNQuads(set, del []*api.NQuad, isGraphql bool) error {
20202020
for _, nq := range set {
20212021
if err := validatePredName(nq.Predicate); err != nil {
20222022
return err
@@ -2031,7 +2031,7 @@ func validateNQuads(set, del []*api.NQuad, qc *queryContext) error {
20312031
if err := validateKeys(nq); err != nil {
20322032
return errors.Wrapf(err, "key error: %+v", nq)
20332033
}
2034-
if err := validateForGraphql(nq, qc.graphql); err != nil {
2034+
if err := validateForGraphql(nq, isGraphql); err != nil {
20352035
return err
20362036
}
20372037
}
@@ -2046,7 +2046,7 @@ func validateNQuads(set, del []*api.NQuad, qc *queryContext) error {
20462046
if nq.Subject == x.Star || (nq.Predicate == x.Star && !ostar) {
20472047
return errors.Errorf("Only valid wildcard delete patterns are 'S * *' and 'S P *': %v", nq)
20482048
}
2049-
if err := validateForGraphql(nq, qc.graphql); err != nil {
2049+
if err := validateForGraphql(nq, isGraphql); err != nil {
20502050
return err
20512051
}
20522052
// NOTE: we dont validateKeys() with delete to let users fix existing mistakes

query/mutation.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,8 @@ func verifyUid(ctx context.Context, uid uint64) error {
151151
}
152152
}
153153

154-
// AssignUids tries to assign unique ids to each identity in the subjects and objects in the
155-
// format of _:xxx. An identity, e.g. _:a, will only be assigned one uid regardless how many times
156-
// it shows up in the subjects or objects
157-
func AssignUids(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64, error) {
154+
func ExtractBlankUIDs(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64, error) {
158155
newUids := make(map[string]uint64)
159-
num := &pb.Num{}
160156
var err error
161157
for _, gmu := range gmuList {
162158
for _, nq := range gmu.Set {
@@ -192,8 +188,19 @@ func AssignUids(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64
192188
}
193189
}
194190

195-
num.Val = uint64(len(newUids))
196-
num.Type = pb.Num_UID
191+
return newUids, nil
192+
}
193+
194+
// AssignUids tries to assign unique ids to each identity in the subjects and objects in the
195+
// format of _:xxx. An identity, e.g. _:a, will only be assigned one uid regardless how many times
196+
// it shows up in the subjects or objects
197+
func AssignUids(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64, error) {
198+
newUids, err := ExtractBlankUIDs(ctx, gmuList)
199+
if err != nil {
200+
return newUids, err
201+
}
202+
203+
num := &pb.Num{Val: uint64(len(newUids)), Type: pb.Num_UID}
197204
if int(num.Val) > 0 {
198205
var res *pb.AssignedIds
199206
// TODO: Optimize later by prefetching. Also consolidate all the UID requests into a single

worker/server_state.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func InitServerState() {
7777
State.FinishCh = make(chan struct{})
7878
State.needTs = make(chan tsReq, 100)
7979

80-
State.initStorage()
80+
State.InitStorage()
8181
go State.fillTimestampRequests()
8282

8383
groupId, err := x.ReadGroupIdFile(Config.PostingDir)
@@ -103,7 +103,7 @@ func setBadgerOptions(opt badger.Options) badger.Options {
103103
return opt
104104
}
105105

106-
func (s *ServerState) initStorage() {
106+
func (s *ServerState) InitStorage() {
107107
var err error
108108

109109
if x.WorkerConfig.EncryptionKey != nil {

0 commit comments

Comments
 (0)