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

multi_iterator looks broken #178

Closed
rsr-at-mindtwin opened this issue Mar 26, 2019 · 6 comments · Fixed by #185
Closed

multi_iterator looks broken #178

rsr-at-mindtwin opened this issue Mar 26, 2019 · 6 comments · Fixed by #185

Comments

@rsr-at-mindtwin
Copy link

rsr-at-mindtwin commented Mar 26, 2019

func (m *multiIterator) Seek(key []byte) bool {
	m.current = 0
	iters := []Iterator{}
	ok := false
	for i := range m.iters {
		if m.iters[i].Seek(key) {
			iters = append(iters, m.iters[i])
			ok = true
		}
	}
	return ok
}

In the code above, the assumption of Next() on the first call is that the set of iterators in m.iters actually are the iterators that had a hit on Seek(), hence the accumulation of iterators into the local []iterator{}.

If that's not the goal, then this code is simply wrong and the iters local shouldn't exist.

@frairon
Copy link
Contributor

frairon commented Mar 27, 2019

Hi Rob,
thanks for the issue report. That code looks indeed pretty strange, if not wrong. I'll take a look later.
If you want to improve it yourself, you're very welcome to create a PR :)

Cheers!

frairon added a commit that referenced this issue Apr 2, 2019
@frairon
Copy link
Contributor

frairon commented Apr 2, 2019

@rsr-at-mindtwin, I had a look at the iterator implementation. I think the idea was that seek indeed filters the iterators so that only the ones matching the seek will remain in the set of iterators for the next Next()-call. Then however, the original iterators would be lost for the following seek calls.
I created a PR with the changes that I think would be necessary to fix that. Take look and let me know what you think.

@rsr-at-mindtwin
Copy link
Author

thanks. that looks right to me.

@SamiHiltunen
Copy link
Contributor

There is a new multi iterator implementation here: https://github.com/lovoo/goka/blob/retention/storage/merge_iterator.go

The new implementation should preserve order when iterating over multiple sorted iterators and work as expected when seeking. While the changes in the branch are not really ready for merging otherwise, the iterator itself is complete as far as I remember. I'll have a look on the weekend and new multi iterator merged.

@SamiHiltunen
Copy link
Contributor

Didn't quite have the time I expected earlier, but better late than never I guess. #185 should fix this issue.

@db7
Copy link
Collaborator

db7 commented May 6, 2019

@frairon can you check the PR? It lgtm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants