-
Notifications
You must be signed in to change notification settings - Fork 44
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
fix: Panic with different composite-indexed child objects #2947
Merged
islamaliev
merged 6 commits into
sourcenetwork:develop
from
islamaliev:fix/panic-indexed-fieldin-child-doc
Aug 22, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7c07418
Make multiScanNode keep track of all calls
islamaliev e882c56
Polish
islamaliev 5512305
Adjust count and call
islamaliev 4f7a741
Create query iterator on Next instead of Init.
islamaliev d2e6590
Add documentation to multiScanNode
islamaliev d37b6e4
Close an existing iterator if it exists
islamaliev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
|
@@ -214,22 +214,22 @@ func (s *selectNode) addSubPlan(fieldIndex int, newPlan planNode) error { | |
if err := s.planner.walkAndReplacePlan(s.source, origScan, multiscan); err != nil { | ||
return err | ||
} | ||
// create multinode | ||
multinode := ¶llelNode{ | ||
// create parallelNode | ||
parallelNode := ¶llelNode{ | ||
p: s.planner, | ||
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. praise: I forgot to add to my earlier review, thanks for renaming this. |
||
multiscan: multiscan, | ||
docMapper: docMapper{s.source.DocumentMap()}, | ||
} | ||
multinode.addChild(-1, s.source) | ||
parallelNode.addChild(-1, s.source) | ||
multiscan.addReader() | ||
// replace our new node internal scanNode with our new multiscanner | ||
if err := s.planner.walkAndReplacePlan(newPlan, origScan, multiscan); err != nil { | ||
return err | ||
} | ||
// add our newly updated plan to the multinode | ||
multinode.addChild(fieldIndex, newPlan) | ||
parallelNode.addChild(fieldIndex, newPlan) | ||
multiscan.addReader() | ||
s.source = multinode | ||
s.source = parallelNode | ||
|
||
// we already have an existing parallelNode as our source | ||
case *parallelNode: | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
|
@@ -322,38 +322,70 @@ func (p *Planner) Scan( | |
// If we have two readers on our multiScanNode, then | ||
// we call Next() on the underlying scanNode only | ||
// once every 2 Next() calls on the multiScan | ||
// | ||
// NOTE: calling Init() on multiScanNode is subject to counting as well and as such | ||
// doesn't not provide idempotency guarantees. Counting is purely for performance | ||
// reasons and removing it should be safe. | ||
type multiScanNode struct { | ||
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. praise: This is very clear, thanks Islam :) |
||
scanNode *scanNode | ||
numReaders int | ||
numCalls int | ||
nextCount int | ||
initCount int | ||
startCount int | ||
closeCount int | ||
|
||
lastBool bool | ||
lastErr error | ||
nextResult bool | ||
err error | ||
} | ||
|
||
// Init initializes the multiScanNode. | ||
// NOTE: this function is subject to counting based on the number of readers and as such | ||
// doesn't not provide idempotency guarantees. Counting is purely for performance | ||
// reasons and removing it should be safe. | ||
func (n *multiScanNode) Init() error { | ||
return n.scanNode.Init() | ||
n.countAndCall(&n.initCount, func() error { | ||
return n.scanNode.Init() | ||
}) | ||
return n.err | ||
} | ||
|
||
func (n *multiScanNode) Start() error { | ||
return n.scanNode.Start() | ||
n.countAndCall(&n.startCount, func() error { | ||
return n.scanNode.Start() | ||
}) | ||
return n.err | ||
} | ||
|
||
// Next only calls Next() on the underlying | ||
// scanNode every numReaders. | ||
func (n *multiScanNode) Next() (bool, error) { | ||
if n.numCalls == 0 { | ||
n.lastBool, n.lastErr = n.scanNode.Next() | ||
// countAndCall keeps track of number of requests to call a given function by checking a | ||
// function's count. | ||
// The function is only called when the count is 0. | ||
// If the count is equal to the number of readers, the count is reset. | ||
// If the function returns an error, the error is stored in the multiScanNode. | ||
func (n *multiScanNode) countAndCall(count *int, f func() error) { | ||
if *count == 0 { | ||
err := f() | ||
if err != nil { | ||
n.err = err | ||
} | ||
} | ||
n.numCalls++ | ||
*count++ | ||
|
||
// if the number of calls equals the numbers of readers | ||
// reset the counter, so our next call actually executes the Next() | ||
if n.numCalls == n.numReaders { | ||
n.numCalls = 0 | ||
// reset the counter, so our next call actually executes the function | ||
if *count == n.numReaders { | ||
*count = 0 | ||
} | ||
} | ||
|
||
// Next only calls Next() on the underlying | ||
// scanNode every numReaders. | ||
func (n *multiScanNode) Next() (bool, error) { | ||
n.countAndCall(&n.nextCount, func() (err error) { | ||
n.nextResult, err = n.scanNode.Next() | ||
return | ||
}) | ||
|
||
return n.lastBool, n.lastErr | ||
return n.nextResult, n.err | ||
} | ||
|
||
func (n *multiScanNode) Value() core.Doc { | ||
|
@@ -373,7 +405,10 @@ func (n *multiScanNode) Kind() string { | |
} | ||
|
||
func (n *multiScanNode) Close() error { | ||
return n.scanNode.Close() | ||
n.countAndCall(&n.closeCount, func() error { | ||
return n.scanNode.Close() | ||
}) | ||
return n.err | ||
} | ||
|
||
func (n *multiScanNode) DocumentMap() *core.DocumentMapping { | ||
|
Oops, something went wrong.
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.
suggestion: If
iter.resultIter
is not nil here, it looks like it should probably be closed before clearing the ref?I have a vague memory of the normal fetcher failing because of this some time ago, but I might be wrong.