-
Notifications
You must be signed in to change notification settings - Fork 334
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
Read from branch with compaction data #7701
Changes from 1 commit
deee833
036a2b4
82694ff
90059b0
c554d87
0170d65
5f44d2b
644a04d
18742fa
6cf1337
11a448f
dfb54e6
f609ec2
eb9c4e4
d51ead2
3adc263
70c49d0
ca9a9cb
29e5085
c2cef8b
005f718
2717510
0400e6c
23221ae
1c10a6e
19d797c
2a0f495
4c46b26
3426e0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,8 +10,9 @@ | |||||||||||||||||||||
iterAHasMore bool | ||||||||||||||||||||||
iterB DiffIterator | ||||||||||||||||||||||
iterBHasMore bool | ||||||||||||||||||||||
p DiffIterator | ||||||||||||||||||||||
started bool | ||||||||||||||||||||||
// the current iterator that has the value to return (iterA or iterB) | ||||||||||||||||||||||
currenIter DiffIterator | ||||||||||||||||||||||
started bool | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func NewJoinedDiffIterator(iterA DiffIterator, iterB DiffIterator) *JoinedDiffIterator { | ||||||||||||||||||||||
|
@@ -20,13 +21,28 @@ | |||||||||||||||||||||
iterAHasMore: true, | ||||||||||||||||||||||
iterB: iterB, | ||||||||||||||||||||||
iterBHasMore: true, | ||||||||||||||||||||||
p: nil, | ||||||||||||||||||||||
currenIter: nil, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// progressIterByKey advances the iterators to the next key when both iterators still has more keys | ||||||||||||||||||||||
func (c *JoinedDiffIterator) progressIterByKey(keyA Key, keyB Key) { | ||||||||||||||||||||||
compareResult := bytes.Compare(keyA, keyB) | ||||||||||||||||||||||
switch { | ||||||||||||||||||||||
case compareResult == 0: | ||||||||||||||||||||||
// key exists in both iterators | ||||||||||||||||||||||
c.iterAHasMore = c.iterA.Next() | ||||||||||||||||||||||
c.iterBHasMore = c.iterB.Next() | ||||||||||||||||||||||
case compareResult < 0: | ||||||||||||||||||||||
// value of iterA > value of iterB | ||||||||||||||||||||||
c.iterAHasMore = c.iterA.Next() | ||||||||||||||||||||||
default: | ||||||||||||||||||||||
// value of iterA < value of iterB | ||||||||||||||||||||||
c.iterBHasMore = c.iterB.Next() | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func (c *JoinedDiffIterator) Next() bool { | ||||||||||||||||||||||
valA := c.iterA.Value() | ||||||||||||||||||||||
valB := c.iterB.Value() | ||||||||||||||||||||||
switch { | ||||||||||||||||||||||
case !c.started: | ||||||||||||||||||||||
// first | ||||||||||||||||||||||
|
@@ -38,68 +54,62 @@ | |||||||||||||||||||||
return false | ||||||||||||||||||||||
case !c.iterAHasMore: | ||||||||||||||||||||||
// iterA is done | ||||||||||||||||||||||
c.p = c.iterB | ||||||||||||||||||||||
c.currenIter = c.iterB | ||||||||||||||||||||||
c.iterBHasMore = c.iterB.Next() | ||||||||||||||||||||||
case !c.iterBHasMore: | ||||||||||||||||||||||
// iterB is done | ||||||||||||||||||||||
c.p = c.iterA | ||||||||||||||||||||||
c.iterAHasMore = c.iterA.Next() | ||||||||||||||||||||||
case bytes.Equal(valA.Key, valB.Key): | ||||||||||||||||||||||
c.iterAHasMore = c.iterA.Next() | ||||||||||||||||||||||
c.iterBHasMore = c.iterB.Next() | ||||||||||||||||||||||
case bytes.Compare(valA.Key, valB.Key) < 0: | ||||||||||||||||||||||
c.currenIter = c.iterA | ||||||||||||||||||||||
c.iterAHasMore = c.iterA.Next() | ||||||||||||||||||||||
c.iterBHasMore = true | ||||||||||||||||||||||
default: | ||||||||||||||||||||||
// value of iterA < value of iterB | ||||||||||||||||||||||
c.iterBHasMore = c.iterB.Next() | ||||||||||||||||||||||
c.iterAHasMore = true | ||||||||||||||||||||||
// both iterators has more keys- progress by key | ||||||||||||||||||||||
c.progressIterByKey(c.iterA.Value().Key, c.iterB.Value().Key) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if c.iterA.Err() != nil { | ||||||||||||||||||||||
c.p = c.iterA | ||||||||||||||||||||||
c.currenIter = c.iterA | ||||||||||||||||||||||
c.iterAHasMore = false | ||||||||||||||||||||||
c.iterBHasMore = false | ||||||||||||||||||||||
return false | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if c.iterB.Err() != nil { | ||||||||||||||||||||||
c.p = c.iterB | ||||||||||||||||||||||
c.currenIter = c.iterB | ||||||||||||||||||||||
c.iterAHasMore = false | ||||||||||||||||||||||
c.iterBHasMore = false | ||||||||||||||||||||||
return false | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if !c.iterAHasMore && !c.iterBHasMore { | ||||||||||||||||||||||
return false | ||||||||||||||||||||||
|
||||||||||||||||||||||
// set c.currenIter to be the next (smaller) value | ||||||||||||||||||||||
|
||||||||||||||||||||||
// if one of the iterators is done, set the other one as the current iterator and return | ||||||||||||||||||||||
if !c.iterAHasMore { | ||||||||||||||||||||||
c.currenIter = c.iterB | ||||||||||||||||||||||
if !c.iterBHasMore { | ||||||||||||||||||||||
return false | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return true | ||||||||||||||||||||||
} else if !c.iterBHasMore { | ||||||||||||||||||||||
c.currenIter = c.iterA | ||||||||||||||||||||||
return true | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// set c.p to be the next (smaller) value | ||||||||||||||||||||||
valA = c.iterA.Value() | ||||||||||||||||||||||
valB = c.iterB.Value() | ||||||||||||||||||||||
switch { | ||||||||||||||||||||||
case !c.iterAHasMore && !c.iterBHasMore: | ||||||||||||||||||||||
c.p = c.iterA | ||||||||||||||||||||||
return false | ||||||||||||||||||||||
case !c.iterAHasMore: | ||||||||||||||||||||||
c.p = c.iterB | ||||||||||||||||||||||
case !c.iterBHasMore: | ||||||||||||||||||||||
c.p = c.iterA | ||||||||||||||||||||||
case bytes.Compare(valA.Key, valB.Key) <= 0: | ||||||||||||||||||||||
c.p = c.iterA | ||||||||||||||||||||||
default: | ||||||||||||||||||||||
c.p = c.iterB | ||||||||||||||||||||||
// if both iterators has more keys, set the iterator with the smaller key as the current iterator | ||||||||||||||||||||||
if bytes.Compare(c.iterA.Value().Key, c.iterB.Value().Key) <= 0 { | ||||||||||||||||||||||
c.currenIter = c.iterA | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
c.currenIter = c.iterB | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return true | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func (c *JoinedDiffIterator) Value() *Diff { | ||||||||||||||||||||||
if c.p == nil { | ||||||||||||||||||||||
if c.currenIter == nil { | ||||||||||||||||||||||
return nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return c.p.Value() | ||||||||||||||||||||||
return c.currenIter.Value() | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func (c *JoinedDiffIterator) Err() error { | ||||||||||||||||||||||
if c.p != nil && c.p.Err() != nil { | ||||||||||||||||||||||
return c.p.Err() | ||||||||||||||||||||||
if c.currenIter != nil && c.currenIter.Err() != nil { | ||||||||||||||||||||||
return c.currenIter.Err() | ||||||||||||||||||||||
} | ||||||||||||||||||||||
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. This seems wrong: it says that if one iterator failed but the other still works, then everything is OK. But it's not!
Suggested change
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. We need a unit test for this, too, unfortunately. |
||||||||||||||||||||||
return nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
@@ -110,7 +120,7 @@ | |||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func (c *JoinedDiffIterator) SeekGE(id Key) { | ||||||||||||||||||||||
c.p = nil | ||||||||||||||||||||||
c.currenIter = nil | ||||||||||||||||||||||
c.iterA.SeekGE(id) | ||||||||||||||||||||||
c.iterB.SeekGE(id) | ||||||||||||||||||||||
} |
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.
Please note that calling Value() here is an error. Even though you return successfully, the caller will probably panic shortly after. Your call, but personally I would at least log an "internal error".