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 some code #2928

Merged
merged 21 commits into from
May 3, 2024
Merged

Fix some code #2928

merged 21 commits into from
May 3, 2024

Conversation

guizmaii
Copy link
Member

@guizmaii guizmaii commented Oct 20, 2023

This PR initially started to understand why update to ZIO 2.0.17 was making a test to fail.
In the end, the issue was in ZIO and has been fixed in ZIO 2.0.19.
During the bug research phase, I found some issues in the code, which are the changes in this PR.

protected val identityExtractor = (rr: ResultRow, s: Session) => rr
protected val identityPrepare: Prepare = (p: PrepareRow, _: Session) => (Nil, p)
private val _identityExtractor: Extractor[Any] = (rr: ResultRow, _: Session) => rr
protected def identityExtractor[T]: Extractor[T] = _identityExtractor.asInstanceOf[Extractor[T]]
Copy link
Member Author

Choose a reason for hiding this comment

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

Improves type inference of the identityExtractor usage

Comment on lines -154 to -161
private[getquill] val streamBlocker: ZStream[Any, Nothing, Any] =
ZStream.scoped {
for {
executor <- ZIO.executor
blockingExecutor <- ZIO.blockingExecutor
_ <- ZIO.acquireRelease(ZIO.shift(blockingExecutor))(_ => ZIO.shift(executor))
} yield ()
}
Copy link
Member Author

@guizmaii guizmaii Oct 20, 2023

Choose a reason for hiding this comment

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

This function/code was probably incorrect and was probably not doing anything.

The ZIO.acquireRelease(ZIO.shift(blockingExecutor))(_ => ZIO.shift(executor)) code/execution takes action in the returned Scope.
Here, we were opening and closing a new Scope for the execution of this code. This means that, after this code, the Scope would already have been closed, would already have executed its finalizer and so would already have executed the "shift back to the previous executor" code.
The code following this function call would be then executed on the "previous executor", not on the blocking one.

I decided to remove this function and replace it with ZStream.blocking because I don't see a good reason for us to change the behaviour/semantics of ZIO's "blocking" mechanism.
ZIO might adopt a "shift back immediately after" or a "continue on the same thread" behaviour for some code wrapped in a [ZIO|ZStream].blocking(...) (FYI, in ZIO 2, it's "continue on the same thread")
The user might decide to yield back or not. I don't see why we're taking this decision to always yield back

@deusaquilus Any specific reason? 🤔

Staying with the default mechanism provides more control to the user who might want to yield back or stay on the same thread. I don't think it's up to us to decide.

case Some(size) =>
ZStream.fromIterator(iter, size)
case None =>
ZStream.fromIterator(new ResultSetIterator(rs, conn, extractor))
Copy link
Member Author

Choose a reason for hiding this comment

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

The ResultSetIterator was instantiated twice when fetchSize was None

@guizmaii guizmaii changed the title Fix tests Fix zio v2.0.17 update Oct 20, 2023
@guizmaii guizmaii changed the title Fix zio v2.0.17 update Fix ZIO v2.0.17 update Oct 20, 2023
@guizmaii guizmaii changed the title Fix ZIO v2.0.17 update Update to ZIO v2.0.17 and fix some code Oct 20, 2023
@guizmaii guizmaii changed the base branch from update/zio-2.0.17 to master October 20, 2023 11:36
@CLAassistant
Copy link

CLAassistant commented Oct 20, 2023

CLA assistant check
All committers have signed the CLA.

@guizmaii guizmaii marked this pull request as draft October 20, 2023 12:19
@guizmaii guizmaii changed the title Update to ZIO v2.0.17 and fix some code Update to ZIO v2.0.18 and fix some code Oct 20, 2023
@guizmaii guizmaii marked this pull request as ready for review October 20, 2023 13:21
@guizmaii
Copy link
Member Author

guizmaii commented Oct 20, 2023

This was referenced Oct 20, 2023
@guizmaii guizmaii marked this pull request as draft October 20, 2023 18:09
@guizmaii guizmaii changed the title Update to ZIO v2.0.18 and fix some code Fix some code Nov 8, 2023
@guizmaii guizmaii marked this pull request as ready for review November 8, 2023 14:16
Copy link
Collaborator

@juliano juliano left a comment

Choose a reason for hiding this comment

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

lgtm

@juliano
Copy link
Collaborator

juliano commented Apr 24, 2024

@guizmaii can I merge it or would you like to wait for Alex review?

@guizmaii
Copy link
Member Author

@juliano If you're okay with it, I think we can merge it. Let's give @deusaquilus a week to tell us if he wants to review it first, maybe?

@juliano juliano merged commit 2fd029a into master May 3, 2024
13 checks passed
@juliano juliano deleted the fix/zio-2.0.17 branch May 3, 2024 14:34
jilen pushed a commit that referenced this pull request Jun 11, 2024
* Update zio, zio-streams to 2.0.17

* Fix tests

* Fix tests

* simplify code

* Fix tests (#2930)

* Fix tests

* Fix tests

* clean

* fix tests

* clean

* Remove `streamBlocker` function

* clean

* Update ZIO to v2.0.19

* Clean

* clean

* clean

---------

Co-authored-by: zio-scala-steward[bot] <145262613+zio-scala-steward[bot]@users.noreply.github.com>
Co-authored-by: Juliano Alves <von.juliano@gmail.com>
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.

3 participants