TomEEDataSourceCreator ReadOnlyConnectionpool

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

TomEEDataSourceCreator ReadOnlyConnectionpool

Inwolf
Hi!
I'm using tomee-microprofile-8.0.3.
I've defined datasource in the webapp/WEB-INF/resources.xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <Resource id="managed" type="DataSource">
        JdbcDriver org.postgresql.Driver
        JdbcUrl jdbc:postgresql://localhost:5432/database_test
        UserName postgres
        Password postgres
        maxActive 5
        maxWait 2000
    </Resource>
</resources>

It uses tomcat's ConnectionPool from org.apache.tomcat.jdbc.pool.

I have two questions:
1. Property maxWait is not used - when I debug ConnectionPool I see that
maxActive is correctly set to 5 and maxWait is not set to 2000 - it uses the
default value of 30000. Why?

2. Running my app with the above datasource settings throws an exception:
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [http-nio-8080-exec-9]
NoWait: Pool empty. Unable to fetch a connection, none available[5 in use].
This happens because ConnectionPool tries to create pool with initial size
set to 10 by default in its init() method. But this is greater than
maxActive = 5 setting and it fails.
Prior to pool creation there is a checkPoolConfiguration() method in
ConnectionPool where the number of initialSize is checked and corrected:

if (properties.getMaxActive()<properties.getInitialSize()) {
            log.warn("initialSize is larger than maxActive, setting
initialSize to: "+properties.getMaxActive());
            properties.setInitialSize(properties.getMaxActive());
}

But this doesn't work because in TomEEDataSourceCreator properties are
wrapped in ReadOnlyConnectionpool and it doesn't call any setter methods
except for setDataSource():

@Override
        public Object invoke(final Object proxy, final Method method, final
Object[] args) throws Throwable {
            final String name = method.getName();
            if (!(name.startsWith("set") && args != null && args.length == 1
&& Void.TYPE.equals(method.getReturnType()))) {
                return method.invoke(delegate, args);
            }
            if (name.equals("setDataSource")) {
                delegate.setDataSource(args[0]);
            }
            return null;
        }
}

If I manually set initialSize less or equal to maxActive than the datasource
and the connectionPool are created.
There are more checks on wrong settings in checkPoolConfiguration() - it
means they are all useless and won't work.
So when a user sets any of settings manually he also should check for the
other settings default values and correct them too.
What's the purpose of wrapping poolConfiguration into
ReadOnlyConnectionpool? It seems to me that it's a bug. It's logged that a
setting is changed but it is not.
Is there a way to make checkPoolConfiguration() work as it was indended - to
automatically change wrong settings?



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Reply | Threaded
Open this post in threaded view
|

Re: TomEEDataSourceCreator ReadOnlyConnectionpool

Inwolf
Well, I've found the answer to the first question - it's a documented bug and
it's still open  https://issues.apache.org/jira/browse/TOMEE-2125
<https://issues.apache.org/jira/browse/TOMEE-2125>  .
You either change the source code or use some dumb property with the value
"maxWait" like
<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <Resource id="managed" type="DataSource">
        JdbcDriver org.postgresql.Driver
        JdbcUrl jdbc:postgresql://localhost:5432/database_test
        UserName postgres
        Password postgres
        maxActive 5
        maxWaitKey maxWait
        maxWait 2000
    </Resource>
</resources>

I still don't know what to do with the second problem - the only option is
to manually correct all settings?



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Reply | Threaded
Open this post in threaded view
|

Re: TomEEDataSourceCreator ReadOnlyConnectionpool

Zowalla, Richard
Hi,

thanks for your email.

Regarding TOMEE-2125 -> I just submitted a related PR [1] containing
the proposed fix (+ unit test)

Gruss
Richard

[1] https://github.com/apache/tomee/pull/762

Am Freitag, den 12.02.2021, 03:34 -0600 schrieb Inwolf:

> Well, I've found the answer to the first question - it's a documented
> bug and
> it's still open  https://issues.apache.org/jira/browse/TOMEE-2125
> <https://issues.apache.org/jira/browse/TOMEE-2125>  .
> You either change the source code or use some dumb property with the
> value
> "maxWait" like
> <?xml version="1.0" encoding="UTF-8"?>
> <resources>
>     <Resource id="managed" type="DataSource">
>         JdbcDriver org.postgresql.Driver
>         JdbcUrl jdbc:postgresql://localhost:5432/database_test
>         UserName postgres
>         Password postgres
>         maxActive 5
>         maxWaitKey maxWait
>         maxWait 2000
>     </Resource>
> </resources>
>
> I still don't know what to do with the second problem - the only
> option is
> to manually correct all settings?
>
>
>
> --
> Sent from:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html

smime.p7s (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: TomEEDataSourceCreator ReadOnlyConnectionpool

Inwolf
Wow, that was quick!
Thanks!



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html