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

Function ProposalKey

x/x.go:659–671  ·  view source on GitHub ↗

{2 bytes Node ID} {4 bytes for random} {2 bytes zero}

(id uint64)

Source from the content-addressed store, hash-verified

657
658// {2 bytes Node ID} {4 bytes for random} {2 bytes zero}
659func ProposalKey(id uint64) (uint64, error) {
660 random4Bytes := make([]byte, 4)
661 if _, err := cryptorand.Read(random4Bytes); err != nil {
662 return 0, err
663 }
664 proposalKey := id<<48 | uint64(binary.BigEndian.Uint32(random4Bytes))<<16
665 // We want to avoid spillage to node id in case of overflow. For instance, if the
666 // random bytes end up being [xx,xx, 255, 255, 255, 255, 0 , 0] (xx, xx being the node id)
667 // we would spill to node id after 65535 calls to unique key.
668 // So by setting 48th bit to 0 we ensure that we never spill out to node ids.
669 proposalKey &= ^(uint64(1) << 47)
670 return proposalKey, nil
671}
672
673// HasString returns whether the slice contains the given string.
674func HasString(a []string, b string) bool {

Callers 2

initProposalKeyMethod · 0.92
initProposalKeyFunction · 0.92

Calls 1

ReadMethod · 0.65

Tested by

no test coverage detected