-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Change uid intersection policy in some cases #8919
Open
harshil-goel
wants to merge
13
commits into
main
Choose a base branch
from
harshil-goel/compression_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
05c5f9d
First commit
7fc02b1
fixed things
9d7a722
Updated tracing percent
d0a5ef7
Added as a list
cc92071
added some traces
0e493ae
modified some benchmarks
763821f
added soem benchmarks
76b4d08
updated
b0073bb
something something
78dc8f1
updated threshold
4cdd30c
updated handle value posting
15f821b
added more traces
13f7e22
added multi api
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ import ( | |
"github.com/dgraph-io/dgraph/types/facets" | ||
"github.com/dgraph-io/dgraph/x" | ||
"github.com/dgraph-io/ristretto/z" | ||
|
||
otrace "go.opencensus.io/trace" | ||
) | ||
|
||
var ( | ||
|
@@ -71,6 +73,7 @@ const ( | |
// List stores the in-memory representation of a posting list. | ||
type List struct { | ||
x.SafeMutex | ||
immutable *pb.List | ||
key []byte | ||
plist *pb.PostingList | ||
mutationMap map[uint64]*pb.PostingList | ||
|
@@ -875,6 +878,21 @@ func (l *List) Rollup(alloc *z.Allocator, readTs uint64) ([]*bpb.KV, error) { | |
return kvs, nil | ||
} | ||
|
||
func (l *List) CreateUnpacked() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like all callers to this are commented out. Is it dead code? |
||
if l.plist.Pack == nil { | ||
return | ||
} | ||
l.immutable = &pb.List{ | ||
Uids: make([]uint64, 0), | ||
} | ||
decoder := codec.NewDecoder(l.plist.Pack) | ||
for ; decoder.Valid(); decoder.Next() { | ||
for _, uid := range decoder.Uids() { | ||
l.immutable.Uids = append(l.immutable.Uids, uid) | ||
} | ||
} | ||
} | ||
|
||
// ToBackupPostingList uses rollup to generate a single list with no splits. | ||
// It's used during backup so that each backed up posting list is stored in a single key. | ||
func (l *List) ToBackupPostingList( | ||
|
@@ -1058,6 +1076,7 @@ func (l *List) encode(out *rollupOutput, readTs uint64, split bool) error { | |
return errors.Wrapf(err, "cannot iterate through the list") | ||
} | ||
plist.Pack = enc.Done() | ||
//l.CreateUnpacked() | ||
if plist.Pack != nil { | ||
if plist.Pack.BlockSize != uint32(blockSize) { | ||
return errors.Errorf("actual block size %d is different from expected value %d", | ||
|
@@ -1137,7 +1156,9 @@ func (l *List) ApproxLen() int { | |
// Uids returns the UIDs given some query params. | ||
// We have to apply the filtering before applying (offset, count). | ||
// WARNING: Calling this function just to get UIDs is expensive | ||
func (l *List) Uids(opt ListOptions) (*pb.List, error) { | ||
func (l *List) Uids(ctx context.Context, opt ListOptions) (*pb.List, error) { | ||
ctx, span := otrace.StartSpan(ctx, "Posting.Uids") | ||
defer span.End() | ||
if opt.First == 0 { | ||
opt.First = math.MaxInt32 | ||
} | ||
|
@@ -1151,11 +1172,18 @@ func (l *List) Uids(opt ListOptions) (*pb.List, error) { | |
l.RUnlock() | ||
return out, ErrTsTooOld | ||
} | ||
algo.IntersectCompressedWith(l.plist.Pack, opt.AfterUid, opt.Intersect, out) | ||
stop := x.SpanTimer(span, "IntersectCompressedWith") | ||
if len(opt.Intersect.Uids) > 5*codec.ApproxLen(l.plist.Pack) { | ||
algo.IntersectCompressedWithAlternate(l.plist.Pack, opt.AfterUid, opt.Intersect, out) | ||
} else { | ||
algo.IntersectCompressedWith(l.plist.Pack, opt.AfterUid, opt.Intersect, out) | ||
} | ||
stop() | ||
l.RUnlock() | ||
return out, nil | ||
} | ||
|
||
span.Annotate(nil, "Starting to read latest data from badger") | ||
err := l.iterate(opt.ReadTs, opt.AfterUid, func(p *pb.Posting) error { | ||
if p.PostingType == pb.Posting_REF { | ||
res = append(res, p.Uid) | ||
|
@@ -1178,6 +1206,7 @@ func (l *List) Uids(opt ListOptions) (*pb.List, error) { | |
} | ||
|
||
// Do The intersection here as it's optimized. | ||
span.Annotate(nil, "Starting normal Intersect") | ||
out.Uids = res | ||
if opt.Intersect != nil { | ||
algo.IntersectWith(out, opt.Intersect, out) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment that this is unpacked posting list?