X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 59A8FD1B178 for ; Sat, 17 Jul 2004 20:22:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 09791-10 for ; Sat, 17 Jul 2004 23:22:12 +0000 (GMT) Received: from mail.svhost.com.ar (mail.svhost.com.ar [200.80.239.22]) by svr1.postgresql.org (Postfix) with ESMTP id 89E1BD1B170 for ; Sat, 17 Jul 2004 20:22:08 -0300 (ADT) Received: from sistemat.com.ar (devel.sistemat.com.ar [192.168.1.40]) by mail.svhost.com.ar (Postfix) with ESMTP id 1830B1DE13; Sat, 17 Jul 2004 20:20:30 -0300 (ART) Message-ID: <40F9B6CB.6050407@sistemat.com.ar> Date: Sat, 17 Jul 2004 20:31:23 -0300 From: "Dario V. Fassi" Organization: SISTEMATICA ingenieria de software srl User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: es, es-ar, en-us, en MIME-Version: 1.0 To: Oliver Jowett Cc: Kris Jurka , "pgsql-jdbc@postgresql.org" Subject: Re: revisiting transaction isolation References: <40F8A692.8000105@opencloud.com> <40F9AF24.9090601@opencloud.com> In-Reply-To: <40F9AF24.9090601@opencloud.com> Content-Type: multipart/alternative; boundary="------------040303060307050002060006" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.0 tagged_above=0.0 required=5.0 tests=HTML_20_30, HTML_MESSAGE, HTML_TITLE_EMPTY X-Spam-Level: * X-Archive-Number: 200407/222 X-Sequence-Number: 10606 This is a multi-part message in MIME format. --------------040303060307050002060006 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit The code bellow throw an exception and I can see any transaction in progress. Dario. String url = getJdbcUrl(); try { isCon = false; con = DriverManager.getConnection( url, usr, pwd ); if ( con == null ) return false; isCon = true; con.setAutoCommit( autoCommit ); int tiso = con.getTransactionIsolation(); try { dmd = con.getMetaData(); int defTxIsolation = -1; if ( dmd != null && dmd.supportsTransactionIsolationLevel( tranIsolation ) ) { defTxIsolation = dmd.getDefaultTransactionIsolation(); } if ( tranIsolation >= 0 && tranIsolation != defTxIsolation ) { tranIsolation = defTxIsolation; } } if ( tranIsolation >= 0 ) { con.setTransactionIsolation( tranIsolation ); tiso = con.getTransactionIsolation(); } } catch ( SQLException se ) { se.printStackTrace(); lastErrMsg = "\n ERROR: TransactionIsolation No Soportado = " + Tools.InfoException( se ); } Oliver Jowett wrote: > Kris Jurka wrote: > >> >> On Sat, 17 Jul 2004, Oliver Jowett wrote: >> >> >>> Currently, this type of code will fail: >>> >>> >>>> conn.setAutoCommit(false); >>>> if (conn.getTransactionIsolation() != >>>> Connection.TRANSACTION_SERIALIZABLE) >>>> conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); >>> >>> >>> The problem is that getTransactionIsolation() issues a query and >>> thus starts a new transaction, and then setTransactionIsolation() >>> complains you can't change isolation level mid-transaction. >>> >>> I'm not sure this is reasonable behaviour. One option is to make >>> getTransactionIsolation (and what other methods too?) not cause a >>> BEGIN to occur if there is no transaction in progress and autocommit >>> is off. >> >> >> >> I see no reason for getTransactionIsolation or any driver call to >> start a transaction, these are only SELECTs and won't be rolled back >> anyway. > > > It's ok for getTransactionIsolation(), but what about, say, metadata > queries -- we do want transaction isolation to apply there even if > it's just a SELECT, right? > > A quick skim of AbstractJdbc2Connection turns up these methods as > candidates for ignoring autocommit: > > - getTransactionIsolation() > - getPGType (both versions) on a cache miss > > It seems reasonable to suppress BEGINs for both of those cases. I can > put together a patch to do that. I'll leave the metadata queries alone > for the moment. > >>>> The return value of the method getTransactionIsolation should reflect >>>> the change in isolation level when it actually occurs. [...] >>> >> >> This seems confusing and error prone. > > > Ok -- I'll leave that alone too. > > -O --------------040303060307050002060006 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit
The code bellow throw an exception and I can see any transaction in progress.

Dario.

        String url   = getJdbcUrl();
        try {
            isCon = false;
            con = DriverManager.getConnection( url, usr, pwd );
            if ( con == null ) return false;
            isCon = true;
            con.setAutoCommit( autoCommit );
            int tiso  = con.getTransactionIsolation();
            try {
                    dmd = con.getMetaData();
                    int defTxIsolation  = -1;
                    if ( dmd != null && dmd.supportsTransactionIsolationLevel( tranIsolation ) ) {
                        defTxIsolation = dmd.getDefaultTransactionIsolation();
                    }
                    if ( tranIsolation >= 0 && tranIsolation != defTxIsolation ) {
                        tranIsolation = defTxIsolation;
                    }
                }
                if ( tranIsolation >= 0 ) {
                    con.setTransactionIsolation( tranIsolation );
                    tiso = con.getTransactionIsolation();
                }
            } catch ( SQLException se ) {
                se.printStackTrace();
                lastErrMsg = "\n ERROR: TransactionIsolation No Soportado = " + Tools.InfoException( se );
            }


Oliver Jowett wrote:
Kris Jurka wrote:

On Sat, 17 Jul 2004, Oliver Jowett wrote:


Currently, this type of code will fail:


 conn.setAutoCommit(false);
 if (conn.getTransactionIsolation() != Connection.TRANSACTION_SERIALIZABLE)
   conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);

The problem is that getTransactionIsolation() issues a query and thus starts a new transaction, and then setTransactionIsolation() complains you can't change isolation level mid-transaction.

I'm not sure this is reasonable behaviour. One option is to make getTransactionIsolation (and what other methods too?) not cause a BEGIN to occur if there is no transaction in progress and autocommit is off.


I see no reason for getTransactionIsolation or any driver call to start a transaction, these are only SELECTs and won't be rolled back anyway.

It's ok for getTransactionIsolation(), but what about, say, metadata queries -- we do want transaction isolation to apply there even if it's just a SELECT, right?

A quick skim of AbstractJdbc2Connection turns up these methods as candidates for ignoring autocommit:

 - getTransactionIsolation()
 - getPGType (both versions) on a cache miss

It seems reasonable to suppress BEGINs for both of those cases. I can put together a patch to do that. I'll leave the metadata queries alone for the moment.

The return value of the method getTransactionIsolation should reflect
the change in isolation level when it actually occurs. [...]

This seems confusing and error prone.

Ok -- I'll leave that alone too.

-O



--------------040303060307050002060006--