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

Add support for customizing transaction start - fixes #432 #640

Closed
wants to merge 2 commits into from

Conversation

BillyYccc
Copy link
Member

Motivation:

fixes #432

Conformance:

Your commits should be signed and you should have signed the Eclipse Contributor Agreement as explained in https://github.com/eclipse/vert.x/blob/master/CONTRIBUTING.md
Please also make sure you adhere to the code style guidelines: https://github.com/vert-x3/wiki/wiki/Vert.x-code-style-guidelines

@BillyYccc BillyYccc added the backport required This issue has not been backported yet but needs to be label May 17, 2020
@BillyYccc BillyYccc added this to the 4.0.0 milestone May 17, 2020
@@ -62,9 +63,9 @@
}
}

Future<Transaction> begin() {
Future<Transaction> begin(String startTxSql) {
Copy link
Member

Choose a reason for hiding this comment

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

startTxSql should be replace by an enum as each database might use something different to do this

Copy link
Member

Choose a reason for hiding this comment

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

also user don't want to know about the SQL for this :-)

@BillyYccc
Copy link
Member Author

I have rethinked and add a prototype here(the code may be a little messy but it can show the basic design)

The primary idea is to provide a simple API to configure transaction options at the start the transaction, and it would only support those common defined behaviors.
So now we have an unified API to configure transaction isolation levels and transaction access modes, specific database sql modifiers are not included in the API such as MySQL WITH CONSISTENT SNAPSHOT and Postgres DEFERRABLE.

Even though we have the same API, the sql to start a transaction in different databases is different, therefore we have to build the begin tx SQL at the codec level for different databases.
Since MySQL it does not support specifying the isolation level in the start tx sql like Postgres, a SQL SET TRANSACTION ISOLATION LEVEL <...> needs to be queried before the transaction start so that the isolation level is correctly set. I think we would go in the same way to solve this kind of issue for DB2/SQL Server as well.

If you're fine with this API, I will proceed to clean the code and work at this.

@gavinking
Copy link

gavinking commented May 17, 2020

LGTM.

The ANSI standard options for the BEGIN TRANSACTION command are ISOLATION LEVEL READ UNCOMMITTED, ISOLATION LEVEL READ COMMITTED, ISOLATION LEVEL REPEATABLE READ, ISOLATION LEVEL SERIALIZABLE, and READ ONLY, READ WRITE.

ANSI SQL also defines DIAGNOSTICS SIZE, but I've never seen that supported in any database.


public static final TransactionOptions DEFAULT_TX_OPTIONS = new TransactionOptions();

private TransactionIsolationLevel transactionIsolationLevel;
Copy link
Member

Choose a reason for hiding this comment

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

simply isolationLevel

public static final TransactionOptions DEFAULT_TX_OPTIONS = new TransactionOptions();

private TransactionIsolationLevel transactionIsolationLevel;
private TransactionAccessMode transactionAccessMode;
Copy link
Member

Choose a reason for hiding this comment

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

simply accessMode

public class StartTxCommand<R> extends TxCommand<R> {
public TransactionOptions transactionOptions;

public StartTxCommand(Kind kind, R result, TransactionOptions transactionOptions) {
Copy link
Member

Choose a reason for hiding this comment

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

rather here directly the access mode and the isolation level as _ TransactionOptions_ is mutable

@@ -152,6 +153,14 @@ static Pool pool(Vertx vertx, SqlConnectOptions connectOptions, PoolOptions pool
*/
<T> Future<T> withTransaction(Function<SqlClient, Future<T>> function);

@GenIgnore
// FIXME codegen
Copy link
Member

Choose a reason for hiding this comment

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

what is the codegen error here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

it should be ok, I just don't add codegen annotations for a POC prototype, will add it later

@vietj
Copy link
Member

vietj commented May 17, 2020

That makes some new classes in the top level package, I think we should have them in a transaction child package instead

@vietj vietj closed this May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport required This issue has not been backported yet but needs to be
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for configuring transaction characteristics
3 participants