MCPcopy
hub / github.com/dgraph-io/dgraph / BumpTo

Method BumpTo

xidmap/xidmap.go:307–359  ·  view source on GitHub ↗

BumpTo can be used to make Zero allocate UIDs up to this given number. Attempts are made to ensure all future allocations of UIDs be higher than this one, but results are not guaranteed.

(uid uint64)

Source from the content-addressed store, hash-verified

305// BumpTo can be used to make Zero allocate UIDs up to this given number. Attempts are made to
306// ensure all future allocations of UIDs be higher than this one, but results are not guaranteed.
307func (m *XidMap) BumpTo(uid uint64) {
308 // If we have a cluster that cannot lease out new UIDs because it has already leased upto its
309 // max limit. Now, we try to live load the data with the given UIDs and the AssignIds complains
310 // that the limit has reached. Hence, update the xidmap's maxSeenUid and make progress.
311 updateLease := func(msg string) {
312 if !strings.Contains(msg, "limit has reached. currMax:") {
313 return
314 }
315 matches := maxLeaseRegex.FindAllStringSubmatch(msg, 1)
316 if len(matches) == 0 {
317 return
318 }
319 maxUidLeased, err := strconv.ParseUint(matches[0][1], 10, 64)
320 if err != nil {
321 glog.Errorf("While parsing currMax %+v", err)
322 return
323 }
324 m.updateMaxSeen(maxUidLeased)
325 }
326
327 for {
328 curMax := atomic.LoadUint64(&m.maxUidSeen)
329 if uid <= curMax {
330 return
331 }
332 glog.V(1).Infof("Bumping up to %v", uid)
333 num := x.Max(uid-curMax, 1e4)
334 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
335 ctx = m.attachNamespace(ctx)
336
337 var err error
338 var assigned *pb.AssignedIds
339 if m.zc == nil {
340 assigned = &pb.AssignedIds{}
341 assigned.StartId, assigned.EndId, err = m.dg.AllocateUIDs(ctx, num)
342 } else {
343 assigned, err = m.zc.AssignIds(ctx, &pb.Num{Val: num, Type: pb.Num_UID})
344 }
345 cancel()
346 if err == nil {
347 glog.V(1).Infof("Requested bump: %d. Got assigned: %v", uid, assigned)
348 m.updateMaxSeen(assigned.EndId)
349 return
350 }
351 updateLease(err.Error())
352 glog.Errorf("While requesting AssignUids(%d): %v", num, err)
353 if x.IsJwtExpired(err) {
354 if err := m.relogin(); err != nil {
355 glog.Errorf("While trying to relogin: %v", err)
356 }
357 }
358 }
359}
360
361// AllocateUid gives a single uid without creating an xid to uid mapping.
362func (m *XidMap) AllocateUid() uint64 {

Callers 3

uidMethod · 0.80
allocateUidsMethod · 0.80
TestXidmapFunction · 0.80

Calls 9

updateMaxSeenMethod · 0.95
attachNamespaceMethod · 0.95
reloginMethod · 0.95
MaxFunction · 0.92
IsJwtExpiredFunction · 0.92
InfofMethod · 0.80
AssignIdsMethod · 0.65
ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by 1

TestXidmapFunction · 0.64