Re: PGStream synchronization

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Maciek Sakrejda <msakrejda(at)truviso(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PGStream synchronization
Date: 2009-08-27 00:55:28
Message-ID: 4A95D980.3070809@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Maciek Sakrejda wrote:

> Any thoughts?

How about, instead of using raw monitor synchronization to provide
mutual exclusion on access to the stream, we use a lock object (i.e.
something similar to java.util.concurrent.locks.Lock, though we can't
use exactly that class before 1.5 obviously), try to grab the lock
before close, and behave differently depending on if we succeeded or not.

So the close logic can look something like this:

if (lock.tryLock()) {
// we have exclusive access to the connection
// do a normal shutdown
try {
sendTerminate();
stream.close();
} finally {
lock.unlock();
}
} else {
// something is concurrently using the connection
// just abruptly close the connection
stream.close();
}

In the concurrent case, we don't send Terminate, but we also don't risk
sending it at the wrong point in the stream.

This means that a concurrent Connection.close() while something is
happening will result in an "unexpected client EOF" logged on the server
side, but that's almost what you want in this case anyway .. concurrent
close pretty much means "help, abort this!" ..

-O

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Maciek Sakrejda 2009-08-27 06:36:43 PGStream synchronization
Previous Message Maciek Sakrejda 2009-08-27 00:37:26 Re: PGStream synchronization