Skip to content

Commit

Permalink
added static value
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Aug 7, 2024
1 parent 873fddf commit 1392aa1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
61 changes: 61 additions & 0 deletions posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,67 @@ func (l *List) GetLangTags(readTs uint64) ([]string, error) {
hex.EncodeToString(l.key))
}

func (l *List) getPosting(startTs uint64) *pb.PostingList {

Check failure on line 1396 in posting/list.go

View workflow job for this annotation

GitHub Actions / lint

func `(*List).getPosting` is unused (unused)
l.RLock()
defer l.RUnlock()
if pl, ok := l.mutationMap[startTs]; ok {
return pl
}
return nil
}

func (l *List) StaticValue(readTs uint64) (*pb.PostingList, error) {
l.RLock()
defer l.RUnlock()

return l.StaticValueWithLockHeld(readTs)
}

func (l *List) StaticValueWithLockHeld(readTs uint64) (*pb.PostingList, error) {
val, found, err := l.findStaticValue(readTs, math.MaxUint64)
if err != nil {
return val, errors.Wrapf(err,
"cannot retrieve default value from list with key %s", hex.EncodeToString(l.key))
}
if !found {
return val, ErrNoValue
}
return val, nil
}

func (l *List) findStaticValue(readTs, uid uint64) (*pb.PostingList, bool, error) {
l.AssertRLock()

mutation, ok := l.mutationMap[readTs]
if ok {
return mutation, true, nil
}

if l.maxTs < readTs {
mutation, ok = l.mutationMap[l.maxTs]
if ok {
return mutation, true, nil
}
}

if len(l.mutationMap) != 0 {
for ts, mutation_i := range l.mutationMap {
if ts <= readTs {
mutation = mutation_i
} else {
break
}
}
return mutation, true, nil
}

if len(l.plist.Postings) > 0 {
return l.plist, true, nil
}

return nil, false, nil
}

// Value returns the default value from the posting list. The default value is
// defined as the value without a language tag.
// Value cannot be used to read from cache
Expand Down
11 changes: 7 additions & 4 deletions posting/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,21 +327,24 @@ func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error)
func (lc *LocalCache) GetSinglePosting(key []byte) (*pb.PostingList, error) {
getList := func() *pb.PostingList {
lc.RLock()
defer lc.RUnlock()

pl := &pb.PostingList{}
if delta, ok := lc.deltas[string(key)]; ok && len(delta) > 0 {
err := pl.Unmarshal(delta)
if err == nil {
lc.RUnlock()
return pl
}
}

l := lc.plists[string(key)]
lc.RUnlock()

if l != nil {
// If the current transaction is updating it, read it from here.
// Otherwise read it from disk. TODO see if this can be fixed.
return l.mutationMap[lc.startTs]
pl, err := l.StaticValue(lc.startTs)
if err != nil {
return pl
}
}

return nil
Expand Down

0 comments on commit 1392aa1

Please sign in to comment.