Skip to content

Commit

Permalink
fixed another test
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Oct 18, 2024
1 parent f421501 commit 1dc6a9f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
11 changes: 10 additions & 1 deletion posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"encoding/hex"
"fmt"
"log"
"math"
"sort"
Expand Down Expand Up @@ -692,6 +693,7 @@ func GetConflictKey(pk x.ParsedKey, key []byte, t *pb.DirectedEdge) uint64 {
}

func (l *List) addMutationInternal(ctx context.Context, txn *Txn, t *pb.DirectedEdge) error {
fmt.Println("Adding Mutation", t)
l.AssertLock()

if txn.ShouldAbort() {
Expand Down Expand Up @@ -721,6 +723,7 @@ func (l *List) addMutationInternal(ctx context.Context, txn *Txn, t *pb.Directed
}

x.PrintMutationEdge(t, pk, txn.StartTs)
fmt.Println("Adding Mutation", t, l.mutationMap)

// We ensure that commit marks are applied to posting lists in the right
// order. We can do so by proposing them in the same order as received by the Oracle delta
Expand Down Expand Up @@ -822,6 +825,10 @@ func (l *List) setMutation(startTs uint64, data []byte) {
func (l *List) Iterate(readTs uint64, afterUid uint64, f func(obj *pb.Posting) error) error {
l.RLock()
defer l.RUnlock()
fmt.Println("IN ITERATE", l.plist)
if l.mutationMap != nil {
fmt.Println("IN ITERATE", l.mutationMap.oldList)
}
return l.iterate(readTs, afterUid, f)
}

Expand Down Expand Up @@ -1778,6 +1785,7 @@ func (l *List) findValue(readTs, uid uint64) (rval types.Val, found bool, err er

func (l *List) findPosting(readTs uint64, uid uint64) (found bool, pos *pb.Posting, err error) {
// Iterate starts iterating after the given argument, so we pass UID - 1
fmt.Println("FIND POSTING", l.mutationMap, l.plist, uid)
var ok bool
if l.mutationMap != nil {
pos, ok = l.mutationMap.uidsH[uid]
Expand All @@ -1795,7 +1803,7 @@ func (l *List) findPosting(readTs uint64, uid uint64) (found bool, pos *pb.Posti
}

var pitr pIterator
err = pitr.seek(l, 0, 0)
err = pitr.seek(l, uid-1, 0)
if err != nil {
return false, nil, errors.Wrapf(err, "cannot initialize iterator when calling List.iterate")
}
Expand All @@ -1806,6 +1814,7 @@ func (l *List) findPosting(readTs uint64, uid uint64) (found bool, pos *pb.Posti
}
if valid {
pp := pitr.posting()
fmt.Println("FIND POSTING", l.mutationMap, l.plist, uid, pp)
if pp.Uid == uid {
return true, pp, nil
}
Expand Down
61 changes: 48 additions & 13 deletions worker/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,57 @@ func TestSingleUid(t *testing.T) {
fmt.Println("UIDS:", uids)
}

func BenchmarkAddMutationWithIndex(b *testing.B) {
gr = new(groupi)
gr.gid = 1
gr.tablets = make(map[string]*pb.Tablet)
addTablets := func(attrs []string, gid uint32, namespace uint64) {
for _, attr := range attrs {
gr.tablets[x.NamespaceAttr(namespace, attr)] = &pb.Tablet{GroupId: gid}
}
func TestLangExact(t *testing.T) {
dir, err := os.MkdirTemp("", "storetest_")
x.Check(err)
defer os.RemoveAll(dir)

opt := badger.DefaultOptions(dir)
ps, err := badger.OpenManaged(opt)
x.Check(err)
pstore = ps
// Not using posting list cache
posting.Init(ps, 0)
Init(ps)
err = schema.ParseBytes([]byte("testLang: string @index(term) @lang ."), 1)
require.NoError(t, err)

ctx := context.Background()
txn := posting.Oracle().RegisterStartTs(5)
attr := x.GalaxyAttr("testLang")

edge := &pb.DirectedEdge{
Value: []byte("english"),
Attr: attr,
Entity: 1,
Op: pb.DirectedEdge_SET,
Lang: "en",
}

x.Check(runMutation(ctx, edge, txn))

edge = &pb.DirectedEdge{
Value: []byte("hindi"),
Attr: attr,
Entity: 1,
Op: pb.DirectedEdge_SET,
Lang: "hi",
}

addTablets([]string{"name", "name2", "age", "http://www.w3.org/2000/01/rdf-schema#range", "",
"friend", "dgraph.type", "dgraph.graphql.xid", "dgraph.graphql.schema"},
1, x.GalaxyNamespace)
addTablets([]string{"friend_not_served"}, 2, x.GalaxyNamespace)
addTablets([]string{"name"}, 1, 0x2)
x.Check(runMutation(ctx, edge, txn))

pl, err := txn.Get(x.DataKey(attr, 1))
x.Check(err)

fmt.Println(pl.Value(5))

pl.Iterate(5, 0, func(p *pb.Posting) error {

Check failure on line 149 in worker/sort_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `pl.Iterate` is not checked (errcheck)
fmt.Println("INSIDE MAIN ITERATE", p)
return nil
})
}

func BenchmarkAddMutationWithIndex(b *testing.B) {
dir, err := os.MkdirTemp("", "storetest_")
x.Check(err)
defer os.RemoveAll(dir)
Expand Down

0 comments on commit 1dc6a9f

Please sign in to comment.