Re: Deadlock detection - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: Deadlock detection
Date
Msg-id 4976FD97.7040609@opencloud.com
Whole thread Raw
In response to Re: Deadlock detection  (Oliver Jowett <oliver@opencloud.com>)
List 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


pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: Deadlock detection
Next
From: Oliver Jowett
Date:
Subject: Re: Deadlock detection