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

fingle-mysql: transaction support #368

Closed
wants to merge 1 commit into from
Closed

fingle-mysql: transaction support #368

wants to merge 1 commit into from

Conversation

fwbrasil
Copy link
Contributor

Problem

Currently it is not possible to run multiple statements using a
single transaction.

Solution

Add the transactional method that executes a function within a transaction.
The function's input is a client that has only one underlying database
connection with an open transaction. The provided client instance
must be used for all database interactions and never leak to outside
the transactional block scope.

The transaction is automatically committed in case of a success and
automatically rolled back in case of a failure.

Result

Users are able to run multiple statements using a single transaction.

@fwbrasil
Copy link
Contributor Author

cc/ @rodolfo42 @missingfaktor @folone

Problem

Currently it is not possible to run multiple statements using a
single transaction.

Solution

Add the transactional method that executes a function within a transaction.
The function's input is a client that has only one underlying database
connection with an open transaction. The provided client instance
must be used for all database interactions and never leak to outside
the transactional block scope.

The transaction is automatically committed in case of a success and
automatically rolled back in case of a failure.

Result

Users are able to run multiple statements using a single transaction.
@mosesn
Copy link
Contributor

mosesn commented Apr 16, 2015

@fwbrasil I think we already added support for transactions in the develop branch.

Does that look like it takes care of your concerns?

@@ -33,6 +33,23 @@ object Client {
}
}

def transactional[R](f: Client => Future[R]): Future[R] =
factory().flatMap { svc =>
val client = apply(ServiceFactory.const(svc))
Copy link
Contributor

Choose a reason for hiding this comment

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

As @mosesn mentioned, we recently added this internally and it's available as part of the develop branch.

Note though, this may have surprising results. Because of how the mysql client operates on the this ServiceFactory you aren't guaranteed exclusivity to this Service (i.e. connection in this case). You need to override the Service#close method to completely control its lifecycle. Take a look at how we implemented it in the develop branch.

@fwbrasil
Copy link
Contributor Author

fwbrasil commented May 4, 2015

@mosesn @roanta Thanks for the feedback, I'll take a look at the develop branch.

It is interesting to see that you are working on improving the finagle-mysql module, it has been difficult to use it in our projects. Out of curiosity: do you consider it production ready?

@fwbrasil fwbrasil closed this May 4, 2015
@roanta
Copy link
Contributor

roanta commented May 4, 2015

I would say it's production ready; we have teams using it in production at twitter.

What kind of difficulties have you guys run into? Is it mostly related to the bare API?

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

Successfully merging this pull request may close these issues.

None yet

3 participants