From: Toru SHIMOGAKI <shimogaki.toru@gmail.com>
To: Oliver Jowett <oliver@opencloud.com>
To: Gregory Stark <stark@enterprisedb.com>
To: pgsql-jdbc@postgresql.org
Cc: oru SHIMOGAKI <shimogaki.toru@oss.ntt.co.jp>
Subject: Re: proposal: setKeepAlive
Date: Mon, 11 Feb 2008 20:05:19 +0900
Message-ID: <e43b8e4f0802110305j169efd9av34e7df184cc7f395@mail.gmail.com> (raw)
In-Reply-To: <47AE5B66.5070005@opencloud.com>
References: <47AC666C.9070704@oss.ntt.co.jp>
<87abmb2weo.fsf@oxford.xeocode.com>
<47AE2D07.50904@opencloud.com>
<87zlu9k9c0.fsf@oxford.xeocode.com>
<47AE36DD.9050102@opencloud.com>
<87r6flk4fz.fsf@oxford.xeocode.com>
<47AE5B66.5070005@opencloud.com>
The attached is the second version of setKeepAlive patch, which enables
that user can turn the configuration flag on/off. The default is off.
2008/2/10, Oliver Jowett <oliver@opencloud.com>:
> I agree that aggressive keepalives are not particularly useful in that case.
I agree the above too, and I don't think TCP keepalive is a perfect
solution. As Gregory already said, to provide a detailed
application-specific monitoring, some kind of application level test
(maybe using setQueryTimeout()) is still needed.
But nonetheless I think some of the cases are solved by this simple
keepalive.
For instance, resource collection without server rebooting on an
application server side, which is occupied by lost connections:
1. There are master-slave database servers connecting to a shared disk,
and application servers connect the master server first.
2. If the master database server gets down and fails over to the slave
server by a high-availability clustering suite, then connections from
the application servers to the master server are remained and not to be
collected, because JDBC driver doesn't send any exceptions in this case,
so application can't take measures to solve it.
3. If hundreds / thousands of connections are remained, a large quantity
of resources used by the lost connections die in vain and should be
removed without application server rebooting sooner or later.
I do hope all the dead server detection is implemented. I'd like to
avoid JDBC driver doesn't say anything in this case now. It seems to
me implementing setQueryTimeout() is so easy as doing setKeepAlive().
I think this patch just provides the least-level assuarance.
Best regards,
Attachments:setKeepAlive_v2.patch (text/x-patch, 4.6K) download
diff -cprN postgresql-jdbc-8.3-603.src-orig/doc/pgjdbc.xml postgresql-jdbc-8.3-603.src/doc/pgjdbc.xml
*** postgresql-jdbc-8.3-603.src-orig/doc/pgjdbc.xml 2008-01-08 15:56:26.000000000 +0900
--- postgresql-jdbc-8.3-603.src/doc/pgjdbc.xml 2008-02-11 16:56:58.000000000 +0900
*************** Connection conn = DriverManager.getConne
*** 592,597 ****
--- 592,607 ----
</varlistentry>
<varlistentry>
+ <term><varname>tcpkeepalive</varname> = <type>boolean</type></term>+ <listitem>+ <para>+ Enable or disable TCP keep-alive probe. The default is+ <literal>false</literal>.+ </para>+ </listitem>+ </varlistentry>+ + <varlistentry>
<term><varname>stringtype</varname> = <type>String</type></term>
<listitem>
<para>
diff -cprN postgresql-jdbc-8.3-603.src-orig/org/postgresql/Driver.java.in postgresql-jdbc-8.3-603.src/org/postgresql/Driver.java.in
*** postgresql-jdbc-8.3-603.src-orig/org/postgresql/Driver.java.in 2008-01-08 15:56:26.000000000 +0900
--- postgresql-jdbc-8.3-603.src/org/postgresql/Driver.java.in 2008-02-11 17:06:16.000000000 +0900
*************** public class Driver implements java.sql.
*** 442,447 ****
--- 442,449 ----
new String[] { "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2" } },
{ "loginTimeout", Boolean.FALSE,
"The login timeout, in seconds; 0 means no timeout beyond the normal TCP connection timout." },
+ { "tcpkeepalive", Boolean.FALSE,+ "Enable or disable TCP keep-alive probe." },
{ "stringtype", Boolean.FALSE,
"The type to bind String parameters as (usually 'varchar'; 'unspecified' allows implicit casting to other types)",
new String[] { "varchar", "unspecified" } },
diff -cprN postgresql-jdbc-8.3-603.src-orig/org/postgresql/core/v2/ConnectionFactoryImpl.java postgresql-jdbc-8.3-603.src/org/postgresql/core/v2/ConnectionFactoryImpl.java
*** postgresql-jdbc-8.3-603.src-orig/org/postgresql/core/v2/ConnectionFactoryImpl.java 2008-01-08 15:56:27.000000000 +0900
--- postgresql-jdbc-8.3-603.src/org/postgresql/core/v2/ConnectionFactoryImpl.java 2008-02-11 17:10:04.000000000 +0900
*************** public class ConnectionFactoryImpl exten
*** 46,51 ****
--- 46,54 ----
boolean requireSSL = (info.getProperty("ssl") != null);
boolean trySSL = requireSSL; // XXX temporary until we revisit the ssl property values
+ // - the TCP keep alive setting+ boolean requireTCPKeepAlive = (Boolean.valueOf(info.getProperty("tcpkepealive")).booleanValue());+
if (logger.logDebug())
logger.debug("Trying to establish a protocol version 2 connection to " + host + ":" + port);
*************** public class ConnectionFactoryImpl exten
*** 69,74 ****
--- 72,80 ----
if (trySSL)
newStream = enableSSL(newStream, requireSSL, info, logger);
+ // Enable TCP keep-alive probe if required.+ newStream.getSocket().setKeepAlive(requireTCPKeepAlive);+
// Construct and send a startup packet.
sendStartupPacket(newStream, user, database, logger);
diff -cprN postgresql-jdbc-8.3-603.src-orig/org/postgresql/core/v3/ConnectionFactoryImpl.java postgresql-jdbc-8.3-603.src/org/postgresql/core/v3/ConnectionFactoryImpl.java
*** postgresql-jdbc-8.3-603.src-orig/org/postgresql/core/v3/ConnectionFactoryImpl.java 2008-01-08 15:56:27.000000000 +0900
--- postgresql-jdbc-8.3-603.src/org/postgresql/core/v3/ConnectionFactoryImpl.java 2008-02-11 17:09:58.000000000 +0900
*************** public class ConnectionFactoryImpl exten
*** 50,55 ****
--- 50,58 ----
boolean requireSSL = (info.getProperty("ssl") != null);
boolean trySSL = requireSSL; // XXX temporary until we revisit the ssl property values
+ // - the TCP keep alive setting+ boolean requireTCPKeepAlive = (Boolean.valueOf(info.getProperty("tcpkeepalive")).booleanValue());+
// NOTE: To simplify this code, it is assumed that if we are
// using the V3 protocol, then the database is at least 7.4. That
// eliminates the need to check database versions and maintain
*************** public class ConnectionFactoryImpl exten
*** 80,85 ****
--- 83,91 ----
if (trySSL)
newStream = enableSSL(newStream, requireSSL, info, logger);
+ // Enable TCP keep-alive probe if required.+ newStream.getSocket().setKeepAlive(requireTCPKeepAlive);+
// Construct and send a startup packet.
String[][] params = {
{ "user", user },
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: shimogaki.toru@gmail.com, oliver@opencloud.com, stark@enterprisedb.com, shimogaki.toru@oss.ntt.co.jp
Subject: Re: proposal: setKeepAlive
In-Reply-To: <e43b8e4f0802110305j169efd9av34e7df184cc7f395@mail.gmail.com>
References: <47AC666C.9070704@oss.ntt.co.jp> <87abmb2weo.fsf@oxford.xeocode.com> <47AE2D07.50904@opencloud.com> <87zlu9k9c0.fsf@oxford.xeocode.com> <47AE36DD.9050102@opencloud.com> <87r6flk4fz.fsf@oxford.xeocode.com> <47AE5B66.5070005@opencloud.com> <e43b8e4f0802110305j169efd9av34e7df184cc7f395@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox