pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Deadlock detection
4+ messages / 4 participants
[nested] [flat]

* Re: Deadlock detection
@ 2009-04-15 21:33  bdbusch <bdbuschg@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: bdbusch @ 2009-04-15 21:33 UTC (permalink / raw)
  To: pgsql-jdbc


We came across this thread today researching our issue. Tersely as possible:

JBoss 4.2.3, Solaris 10 (x64), PG 8.2 (with GIS), Hibernate/EJB2.

We were storing a GIS column as a LOB in WKT format (e.g., POINT(23.22
23.22)) and ocassionly would have apparent transactions timeout trying to
insert into this table. (turns out that a T doesn't timeout per se, it just
never finishes and the timeout our customers see are Ajax/session related).

- JBoss logs would show the transaction committing from Hibernate.

- Thread dumps on the JVM would show the stuck thread in 

"http-0.0.0.0-8443-4" daemon prio=3 tid=0x00000000019ee400 nid=0x70 runnable
[0xfffffd7eab923000..0xfffffd7eab9268a0]
   java.lang.Thread.State: RUNNABLE
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at
java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
        - locked <0xfffffd7fad49c858> (a java.io.BufferedOutputStream)
        at java.io.FilterOutputStream.write(FilterOutputStream.java:80)
        at org.postgresql.core.PGStream.Send(PGStream.java:208)
        at
org.postgresql.core.v3.SimpleParameterList.writeV3Value(SimpleParameterList.java:258)
        at
org.postgresql.core.v3.QueryExecutorImpl.sendBind(QueryExecutorImpl.java:861)
        at
org.postgresql.core.v3.QueryExecutorImpl.sendOneQuery(QueryExecutorImpl.java:1052)
        at
org.postgresql.core.v3.QueryExecutorImpl.sendQuery(QueryExecutorImpl.java:643)
        at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:344)
        - locked <0xfffffd7fad4a1af8> (a
org.postgresql.core.v3.QueryExecutorImpl)
        at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2592)
        at sun.reflect.GeneratedMethodAccessor152.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$StatementHandler.invoke(AbstractJdbc23PooledConnection.java:471)
        at $Proxy291.executeBatch(Unknown Source)
        at
org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:774)
        at
org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
        at
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
        at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
        at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
        at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
...

(no other monitor/blocks - ONLY thread "running" at the time!)

- PGAdmin3 server stats/locks would show a slew of locks on this table (no
other locks, so no traditional  deadlock per se).

- truss(1M) on the postgres pid holding the locks showed:

% truss -p 14713
send(9, 0x082FBF00, 8192, 0)    (sleeping...)

pfiles(1M) on this pid showed that fd9 was this same socket connected to our
JVM and blocked

clearly (at least to us) - the database was writing to this socket (seen
from truss) and the jvm was writing to this socket (seen from jvm stack)


- netstat(1M) showed no send/recvQ data on this socket

- PG log showed 

-- query was simple insert into FeatureName(xxx) values ($1, ...)
-- the geom text/LOB had a 22K bind (large country MULTIPOLYGON)

WORKAROUND

We're going to remove the string (we determined our client app doesn't use
the geom for this table) or at least convert it to the binary version long
term when we start using it again.

WAY FORWARD

We're planning on upgrading to 8.3.17 (? whatever is the latest) and hope
that this deadlock in the driver doesn't happen again.

Just posting this if it might be useful for your testing.



-- 
View this message in context: http://www.nabble.com/Deadlock-detection-tp21580039p23067564.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Deadlock detection
@ 2009-06-01 23:30  Kris Jurka <books@ejurka.com>
  1 sibling, 2 replies; 4+ messages in thread

From: Kris Jurka @ 2009-06-01 23:30 UTC (permalink / raw)
  To: Oliver Jowett <oliver@opencloud.com>; +Cc: Simon Riggs <simon@2ndQuadrant.com>; Daniel Migowski <dmigowski@ikoffice.de>; pgsql-jdbc



On Thu, 22 Jan 2009, Oliver Jowett wrote:

