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

Method AssignUid

xidmap/xidmap.go:252–285  ·  view source on GitHub ↗

AssignUid creates new or looks up existing XID to UID mappings. It also returns if UID was created.

(xid string)

Source from the content-addressed store, hash-verified

250// AssignUid creates new or looks up existing XID to UID mappings. It also returns if
251// UID was created.
252func (m *XidMap) AssignUid(xid string) (uint64, bool) {
253 sh := m.shardFor(xid)
254 sh.RLock()
255
256 uid := sh.tree.Get(farm.Fingerprint64([]byte(xid)))
257 sh.RUnlock()
258 if uid > 0 {
259 return uid, false
260 }
261
262 sh.Lock()
263 defer sh.Unlock()
264
265 uid = sh.tree.Get(farm.Fingerprint64([]byte(xid)))
266 if uid > 0 {
267 return uid, false
268 }
269
270 newUid := sh.assign(m.newRanges)
271 sh.tree.Set(farm.Fingerprint64([]byte(xid)), newUid)
272
273 if m.writer != nil {
274 var uidBuf [8]byte
275 binary.BigEndian.PutUint64(uidBuf[:], newUid)
276 m.kvBuf = append(m.kvBuf, kv{key: []byte(xid), value: uidBuf[:]})
277
278 if len(m.kvBuf) == 64 {
279 m.kvChan <- m.kvBuf
280 m.kvBuf = make([]kv, 0, 64)
281 }
282 }
283
284 return newUid, true
285}
286
287func (sh *shard) Current() uint64 {
288 sh.RLock()

Callers 8

lookupUidMethod · 0.80
uidMethod · 0.80
TestXidmapFunction · 0.80
TestXidmapMemoryFunction · 0.80
BenchmarkXidmapWritesFunction · 0.80
BenchmarkXidmapReadsFunction · 0.80

Calls 8

shardForMethod · 0.95
RLockMethod · 0.80
RUnlockMethod · 0.80
GetMethod · 0.65
SetMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
assignMethod · 0.45

Tested by 6

TestXidmapFunction · 0.64
TestXidmapMemoryFunction · 0.64
BenchmarkXidmapWritesFunction · 0.64
BenchmarkXidmapReadsFunction · 0.64