Skip to content
Snippets Groups Projects
Commit 749b981d authored by Manish R Jain's avatar Manish R Jain
Browse files

Handle absense of mutation or query in GraphQL. Fix bugs in goroutine's...

Handle absense of mutation or query in GraphQL. Fix bugs in goroutine's variable access, and pointer assignment to mutationArray.
parent 520e8560
No related branches found
No related tags found
No related merge requests found
......@@ -88,6 +88,7 @@ func mutationHandler(mu *gql.Mutation) error {
}
}
if err := worker.GetOrAssignUidsOverNetwork(&xidToUid); err != nil {
glog.WithError(err).Error("GetOrAssignUidsOverNetwork")
return err
}
......@@ -143,7 +144,20 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
x.SetStatus(w, x.E_INVALID_REQUEST, err.Error())
return
}
mutationHandler(mu)
// If we have mutations, run them first.
if mu != nil && len(mu.Set) > 0 {
if err = mutationHandler(mu); err != nil {
glog.WithError(err).Error("While handling mutations.")
x.SetStatus(w, x.E_ERROR, err.Error())
return
}
}
if gq == nil || (gq.UID == 0 && len(gq.XID) == 0) {
x.SetStatus(w, x.E_OK, "Done")
return
}
sg, err := query.ToSubGraph(gq)
if err != nil {
......@@ -204,6 +218,10 @@ func main() {
addrs := strings.Split(*workers, ",")
lenAddr := uint64(len(addrs))
if lenAddr == 0 {
// If no worker is specified, then we're it.
lenAddr = 1
}
posting.Init(clog)
......
package worker
import (
"fmt"
"sync"
"github.com/dgraph-io/dgraph/conn"
......@@ -33,6 +34,10 @@ func createXidListBuffer(xids map[string]uint64) []byte {
func getOrAssignUids(
xidList *task.XidList) (uidList []byte, rerr error) {
if xidList.XidsLength() == 0 {
return uidList, fmt.Errorf("Empty xid list")
}
wg := new(sync.WaitGroup)
uids := make([]uint64, xidList.XidsLength())
che := make(chan error, xidList.XidsLength())
......@@ -40,15 +45,15 @@ func getOrAssignUids(
wg.Add(1)
xid := string(xidList.Xids(i))
go func() {
go func(idx int) {
defer wg.Done()
u, err := uid.GetOrAssign(xid, 0, 1)
if err != nil {
che <- err
return
}
uids[i] = u
}()
uids[idx] = u
}(i)
}
wg.Wait()
close(che)
......
......@@ -42,6 +42,7 @@ func mutate(m *Mutations, left *Mutations) error {
return fmt.Errorf("predicate fingerprint doesn't match this instance.")
}
glog.WithField("edge", edge).Debug("mutate")
key := posting.Key(edge.Entity, edge.Attribute)
plist := posting.GetOrCreate(key, dataStore)
if err := plist.AddMutation(edge, posting.Set); err != nil {
......@@ -93,6 +94,7 @@ func MutateOverNetwork(
mu := mutationArray[idx]
if mu == nil {
mu = new(Mutations)
mutationArray[idx] = mu
}
mu.Set = append(mu.Set, edge)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment