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

Function uidToVal

dgraph/cmd/debug/run.go:126–172  ·  view source on GitHub ↗
(itr *badger.Iterator, prefix string)

Source from the content-addressed store, hash-verified

124}
125
126func uidToVal(itr *badger.Iterator, prefix string) map[uint64]int {
127 keys := make(map[uint64]int)
128 var lastKey []byte
129 for itr.Rewind(); itr.Valid(); {
130 item := itr.Item()
131 if bytes.Equal(lastKey, item.Key()) {
132 itr.Next()
133 continue
134 }
135 lastKey = append(lastKey[:0], item.Key()...)
136 pk, err := x.Parse(item.Key())
137 x.Check(err)
138 if !pk.IsData() || !strings.HasPrefix(x.ParseAttr(pk.Attr), prefix) {
139 continue
140 }
141 if pk.IsSchema() {
142 continue
143 }
144 if pk.StartUid > 0 {
145 // This key is part of a multi-part posting list. Skip it and only read
146 // the main key, which is the entry point to read the whole list.
147 continue
148 }
149
150 pl, err := posting.ReadPostingList(item.KeyCopy(nil), itr)
151 if err != nil {
152 log.Fatalf("Unable to read posting list: %v", err)
153 }
154 err = pl.Iterate(math.MaxUint64, 0, func(o *pb.Posting) error {
155 from := types.Val{
156 Tid: types.TypeID(o.ValType),
157 Value: o.Value,
158 }
159 out, err := types.Convert(from, types.StringID)
160 x.Check(err)
161 key := out.Value.(string)
162 k, err := strconv.Atoi(key)
163 x.Check(err)
164 keys[pk.Uid] = k
165 // fmt.Printf("Type: %v Uid=%d key=%s. commit=%d hex %x\n",
166 // o.ValType, pk.Uid, key, o.CommitTs, lastKey)
167 return nil
168 })
169 x.Checkf(err, "during iterate")
170 }
171 return keys
172}
173
174func seekTotal(db *badger.DB, readTs uint64) int {
175 txn := db.NewTransactionAt(readTs, false)

Callers 1

seekTotalFunction · 0.85

Calls 15

ParseFunction · 0.92
CheckFunction · 0.92
ParseAttrFunction · 0.92
ReadPostingListFunction · 0.92
TypeIDTypeAlias · 0.92
ConvertFunction · 0.92
CheckfFunction · 0.92
ValidMethod · 0.80
ItemMethod · 0.80
IsDataMethod · 0.80
IsSchemaMethod · 0.80
FatalfMethod · 0.80

Tested by

no test coverage detected