Skip to content

Refactor connection state management (#326) - #329

Merged
roji merged 4 commits into
npgsql:masterfrom
roji:state_refactor
Sep 1, 2014
Merged

roji merged 4 commits into
npgsql:masterfrom
roji:state_refactor

Conversation

@roji

@roji roji commented Aug 28, 2014

Copy link
Copy Markdown
Member

This PR does the work described in #326. All unit tests pass.

I've split the work into 3 commits, and tried to make each as clear and self-contained as possible, to help reviews.

I'd really appreciate if you guys could take a look, this touches on some very fundamental things.

@roji roji self-assigned this Aug 28, 2014
Comment thread Npgsql/Npgsql/NpgsqlConnector.de.resx Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know this seems a detail, but I think the character ü was missed here. :) I also noticed some other missing chars in the japanese files too.

@franciscojunior

Copy link
Copy Markdown
Member

I think your changes are excellent, @roji !

I did a comment about some missing chars in the resource files.

Also, another point is that you removed the NpgsqlNetworkStream. Currently this class was created to fix a problem when closing the connections from the pool when an application was finished. You can see more information about this problem and my fix here: http://lists.pgfoundry.org/pipermail/npgsql-devel/2011-December/001183.html

Unless we fix it in another way, if we remove the NpgsqlNetworkStream and its override of Dispose(), we would get a regression where this message would appear again in the server logs.

Also, I noticed that at the time I wrote this fix, it used to work on Mono. Now, I notice that it isn't working on Mono anymore, only on ms .Net. I think Mono isn't being able to call my Dispose override.

I don't know if ms.net 4.0 or 4.5 adds any support to notify applications and assemblies when an application domain is being unloaded. If there is such support, we could use it to signalize NpgsqlConnectorPool that the assembly is being unloaded and that it should close all connections in the pools.

Another usage for NpgsqlNetworkStream I foresee is to refactor PGUtil methods and add them to the NpgsqlNetworkStream itself. As you already noticed in other parts of Npgsql, some methods aren't so object oriented. PGUtil methods are such methods. I think a lot of them could be easily moved to a stream class. Or maybe we could use some extension methods to add support to the BufferedStream class.

What do you think?

@roji

roji commented Aug 30, 2014

Copy link
Copy Markdown
Member Author

Hi @franciscojunior! Thank you very much for taking the time to review, it's not easy to read big diffs like the one for this PR :)

Comments:

  • UTF-8 issues in resx: Good catch! I guess I was using a non-UTF8 editor. Should be fixed.
  • NpgsqlNetworkStream: Thanks for explaining. At least for now I reverted back to using your solution (with NpgsqlNetworkStream), we can think about this at some point later if we want (it's not part of this PR anyway).
  • I restored the pre-9.0 checks and all the Supports* properties, mostly because of the discussion in Redshift does not support startup parameter LC_MONETARY #163.
  • I went over all of the stream methods in PGUtil and made them extension methods, the code looks nicer and more OO. (am leaving this commit aside for now, this PR is large enough as it is)

Note that I rewrote the branch history and force-pushed. Let me know if you see any other issues.

@roji
roji force-pushed the state_refactor branch 3 times, most recently from 15e7321 to 8366126 Compare August 30, 2014 08:28
@roji

roji commented Aug 30, 2014

Copy link
Copy Markdown
Member Author

Please hold off on reviewing this, I still have one correction I'll do later today.

@roji
roji force-pushed the state_refactor branch 3 times, most recently from 4e7e79f to ce31156 Compare August 31, 2014 09:47
roji added 4 commits August 31, 2014 12:48
Apart from the reshuffle, everything was more or less left
as is, as much as possible.

This is a WIP commit, the project does not compile.
- Grouped relevant methods in #regions
- Converted some fields/properties into auto properties

This is a WIP commit, the project does not compile.
- Redefined state as an Npgsql-specific enum on the connector.
  It's the single source of truth on state.
- The state now tracks query state as well, with the values Executing
  and Fetching. Previously the reader was checked to know whether we
  were fetching.
- NpgsqlConnection.State now returns the Connecting value as per MSDN docs
- NpgsqlConnection.FullState now returns ConnectionState's reserved values
  (Executing and Fetching, Broken to be added)
- Removed some remaining legacy code for pre-9.0 backends

All unit tests pass
@roji

roji commented Aug 31, 2014

Copy link
Copy Markdown
Member Author

I think everything is OK now. @franciscojunior (and anyone else who has time), let me know if you're OK with merging.

@franciscojunior

Copy link
Copy Markdown
Member

I think everything is OK now. @franciscojunior (and anyone else who has time), let me know if you're OK with merging.

Excellent, @roji ! I'll have a look and will let you know if I find anything else.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In a next review, we can remove all references to "Shared" connections. In the beginning we had the idea of using it because we thought it would be used. But after learning more about the ADO.Net connection semantics, we never implemented it.

@franciscojunior

Copy link
Copy Markdown
Member

+1 to merge.

I reviewed and it seems very good!
Excellent work, @roji !

roji added a commit that referenced this pull request Sep 1, 2014
Refactor connection state management (#326)
@roji
roji merged commit 6bcb25d into npgsql:master Sep 1, 2014
roji added a commit that referenced this pull request Sep 1, 2014
The code contained traces from a partial implementation of
shared connections that was never released. Cleaned up as
suggested by @franciscojunior in
#329 (comment)
@roji
roji deleted the state_refactor branch September 20, 2014 19:48
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.

2 participants