pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marko Topolnik <marko.topolnik@gmail.com>
To: Steven Schlansker <stevenschlansker@gmail.com>
Cc: pgsql-jdbc@postgresql.org JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: New significance of holdable result sets in Java 8
Date: Thu, 13 Nov 2014 13:08:32 +0100
Message-ID: <EF9251DC-B579-4D64-B3FF-CCBB23F1846D@gmail.com> (raw)
In-Reply-To: <49F13D7D-3726-4482-B35A-2AD607E88EBF@gmail.com>
References: <771672CB-9567-4966-8CE9-9D84E4F858D8@gmail.com>
	<75C17D7A-95D9-471F-AF64-EFE83D971654@gmail.com>
	<5855156D-8010-4735-A63D-DC5DF5EABD27@gmail.com>
	<49F13D7D-3726-4482-B35A-2AD607E88EBF@gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

Yes, your approach makes perfect sense---as long as you don't care about transactional semantics.

If the transaction boundary is moved all the way to the end of serving the response, the following happens:

1. 200 OK status code reported, but transaction still not committed;
2. transaction may roll back due to errors in transfer;
3. thanks to buffering, the transfer may also fail _after_ the transaction has committed.

So, not only have you established quite messy and illogical transaction semantics for your client (for example, a typical onSuccess callback on the HTTP request cannot assume the transaction succeeded); the client has no idea _in principle_ what happened to the transaction if transfer is aborted for any reason.

In an earlier incarnation of my project I did indeed have setup exactly as you describe it, but after realizing the above problems, I had to back off and revert to standard transaction boundaries.


On 12. stu. 2014., at 23:04, Steven Schlansker <stevenschlansker@gmail.com> wrote:

> 
> On Nov 12, 2014, at 11:20 AM, Marko Topolnik <marko.topolnik@gmail.com> wrote:
>> 
>> I am aware of this approach; I even discuss it as a typical workaround in my blog post [1]. The problem is, this completely dispenses with the detailed and complex setup present in the View layer: the response format can be driven by the Accept HTTP header, encoding may be adapted to the request, and so on. I did pretty much that in my Clojure projects because Clojure's ecosystem isn't as well-developed so roll-your-own solutions are the norm. With Spring, however, you lose a great deal when you give your Controller method access to the raw response.
>> 
>> I have already developed a Stream-based REST service along the lines I discuss in the mentioned blog post and the advantages are quite clear to me. It is a direction that Spring would probably like to move in as well.
>> 
>> [1] http://www.airpair.com/v1/posts/spring-streams-memory-efficiency
>> ...
>> You still seem to dictate the output format directly from the Controller, the avoidance of which is motivating my approach.
>> 
> 
> Indeed, after reading your blog post, it looks like we have 95% the exact same solution.
> 
> The essential difference I propose is that instead of having a holdable ResultSet (which requires PG-JDBC changes)
> you hold the Connection/Statement/ResultSet with transaction open for the duration.
> 
> This way the transaction stays open for the duration of your request.  So you establish a stream all the way through
> from end client -> PG.
> 
> With your suggestion, a holdable ResultSet, you run into what Dave mentioned:
> 
> http://www.postgresql.org/docs/9.3/static/sql-declare.html
>> In the current implementation, the rows represented by a held cursor are copied into a temporary file or memory area so that they remain available for subsequent transactions.
> 
> So in fact you are just materializing the result set server side.  This IMO defeats the entire purpose - you cannot begin streaming out results until the materialize finishes (the holdable cursor will not be available until said materialize is done, I believe?  or at least the transaction will not commit until that point?)  Therefore my proposal is significantly more efficient and will never surprisingly materialize gigabytes of temporary disk usage.
> 
> Makes more sense?
> 



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (14+ messages)  latest in thread

Message-ID: <EF9251DC-B579-4D64-B3FF-CCBB23F1846D@gmail.com>
Permalink:  ../EF9251DC-B579-4D64-B3FF-CCBB23F1846D@gmail.com/
Also on:    postgresql.org/message-id/EF9251DC-B579-4D64-B3FF-CCBB23F1846D@gmail.com

 · 

reply

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: marko.topolnik@gmail.com, stevenschlansker@gmail.com
  Subject: Re: New significance of holdable result sets in Java 8
  In-Reply-To: <EF9251DC-B579-4D64-B3FF-CCBB23F1846D@gmail.com>
  References: <771672CB-9567-4966-8CE9-9D84E4F858D8@gmail.com> <75C17D7A-95D9-471F-AF64-EFE83D971654@gmail.com> <5855156D-8010-4735-A63D-DC5DF5EABD27@gmail.com> <49F13D7D-3726-4482-B35A-2AD607E88EBF@gmail.com> <EF9251DC-B579-4D64-B3FF-CCBB23F1846D@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