-
Notifications
You must be signed in to change notification settings - Fork 22
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
Closing opened connections #116
Conversation
This fixes #96 by closing opened connections when it is getting the size of the table/query by executing COUNT and when it finishes the foreign scan iteration.
2 things:
|
🤔 I think so. As part of the revision I'll check also if all the connections are closed when some error occurred. |
Implemented the method `odbc_disconecction` which closes connections opened after doing: - odbc_table_size - odbc_query_size - odbc_tables_list - foreign scan Tested with the "employees" MySQL database: - `select * from test.departments;` - `IMPORT FOREIGN SCHEMA "employees" FROM SERVER mysql INTO "test";` - `SELECT * FROM ODBCTablesList('mysql', 10);` - `SELECT * FROM ODBCTableSize('mysql', 'dept_emp');` - `SELECT * FROM ODBCQuerySize('mysql', 'select * from salaries');`
odbc_fdw.c
Outdated
static void | ||
odbc_disconnection(SQLHENV *env, SQLHDBC *dbc) | ||
{ | ||
if (dbc && *dbc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is suspicious and likely what's causing crashes on Windows builds. You are setting the contents of dbc
to NULL, but is SQLHDBC
declared as a NULLable type in the ODBC standard (I'm guessing it comes from there)?
In any case, the fact that we are asking ourselves this question means that this approach is wrong. Either always use a pointer or ensure you only call the disconnect once so you don't need the NULL guards.
I think you need to check the output of both the connect and disconnect calls. It might be that we are getting errors on them. |
odbc_fdw.c
Outdated
SRF_RETURN_DONE(funcctx); | ||
odbc_disconnection(&env, &dbc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will never be called since SRF_RETURN_DONE
will return from the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. This function uses SRF and I was trying to disconnect it using wrong handlers. I stored these handlers into the user_fctx
and using them to disconnect.
Implementing the right order to close a connection: 1. disconnect with the DBC handler 2. free the DBC handler 3. free the ENV handler Fix the disconnection in `odbc_tables_list`. This method is using a set-returning function (SRF) so I added to the `user_fctx` the dbc and env handlers in order to disconnect when the iteration has finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm not sure if dying with with ERROR here is enough or it should be FATAL, but in any case it's a great improvement. Let's get this merged and we can revisit if necessary in the future.
Jenkins tests are failing apparently due to mysql installation and should be easy to fix. Other than that, it'd be cool to merge and deploy this. |
Package update fails if MySQL is not running
Start MySQL before updating it
Broken testsTests spontaneously broke in Travis because of an update of the mysql 5.7 packages (we are installing mysql-server-core-5.7 mysql-client-5.7 mysql-server-5.7). It the previous working tests the base image packages needn't an update:
But now they're updated
And the update was failing:
This is fixed by efd8ba1 and a0a8a43 by installing the packages after starting the server. But then, access to MySQL fails with
Which is fixed by 44b530f by changing the |
@Algunenano could you give your blessing to this? I'll proceed to release and deploy this if you agree. |
LGTM. I don't think we've ever updated odbc_fdw without also upgrading PG, so good luck with that. |
@jgoizueta is this deployed? |
This is released in v0.5.1 but not deployed, AFAIK we still have v0.4.0 in production |
This fixes #96 by closing opened connections when it is getting the size
of the table/query by executing COUNT and when it finishes the foreign
scan iteration.