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

Backport the MS SQL Client to Vert.x 3.9.x #604

Closed
wants to merge 1 commit into from

Conversation

cescoffier
Copy link
Contributor

Just adapt the code from the 4.x branch (master) to work with 3.9.x.

Motivation:

There is a need to get the MS SQL client to work against 3.9. This PR is just adapting the code to follow the Vert.x 3.9 conventions.

Just adapt the code from the 4.x branch (master) to work with 3.9.x.

Signed-off-by: Clement Escoffier <[email protected]>
@cescoffier cescoffier requested a review from vietj May 6, 2020 07:38
@vietj vietj requested a review from BillyYccc May 6, 2020 07:40
@gavinking
Copy link

Oh, that's great!

Copy link
Member

@BillyYccc BillyYccc left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@aguibert aguibert left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Can you also add this stage to the .travis.yml file though so we have test coverage right away and make sure that all tests are passing?

    - stage: test
      name: "MSSQL 2017-CU12"
      jdk: openjdk8
      script: mvn -q clean verify -B --projects vertx-sql-client,vertx-mssql-client

@pmlopes pmlopes self-requested a review May 8, 2020 07:44
Copy link
Contributor

@pmlopes pmlopes left a comment

Choose a reason for hiding this comment

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

As a personal note, I am not currently in favor of this back-port because it is lacking some important features. These features will almost for sure let users down and we will get more maintenance burden on the backport, than focusing on getting the current master and 4.0.0 out of the door.

  • [MSSQL]TLS support #605 - without this, most likely you won't be able to use the client on a cloud environment such as Azure, or on perm where the application server and db server are not the same physical machine.
  • [MSSQL]Cursor support #606 - missing cursors, will likely be a blocker for stored procedure users or "power users" that stream results from the db directly.
  • [MSSQL]Batch Queries support #607 - this can be a blocker for ETL applications where batching is a common technique to address large ingestion of data.
  • [MSSQL]datatype support #608 - A more generic issue the current code only supports a subset of the datatypes MSSQL has. Unlike pg and mysql where we have (if not all) data types handled.
  • [MSSQL]Transaction support #610 - Most definitely a blocker, missing transactions will be a blocker unless users are just thinkering or PoC projects where data loss can be allowed/developing simple read only applications.

This back-port will create more maintenance work for the team which is not able to sustain this load. We could think of a back-port in the future if the expectations are clearly defined. I'd suggest as an alternative that downtream projects interested on this module to start using the SNAPSHOT builds on sonatype or the milestone releases instead.

@cescoffier
Copy link
Contributor Author

cescoffier commented May 8, 2020 via email

@gavinking
Copy link

@pmlopes are any of those issues blockers for typical usage of the Vert.x client under Hibernate Reactive and especially with Quarkus? (This use case is the motivation for the backport.)

It doesn't look to me like they are, though I'm not sure about #605.

I'd suggest as an alternative that downtream projects interested on this module to start using the SNAPSHOT builds on sonatype or the milestone releases instead.

That's not an option for Quarkus, and therefore also not an option for Hibernate Reactive.

@vietj
Copy link
Member

vietj commented May 8, 2020

@gavinking can you use test this branch to see how much it fits your current expectations ?

@gavinking
Copy link

@vietj I can try it out in standalone mode, I guess, though I'm not the right person to test the Quarkus scenario.

@gavinking
Copy link

Alright, so I tried to get a very basic test (SQLServerBasicTest) working on SQL Server using the 3.9.1 snapshot, and here's the result:

https://github.com/gavinking/hibernate-rx/tree/sqlserver

I can see a couple of queries for next sequence values executed and returning successfully, but then as soon as I try to run the first select or insert query, it hangs waiting for a response from the driver.

I have no clue what the cause might be: something to do with us not using with transactions? Something to do with the connection properties I'm using? Something else?

@vietj
Copy link
Member

vietj commented May 9, 2020

@gavinking can you make a reproducer case ? e.g you add a new test in the sql server tests and then we get an analysis from @BillyYccc

@gavinking
Copy link

gavinking commented May 11, 2020

Folks, I have simplified it down to the following:

package org.hibernate.rx;

