Re: Deadlock detection

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: PostgreSQL - JDBC <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Deadlock detection
Date: 2009-01-21 10:48:55
Message-ID: 4976FD97.7040609@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Oliver Jowett wrote:

> If you want a minimally invasive approach (in terms of rewriting driver
> code) and some extra overhead isn't a problem then I would suggest
> something like this:
>
> (1) spawn a separate write thread for each connection; it reads from an
> unbounded buffer
>
> (2)instead of writes from the thread running a query going directly to
> the real stream, they instead go into the buffer (without blocking), and
> the corresponding write thread picks them up for immediate writing
>
> (3) implement OutputStream.flush() to wait for the buffer to empty,
> *with a timeout*. If you hit the timeout while waiting to flush, then
> you've detected a potential deadlock case and can dump out some state
> and then continue anyway.

Also, if it wasn't obvious, I'm thinking you do this by a custom
OutputStream implementation that just sits on top of the real stream;
you don't need to change any of the callers so it's just a bit of setup
code then the vast majority of the driver guts are unchanged. You could
even make it conditional on a connection parameter ..

-O

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Simon Riggs 2009-01-21 11:30:40 Re: Deadlock detection
Previous Message Oliver Jowett 2009-01-21 10:38:05 Re: Deadlock detection