diff --git a/loader/loader.go b/loader/loader.go index 5fa1e7999b5649a56602333a066c5fddb86e4190..a3953e117f18bbd86f2258d263f0c1def688442d 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -144,48 +144,40 @@ func (s *state) handleNQuads(wg *sync.WaitGroup) { wg.Done() } +func (s *state) getUidForString(str string) { + _, err := rdf.GetUid(str, s.instanceIdx, s.numInstances) + for err != nil { + // Just put in a retry loop to tackle temporary errors. + if err == posting.E_TMP_ERROR { + time.Sleep(time.Microsecond) + glog.WithError(err).WithField("nq.Subject", str). + Error("Temporary error") + } else { + glog.WithError(err).WithField("nq.Subject", str). + Error("While getting UID") + return + } + _, err = rdf.GetUid(str, s.instanceIdx, s.numInstances) + } +} + func (s *state) handleNQuadsWhileAssign(wg *sync.WaitGroup) { for nq := range s.cnq { if farm.Fingerprint64([]byte(nq.Subject))%s.numInstances != s.instanceIdx { // This instance shouldnt assign UID to this string atomic.AddUint64(&s.ctr.ignored, 1) } else { - _, err := rdf.GetUid(nq.Subject, s.instanceIdx, s.numInstances) - for err != nil { - // Just put in a retry loop to tackle temporary errors. - if err == posting.E_TMP_ERROR { - time.Sleep(time.Microsecond) - glog.WithError(err).WithField("nq.Subject", nq.Subject). - Error("Temporary error") - } else { - glog.WithError(err).WithField("nq.Subject", nq.Subject). - Error("While getting UID") - return - } - _, err = rdf.GetUid(nq.Subject, s.instanceIdx, s.numInstances) - } + s.getUidForString(nq.Subject) } if len(nq.ObjectId) == 0 || farm.Fingerprint64([]byte(nq.ObjectId))%s.numInstances != s.instanceIdx { // This instance shouldnt or cant assign UID to this string atomic.AddUint64(&s.ctr.ignored, 1) } else { - _, err := rdf.GetUid(nq.ObjectId, s.instanceIdx, s.numInstances) - for err != nil { - // Just put in a retry loop to tackle temporary errors. - if err == posting.E_TMP_ERROR { - time.Sleep(time.Microsecond) - glog.WithError(err).WithField("nq.Subject", nq.Subject). - Error("Temporary error") - } else { - glog.WithError(err).WithField("nq.ObjectId", nq.ObjectId). - Error("While getting UID") - return - } - _, err = rdf.GetUid(nq.ObjectId, s.instanceIdx, s.numInstances) - } + s.getUidForString(nq.ObjectId) } } + wg.Done() } diff --git a/query/query.go b/query/query.go index 3ee69a2adc97c2a498620dc099bbe7d0abaa4712..4d2e28fe5d8e352c6fca59296918fc833b84fd58 100644 --- a/query/query.go +++ b/query/query.go @@ -255,7 +255,7 @@ func NewGraph(euid uint64, exid string) (*SubGraph, error) { // This would set the Result field in SubGraph, // and populate the children for attributes. if len(exid) > 0 { - u, err := uid.GetOrAssign(exid, 0, 1) // mod = 0, numInstances = 1 by default + u, err := uid.GetOrAssign(exid, 0, 1) // instanceIdx = 0, numInstances = 1 by default if err != nil { x.Err(glog, err).WithField("xid", exid).Error( "While GetOrAssign uid from external id")