import io.vertx.core.Vertx;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.mssqlclient.MSSQLConnectOptions;
import io.vertx.mssqlclient.MSSQLPool;
import io.vertx.sqlclient.PoolOptions;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(VertxUnitRunner.class)
public class ConnectionTest {
	@Test
	public void testConnection(TestContext context) {
		MSSQLConnectOptions options = new MSSQLConnectOptions()
				.setHost( "localhost" )
				.setUser( "sa" )
				.setPassword( "reallyStrongPwd123" );
		MSSQLPool pool = MSSQLPool.pool( Vertx.vertx(), options, new PoolOptions() );
		Async async = context.async();
		pool.preparedQuery( "select * from INFORMATION_SCHEMA.SEQUENCES" ).execute(
				ar -> {
					System.out.println( ar.result().rowCount() );
					System.out.println("...done");
					async.complete();
				}
		);
		System.out.println("waiting...");
	}
}

This test hangs and never completes. Surely this must be something simple somehow related to my setup.

@gavinking
Copy link

But the thing that seems strange is that if I replace the query with:

select next value for hibernate_sequence

Then the test completes successfully. Which is why I wonder if this has something to do with txns.

@vietj
Copy link
Member

vietj commented May 11, 2020

so you mean that "select * from INFORMATION_SCHEMA.SEQUENCES" has a problem ?

@gavinking
Copy link

so you mean that "select * from INFORMATION_SCHEMA.SEQUENCES" has a problem ?

Yes, but any table will do. It's not specific to INFORMATION_SCHEMA.SEQUENCES.

@BillyYccc
Copy link
Member

I have tried and found some of the data types in the table are not supported for now such as nvarchar.

@gavinking
Copy link

It's not just that. Honestly I'm just finding a whole lot of really strange behavior (queries that sometimes work and sometimes don't). But it's really hard to debug because I never get any error.

I think the root problem is that it shouldn't hang when an error occurs. It should send the error back to my callback and/or terminate the async operation. This doesn't seem to happen: I never get errors at all, no matter how broken my query is. I can send the query create to the database and it hangs.

@gavinking
Copy link

OK, so apart from the Big problem, which is the failure to report errors, it looks like the other major source of my pain is that it doesn't like inserting null into nullable columns.

Here's the test code I'm using to show this. Note that it uses testcontainers to create the db.

package org.hibernate.rx;

import io.vertx.core.Vertx;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.mssqlclient.MSSQLConnectOptions;
import io.vertx.mssqlclient.MSSQLPool;
import io.vertx.sqlclient.PoolOptions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.testcontainers.containers.MSSQLServerContainer;

@RunWith(VertxUnitRunner.class)
public class ConnectionTest {
	public static final MSSQLServerContainer<?> sqlserver = new MSSQLServerContainer<>()
			.withReuse( true );

	@Test
	public void testConnection(TestContext context) {
		sqlserver.start();
		System.out.println( sqlserver.getJdbcUrl() );
		System.out.println( sqlserver.getFirstMappedPort() );
		MSSQLConnectOptions options = new MSSQLConnectOptions()
				.setHost( "localhost" )
				.setPort( sqlserver.getFirstMappedPort() )
				.setUser( sqlserver.getUsername() )
				.setPassword( sqlserver.getPassword() );
		MSSQLPool pool = MSSQLPool.pool( Vertx.vertx(), options, new PoolOptions() );
		Async async = context.async();
		pool.preparedQuery( "create table WithNull (nullint int)" ).execute(
				ar1 -> {
					System.out.println( ar1.result().rowCount() );
					System.out.println("...inserting...");
					pool.preparedQuery("insert into WithNull (nullint) values (null)").execute(
						ar2 -> {
							System.out.println( ar2.result().rowCount() );
							System.out.println("...querying...");
							pool.preparedQuery("select * from WithNull").execute(
								ar3 -> {
									System.out.println( ar3.result().rowCount() );
									System.out.println("...done");
									sqlserver.stop();
									async.complete();
								}
							);
						}
					);
				}
		);
		System.out.println("creating table...");
	}
}

@BillyYccc
Copy link
Member

I have create an issue for this, see #627.
Some unsupported behaviors will throw UnsupportedOperationException which may not be captured correctly by the callback, they should be improved and be logged as an error maybe.

@vietj vietj closed this Apr 23, 2021
@vietj vietj deleted the features/backport-sqlserver-client-to-3.9 branch April 23, 2021 13:09
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.

6 participants