Skip to content

Conversation

@benbierens
Copy link
Contributor

During debugging, I wrote these tests to check that the datastores can handle concurrent queries.
This didn't help. It didn't reveal any problems. But I figure we might as well keep the tests.

Copy link
Contributor

@tbekas tbekas left a comment

Choose a reason for hiding this comment

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

Nice test 👍

return success (key.some, data)

iter.next = next
iter.dispose = proc(): Future[?!void] {.async.} =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that disposing an inter should follow iter being finished, not the other way around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry, I'm not sure what you mean. :o

Copy link
Contributor

@tbekas tbekas Aug 15, 2024

Choose a reason for hiding this comment

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

So setting finished to true, should be an internal to iterator event that's signaling that all items were yielded (line 197).

With this change, flag finished would be set to true whenever dispose() would be called (even if all items were not yielded). So as a client of this API you can finish iteration prematurely and call dispose(), but that's not the same as yielding all elements.

Copy link
Contributor

@gmega gmega Aug 15, 2024

Choose a reason for hiding this comment

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

🔴 Well the client won't even finish iteration because next will still happily return the next element as next doesn't check the finished flag to decide what to do. So if you're relying on it returning success (Key.none, ...) to know when to stop, this will not have the intended effect.

I suppose that to get the right semantics (assuming this is the right one) you need to check the state of the finished flag in addition to the state of the walker iterator (e.g if finished(walker) or iter.finished).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I understand the desired behavior and I'm gonne write a test for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: Finished iters will always return None when asked for next. There's a test to ensure this, and ensure that disposed iters become finished.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why we're (incorrectly) changing the semantics of the iterators now?

as @tbekas is saying:

So setting finished to true, should be an internal to iterator event that's signaling that all items were yielded (line 197).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the goal is to allow dispose to be called before the iterator returns all elements. I suppose this is useful because it's not always that you will want to consume the whole set of results from a query, and in that case you'll want to free up the resources (dispose) anyway. Is that the use case @benbierens?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah OK the concern I had is fixed by this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can't assume the iterator will always run through all elements. I've added a test to show that you can properly clean up an iterator early by calling dispose on it. Any nexts would then yield nothing and the underlying resources can be closed.

Copy link
Contributor

@gmega gmega left a comment

Choose a reason for hiding this comment

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

The tests are fine, but the semantics for disposal is a bit weird for fsds, wanna make sure that's what's intended.

return success (key.some, data)

iter.next = next
iter.dispose = proc(): Future[?!void] {.async.} =
Copy link
Contributor

@gmega gmega Aug 15, 2024

Choose a reason for hiding this comment

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

🔴 Well the client won't even finish iteration because next will still happily return the next element as next doesn't check the finished flag to decide what to do. So if you're relying on it returning success (Key.none, ...) to know when to stop, this will not have the intended effect.

I suppose that to get the right semantics (assuming this is the right one) you need to check the state of the finished flag in addition to the state of the walker iterator (e.g if finished(walker) or iter.finished).

@benbierens benbierens requested a review from gmega August 19, 2024 09:08
Copy link
Contributor

@gmega gmega left a comment

Choose a reason for hiding this comment

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

OK the concerns I had have been addressed so approving it.

return success (key.some, data)

iter.next = next
iter.dispose = proc(): Future[?!void] {.async.} =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the goal is to allow dispose to be called before the iterator returns all elements. I suppose this is useful because it's not always that you will want to consume the whole set of results from a query, and in that case you'll want to free up the resources (dispose) anyway. Is that the use case @benbierens?

return success (key.some, data)

iter.next = next
iter.dispose = proc(): Future[?!void] {.async.} =
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah OK the concern I had is fixed by this.

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 this pull request may close these issues.

5 participants