Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(cache): Add a sharded map for global cache #9180

Open
wants to merge 3 commits into
base: harshil-goel/mutable-map
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ func (s *Server) doQuery(ctx context.Context, req *Request) (resp *api.Response,
EncodingNs: uint64(l.Json.Nanoseconds()),
TotalNs: uint64((time.Since(l.Start)).Nanoseconds()),
}
//fmt.Println("====Query Resp", qc.req.Query, qc.req.StartTs, qc.req, string(resp.Json))
return resp, gqlErrs
}

Expand Down
1 change: 1 addition & 0 deletions posting/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func addMutation(t *testing.T, l *List, edge *pb.DirectedEdge, op uint32,
}

txn.Update()
txn.UpdateCachedKeys(commitTs)
writer := NewTxnWriter(pstore)
require.NoError(t, txn.CommitToDisk(writer, commitTs))
require.NoError(t, writer.Flush())
Expand Down
3 changes: 2 additions & 1 deletion posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ func (l *List) setMutation(startTs uint64, data []byte) {
l.mutationMap = newMutableMap()
}
l.mutationMap.set(startTs, pl)

if pl.CommitTs != 0 {
l.maxTs = x.Max(l.maxTs, pl.CommitTs)
}
Expand Down Expand Up @@ -903,6 +902,7 @@ func (l *List) Iterate(readTs uint64, afterUid uint64, f func(obj *pb.Posting) e
// If greater than zero, this timestamp must thus be greater than l.minTs.
func (l *List) pickPostings(readTs uint64) (uint64, []*pb.Posting) {
// This function would return zero ts for entries above readTs.
// either way, effective ts is returning ts.
effective := func(start, commit uint64) uint64 {
if commit > 0 && commit <= readTs {
// Has been committed and below the readTs.
Expand Down Expand Up @@ -1099,6 +1099,7 @@ func (l *List) getPostingAndLength(readTs, afterUid, uid uint64) (int, bool, *pb
var count int
var found bool
var post *pb.Posting

err := l.iterate(readTs, afterUid, func(p *pb.Posting) error {
if p.Uid == uid {
post = p
Expand Down
2 changes: 2 additions & 0 deletions posting/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@
kvs, err := ol.Rollup(nil, txn.StartTs-3)
require.NoError(t, err)
require.NoError(t, writePostingListToDisk(kvs))
// Delete item from global cache before reading, as we are not updating the cache in the test
globalCache.Del(z.MemHash(key))

Check failure on line 536 in posting/list_test.go

View workflow job for this annotation

GitHub Actions / dgraph-upgrade-tests

undefined: globalCache

Check failure on line 536 in posting/list_test.go

View workflow job for this annotation

GitHub Actions / dgraph-integration2-tests

undefined: globalCache

Check failure on line 536 in posting/list_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: globalCache

Check failure on line 536 in posting/list_test.go

View workflow job for this annotation

GitHub Actions / dgraph-oss-build

undefined: globalCache
ol, err = getNew(key, ps, math.MaxUint64)
require.NoError(t, err)
}
Expand Down
9 changes: 6 additions & 3 deletions posting/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (vc *viLocalCache) GetWithLockHeld(key []byte) (rval index.Value, rerr erro
func (vc *viLocalCache) GetValueFromPostingList(pl *List) (rval index.Value, rerr error) {
value := pl.findStaticValue(vc.delegate.startTs)

if value == nil {
if value == nil || len(value.Postings) == 0 {
return nil, ErrNoValue
}

Expand Down Expand Up @@ -312,8 +312,9 @@ func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error)
}
} else {
pl = &List{
key: key,
plist: new(pb.PostingList),
key: key,
plist: new(pb.PostingList),
mutationMap: newMutableMap(),
}
}

Expand Down Expand Up @@ -395,6 +396,8 @@ func (lc *LocalCache) GetSinglePosting(key []byte) (*pb.PostingList, error) {
}
}
pl.Postings = pl.Postings[:idx]
//pk, _ := x.Parse([]byte(key))
//fmt.Println("====Getting single posting", lc.startTs, pk, pl.Postings)
return pl, nil
}

Expand Down
Loading
Loading