> Kris Jurka wrote:
>>
>> On Thu, 22 Jan 2009, Oliver Jowett wrote:
>>>
>>> This passes the regression testsuite with antiDeadlock=true, but I don't
>>> have a deadlock testcase on hand to try unfortunately.
>>>
>>
>> This has a test case which deadlocks consistently:
>>
>> http://archives.postgresql.org/pgsql-jdbc/2008-10/msg00045.php
>
> Perfect, thanks
>
> My changes seem to pass BatchDeadLock with antiDeadlock=true (and still
> hang with antiDeadlock=false):

I'm not really sure what to do with this code.  It does two different 
things and what is does best really wasn't the thrust of this thread.

1) It avoids deadlocks by buffering the writes in local memory.  That's 
great, but wasn't really the point of the thread.  Would we suggest people 
run with antiDeadlock=true in a production environment to avoid deadlocks? 
If so, why wouldn't it be the default.

2) It warns when a deadlock has potentially occurred with stack trace 
information to provide the call location.  That's good, but it can't be 
100% accurate.  With a small timeout it may warn when there wouldn't be an 
actual deadlock and with a large timeout it may not warn when the call 
would have deadlocked without the intermediate buffer.  Having the 
intermediate buffer means that you aren't testing the same thing, so a 
success with antiDeadlock=true has no implications as to whether your 
application will deadlock with it turned off.  Previously it was discussed 
that you'd really want to cap the buffer size, so perhaps relating the 
maximum buffer size to Socket.getSendBufferSize might make the results of 
testing with antiDeadlock more representative of the behavior with it 
turned off.

So it's a useful piece of code, but I'm not sure what context it should 
really be used in.  Is anyone using this?  For what purpose?

Kris Jurka



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Deadlock detection
@ 2009-06-04 06:01  Oliver Jowett <oliver@opencloud.com>
  parent: Kris Jurka <books@ejurka.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Oliver Jowett @ 2009-06-04 06:01 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: Simon Riggs <simon@2ndQuadrant.com>; Daniel Migowski <dmigowski@ikoffice.de>; pgsql-jdbc

Kris Jurka wrote:

> So it's a useful piece of code, but I'm not sure what context it should 
> really be used in.  Is anyone using this?  For what purpose?

I'm not using it, it was just a quick hack to try to narrow down a 
deadlock problem IIRC ..

-O



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Deadlock detection
@ 2009-06-04 21:53  Simon Riggs <simon@2ndQuadrant.com>
  parent: Kris Jurka <books@ejurka.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Simon Riggs @ 2009-06-04 21:53 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: Oliver Jowett <oliver@opencloud.com>; Daniel Migowski <dmigowski@ikoffice.de>; pgsql-jdbc


On Mon, 2009-06-01 at 19:30 -0400, Kris Jurka wrote:

> 1) It avoids deadlocks by buffering the writes in local memory.  That's 
> great, but wasn't really the point of the thread.  Would we suggest people 
> run with antiDeadlock=true in a production environment to avoid deadlocks? 
> If so, why wouldn't it be the default.

> So it's a useful piece of code, but I'm not sure what context it should 
> really be used in.  Is anyone using this?  For what purpose?

The reason the code was written went away before the code could sensibly
be used. We removed the contention in the database by redesign rather
than by JDBC changes. Thanks to Oliver for taking the time.

Having said that, it is clear there were some issues there that are not
fully explained. It may be that it is a JDBC driver issue, but also it
may be a protocol/handling issue. Intermittent issues are hard to get a
full state on to debug, and we are left looking at spoor or wishing we
had some.

I would like to see code added to the driver for (1), or other code. My
main request is that we have some way of responding to the problems that
we know can exist. The main argument for not buffering everything would
be performance, I think. 99.9% of users are happy as is, so to act in a
way that effects them would be bad. Sometimes, a "safe mode" would be a
useful thing to be able to enable, as a way of eliminating doubt.

-- 
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2009-06-04 21:53 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-04-15 21:33 ` bdbusch <bdbuschg@gmail.com>
2009-06-01 23:30 ` Kris Jurka <books@ejurka.com>
2009-06-04 06:01   ` Oliver Jowett <oliver@opencloud.com>
2009-06-04 21:53   ` Simon Riggs <simon@2ndQuadrant.com>

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