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

fix: Panic with different composite-indexed child objects #2947

Conversation

islamaliev
Copy link
Contributor

Relevant issue(s)

Resolves #2924

Description

Make multiScanNode keep track of all calls.

The issue was that multiScanNode that keeps track of how many calls to Next() should be made, would call Init() and Start() every time without tracking, which would result in child nodes being initialized and started multiple times, which in turn created index iterators without closing them.

@islamaliev islamaliev self-assigned this Aug 22, 2024
@islamaliev islamaliev added bug Something isn't working area/query Related to the query component labels Aug 22, 2024
@islamaliev islamaliev added this to the DefraDB v0.13 milestone Aug 22, 2024
@islamaliev islamaliev requested a review from a team August 22, 2024 16:05
@islamaliev islamaliev changed the title fix: panic with different composite-indexed child objects fix: Panic with different composite-indexed child objects Aug 22, 2024
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust it fixes it, but it is not clear why - please add some documentation :)

internal/planner/scan.go Outdated Show resolved Hide resolved
@AndrewSisley
Copy link
Contributor

AndrewSisley commented Aug 22, 2024

which in turn created index iterators without closing them.

To me this makes it sound like the previous index iterator should be closed on Init of whatever created it. Init is designed to be called multiple times and it should reset the node state on each call. I think that the changes in this PR actually breaks this in multiScanNode, in order to manage the symptoms of the index iterator not disposing of it's prior state correctly.

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 88.40580% with 8 lines in your changes missing coverage. Please review.

Project coverage is 79.25%. Comparing base (64a2ada) to head (d37b6e4).
Report is 1 commits behind head on develop.

Files Patch % Lines
internal/db/fetcher/indexer_iterators.go 84.62% 3 Missing and 3 partials ⚠️
internal/planner/scan.go 92.31% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2947      +/-   ##
===========================================
- Coverage    79.26%   79.25%   -0.02%     
===========================================
  Files          326      326              
  Lines        24870    24870              
===========================================
- Hits         19713    19709       -4     
  Misses        3740     3740              
- Partials      1417     1421       +4     
Flag Coverage Δ
all-tests 79.25% <88.41%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
internal/planner/multi.go 83.78% <100.00%> (ø)
internal/planner/scan.go 90.48% <92.31%> (+0.88%) ⬆️
internal/db/fetcher/indexer_iterators.go 74.81% <84.62%> (-1.49%) ⬇️

... and 20 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64a2ada...d37b6e4. Read the comment docs.

Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks Islam :)

Please have a quick look at the final suggestion before merge.

func (iter *indexPrefixIterator) Init(ctx context.Context, store datastore.DSReaderWriter) error {
iter.ctx = ctx
iter.store = store
iter.resultIter = nil
Copy link
Contributor

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.

// create multinode
multinode := &parallelNode{
// create parallelNode
parallelNode := &parallelNode{
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

//
// 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: This is very clear, thanks Islam :)

// The issue was that [multiScanNode] that keeps track of how many calls to [Next()] should
// be made, would call [Init()] and [Start()] every time without tracking, which would result
// in child nodes being initialized and started multiple times, which in turn created
// index iterators without closing them.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Thanks for taking the time to link this to the ticket, it highlights the importance of the test very nicely.

@islamaliev islamaliev merged commit 002851e into sourcenetwork:develop Aug 22, 2024
40 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/query Related to the query component bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fetching indexed field in child document panics
2 participants