Skip to content

Java 11 #64

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

Merged
merged 23 commits into from
Mar 11, 2019
Merged

Java 11 #64

merged 23 commits into from
Mar 11, 2019

Conversation

marat-gainullin
Copy link
Contributor

No description provided.

@marat-gainullin
Copy link
Contributor Author

marat-gainullin commented Jan 21, 2019

  • Async API refatored to use CompletableFutures and RxJava dependency eliminated
  • Real PreparedStatements reusing through connection pool introduced
  • Parse|Bind|Describe|Execute|Close|Sync message chain splitted into Parse|Sync and Bind|Describe|Execute|Sync and Close|Sync chains to reuse PreparedStatement instances
  • Strings reading refactored to be able to read strings of unlimited size
  • Connection pool refactored to use of clean synchronization technics
  • Performance improved about 25% according to original test plan from PerformanceTest
  • Some errors fixed
  • PgRow refactored
  • ArrayConversions refactored to be able to use Postgres type bytea[]

@alaisi alaisi self-assigned this Jan 26, 2019
@cretz
Copy link
Contributor

cretz commented Feb 2, 2019

That's a lot of work, good job. You basically did what I did with https://github.com/cretz/pgnio after finding bugs here and realizing it was basically abandoned.

@marat-gainullin
Copy link
Contributor Author

This work is intended to fill the gap in async database connectivity for my other project - Septima
https://github.com/marat-gainullin/septima

Your project is cool. Especially I like support of COPY protocol.
We could combine our effort to make similar work for other DBMSes.

Copy link
Owner

@alaisi alaisi left a comment

Choose a reason for hiding this comment

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

Thanks for the effort you have put into this. I think with a bit of polish we can get this to a state where it can be merged.

return pooledConnection.completeScript(validationQuery)
.handle((rss, th) -> {
if (th != null) {
return ((PooledPgConnection) pooledConnection).delegate.close()
Copy link
Owner

Choose a reason for hiding this comment

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

Does this leave the pool size at the wrong value?

Copy link
Contributor Author

@marat-gainullin marat-gainullin Feb 13, 2019

Choose a reason for hiding this comment

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

Basically, no. The exceptionally completed Future is returned here and than it composed later. It should lead to .exceptionally handler been invoked later. That handler has logic of decreasing of pool size if any exception occurs. But, i haven't checked this by my own eye yet. So, it should be checked. Fortunatelly, there is a test for bad validationQuery that can be examined with a debugger & eye.

Copy link
Contributor Author

@marat-gainullin marat-gainullin Feb 14, 2019

Choose a reason for hiding this comment

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

Indeed, exceptions are handled in a general manner here and pool size is decreased correctly. I've checked this by hand.

@@ -0,0 +1,15 @@
package com.pgasync;
Copy link
Owner

Choose a reason for hiding this comment

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

Why the new package structure?

Copy link
Contributor Author

@marat-gainullin marat-gainullin Feb 13, 2019

Choose a reason for hiding this comment

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

The new package structure is proposed to get rid of clumsy name impl and to be able to give an implementation a name like a github.
If you have thoughts about more gracefull package structure, than i'll refactor it with pleasure.


private final PgConnection delegate;
private PooledPgPreparedStatement evicted;
private final LinkedHashMap<String, PooledPgPreparedStatement> statements = new LinkedHashMap<>() {
Copy link
Owner

Choose a reason for hiding this comment

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

LinkedHashMap is not thread safe but is mutated without any locking

Copy link
Contributor Author

@marat-gainullin marat-gainullin Feb 13, 2019

Choose a reason for hiding this comment

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

Check the JavaDoc on com.pgasync.Connection interface please. Connections are desined to be never thread safe. So, it is not an issue since statements map is a PooledPgConnection instance field.

Copy link
Owner

@alaisi alaisi Feb 13, 2019

Choose a reason for hiding this comment

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

Ah, you're correct, I tripped on the deep nesting of classes.

counter = 0;
prefix = "_" + prefix;
}
return prefix + ++counter;
Copy link
Owner

Choose a reason for hiding this comment

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

Not thread-safe, counter should be an AtomicLong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, currently it is a bug. But there is another option. According to Postgres protocol, prepared statements exist within a Postgres session only, and so wouldn't be better to refactor the only use case of NameSequence and make it instance non static? This will help us to avoid counter contention.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, that sounds like a better choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@marat-gainullin
Copy link
Contributor Author

@alaisi Do you consider to add more review comments or improvement proposals?

@alaisi alaisi merged commit efd7f1f into alaisi:master Mar 11, 2019
@alaisi
Copy link
Owner

alaisi commented Mar 11, 2019

Reviewed and merged, thanks for the effort!

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.

3 participants