Skip to content

Commit e893711

Browse files
author
Harshil Goel
committed
Fixed comments
1 parent 3b32245 commit e893711

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

posting/list_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ func TestReadSingleValue(t *testing.T) {
480480
require.NoError(t, err)
481481
checkValue(t, ol, string(k.Postings[0].Value), uint64(j))
482482
}
483-
484483
}
485484
}
486485

posting/lists.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -195,24 +195,35 @@ func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error)
195195
return lc.SetIfAbsent(skey, pl), nil
196196
}
197197

198+
// GetSinglePosting retrieves the cached version of the first item in the list associated with the
199+
// given key. This is used for retrieving the value of a scalar predicats.
198200
func (lc *LocalCache) GetSinglePosting(key []byte) (*pb.PostingList, error) {
201+
getDeltas := func() *pb.PostingList {
202+
lc.RLock()
203+
defer lc.RUnlock()
199204

200-
getPostings := func() (*pb.PostingList, error) {
201205
pl := &pb.PostingList{}
202-
lc.RLock()
203206
if delta, ok := lc.deltas[string(key)]; ok && len(delta) > 0 {
204207
err := pl.Unmarshal(delta)
205208
if err != nil {
206-
lc.RUnlock()
207-
return pl, nil
209+
return pl
208210
}
209211
}
210-
lc.RUnlock()
211212

213+
return nil
214+
}
215+
216+
getPostings := func() (*pb.PostingList, error) {
217+
pl := getDeltas()
218+
if pl != nil {
219+
return pl, nil
220+
}
221+
222+
pl = &pb.PostingList{}
212223
txn := pstore.NewTransactionAt(lc.startTs, false)
213224
item, err := txn.Get(key)
214225
if err != nil {
215-
return pl, err
226+
return nil, err
216227
}
217228

218229
err = item.Value(func(val []byte) error {
@@ -227,10 +238,10 @@ func (lc *LocalCache) GetSinglePosting(key []byte) (*pb.PostingList, error) {
227238

228239
pl, err := getPostings()
229240
if err == badger.ErrKeyNotFound {
230-
err = nil
241+
return nil, nil
231242
}
232243
if err != nil {
233-
return pl, err
244+
return nil, err
234245
}
235246

236247
// Filter and remove STAR_ALL and OP_DELETE Postings

worker/task.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,14 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
376376

377377
outputs := make([]*pb.Result, numGo)
378378
listType := schema.State().IsList(q.Attr)
379+
380+
// These are certain special cases where we can get away with reading only the latest value
381+
// Lang doesn't work because we would be storing various different languages at various
382+
// time. So when we go to read the latest value, we might get a different language.
383+
// Similarly with DoCount and ExpandAll and Facets. List types are also not supported
384+
// because list is stored by time, and we combine all the list items at various timestamps.
379385
hasLang := schema.State().HasLang(q.Attr)
380-
getMultiplePosting := q.DoCount || q.ExpandAll || listType || hasLang
381-
//getMultiplePosting := true
386+
getMultiplePosting := q.DoCount || q.ExpandAll || listType || hasLang || q.FacetParam != nil
382387

383388
calculate := func(start, end int) error {
384389
x.AssertTrue(start%width == 0)
@@ -399,7 +404,10 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
399404
fcs := &pb.FacetsList{FacetsList: make([]*pb.Facets, 0)} // TODO Figure out how it is stored
400405

401406
if !getMultiplePosting {
402-
pl, _ := qs.cache.GetSinglePosting(key)
407+
pl, err := qs.cache.GetSinglePosting(key)
408+
if err != nil {
409+
return err
410+
}
403411
if pl == nil || len(pl.Postings) == 0 {
404412
out.UidMatrix = append(out.UidMatrix, &pb.List{})
405413
out.FacetMatrix = append(out.FacetMatrix, &pb.FacetsList{})
@@ -413,11 +421,6 @@ func (qs *queryState) handleValuePostings(ctx context.Context, args funcArgs) er
413421
Tid: types.TypeID(p.ValType),
414422
Value: p.Value,
415423
}
416-
417-
// TODO Apply facet tree before
418-
if q.FacetParam != nil {
419-
fcs.FacetsList = append(fcs.FacetsList, &pb.Facets{Facets: facets.CopyFacets(p.Facets, q.FacetParam)})
420-
}
421424
}
422425
} else {
423426
pl, err := qs.cache.Get(key)

0 commit comments

Comments
 (0)