Return-Path: Delivered-To: apmail-db-jdo-dev-archive@www.apache.org Received: (qmail 90258 invoked from network); 13 Apr 2007 18:36:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Apr 2007 18:36:33 -0000 Received: (qmail 72300 invoked by uid 500); 13 Apr 2007 18:36:39 -0000 Mailing-List: contact jdo-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-dev@db.apache.org Received: (qmail 72284 invoked by uid 99); 13 Apr 2007 18:36:39 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Apr 2007 11:36:39 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [192.18.42.249] (HELO nwk-ea-fw-1.sun.com) (192.18.42.249) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Apr 2007 11:36:32 -0700 Received: from d1-sfbay-10.sun.com ([192.18.39.120]) by nwk-ea-fw-1.sun.com (8.13.6+Sun/8.12.9) with ESMTP id l3DIaBZM016826 for ; Fri, 13 Apr 2007 11:36:11 -0700 (PDT) Received: from conversion-daemon.d1-sfbay-10.sun.com by d1-sfbay-10.sun.com (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) id <0JGG004018YPQ700@d1-sfbay-10.sun.com> (original mail from Craig.Russell@Sun.COM) for jdo-dev@db.apache.org; Fri, 13 Apr 2007 11:36:11 -0700 (PDT) Received: from [129.146.30.129] by d1-sfbay-10.sun.com (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPSA id <0JGG004AD90BXV20@d1-sfbay-10.sun.com> for jdo-dev@db.apache.org; Fri, 13 Apr 2007 11:36:11 -0700 (PDT) Date: Fri, 13 Apr 2007 11:36:10 -0700 From: Craig L Russell Subject: Re: enlistment of native connections for optimistic txs In-reply-to: <461B52EE.6080609@objectmagic.org> Sender: Craig.Russell@Sun.COM To: Apache JDO project , JDO Expert Group Message-id: <71CDF8BA-E291-4AB9-9E36-F24F44BA13FE@SUN.com> MIME-version: 1.0 X-Mailer: Apple Mail (2.752.3) Content-type: multipart/signed; protocol="application/pkcs7-signature"; boundary=Apple-Mail-10-613674902; micalg=sha1 References: <1176065353.461955493a030@webmail.jpox.org> <5E68EE17-2CA0-4D25-8326-358DE42BF846@SUN.com> <461B52EE.6080609@objectmagic.org> X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-10-613674902 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Hi Guido, A new proposal is attached below. On Apr 10, 2007, at 2:03 AM, Guido Anzuoni wrote: > Craig L Russell wrote: >> Hi Erik, >> >> Thanks for clarifying your proposal. >> >> I agree that this improves portability, but with a penalty. You =20 >> can no >> longer use optimistic concurrency once you decide to do some native >> SQL, even if you don't ever perform any INSERT, DELETE, or UPDATE >> statements. And this will have negative performance consequences for >> some applications. >> >> While backward compatibility is important, I would agree with you =20 >> that >> correctness is even more important. So it doesn't bother me too much >> if we change the semantic so that by default, getting a datastore >> connection is equivalent to doing a flush in an optimistic >> transaction. But I'd still like to give the user the ability to get >> the same level of performance they now enjoy by deferring the >> enlistment in the datastore transaction to flush or commit. >> >> So how about adding a flag that defaults to true if not specified to >> enlist the datastore connection in the datastore transaction? >> >> >> Connection getDataStoreConnection() >> >> This method is equivalent to getDataStoreConnection(true). Seems like the default should be different based on whether you are =20 in a JDO transaction. So maybe the default should be getDataStoreConnection=20 (pm.currentTransaction().isActive()) >> >> Connection getDataStoreConnection(boolean enlist) >> >> If this method is called outside an active transaction, the object >> returned will not be enlisted in any >> transaction, regardless of the setting of the enlist parameter. > In this case, the user does not know that his request has not been =20 > honored. Maybe it makes sense to throw a JDOUserException, since there is no =20 transaction in which to enlist the connection, and the default is =20 false. A user can only get the exception by asking for something that =20= is impossible. > >> >> If it is called while a datastore transaction is active, the object >> returned will be enlisted in the current transaction, regardless of >> the setting of the enlist parameter. >> > Again, the implementation might do something different from what =20 > requested. Right, either a non-enlisted connection (enlist=3D=3Dfalse) or the =20 connection enlisted in the current transaction. The use case for this is to grab a non-enlisted connection that is =20 used e.g. to get a sequence number that will never be rolled back. > >> If it is called while an optimistic transaction is active, and the >> enlist parameter is true, a datastore transaction is begun if not >> already begun, and the object returned will be enlisted in the =20 >> current >> datastore transaction. >> >> If it is called while an optimistic transaction is active, the enlist >> parameter is false, and a datastore transaction is already begun, the >> object returned will be enlisted in the datastore transaction. > Same as above Right, either a separate non-enlisted connection (enlist=3D=3Dfalse) or =20= the connection enlisted in the current transaction (enlist=3D=3Dtrue). > >> If it is called while an optimistic transaction is active, the enlist >> parameter is false, and a datastore transaction is not already begun, >> the object returned will not be enlisted in any datastore =20 >> transaction. >> > What if the user issues some INSERT, DELETE, UPDATE ? This is the user's choice, which is not a default behavior, but =20 something explicitly asked for. The default will always be to get an =20 enlisted connection, and the only way to get a non-enlisted =20 connection is to ask for it. > Is it possible to call conn.commit() ? Yes, the non-enlisted connection changes were already committed (auto-=20= commit). We should add this to the spec, that the non-enlisted =20 connection is auto-commit. > > I agree that there is a potential penalty in optimistic =20 > transactions if > we blindly enlist native connections but, if we let the user know > exactly what is going on, > an aware decision can be taken. > getDataStoreConnection() will always return the enlisted connection if > any, otherwise null is returned (maybe getNativeConnection() could > return null). I think that returning null is never the right behavior. > Now, if the user wants to access a consistent backend, he HAVE to > flush(), triggering connection enlistment (what if there are no =20 > pending > updates ?). > If the user wants to operate on an independent connection to the same > datastore used by the PM he could use what is configured in the PMF > (OK, some helper methods might...help). I think that inventing a parallel mechanism is overkill if we can =20 give users what the need from this one. > It could be also achieved with a different handling of the proposed > enlist flag for the 'false' scenarios, but it would be strange to > request to the > PM a datastore connection the PM is not using at all !!!. It would =20 > look > like a data source. Yes, that's the intent. There is no need for the user to somehow go =20 behind the scenes to figure out how the PMF is configured and get a =20 connection from that same data source. Craig Connection getDataStoreConnection() This method is equivalent to getDataStoreConnection=20 (pm.currentTransaction().isActive()). That is, it defaults to =20 getDataStoreConnection(true) is a JDO transaction is active, and =20 getDataStoreConnection(false) if not. JDOConnection getDataStoreConnection(boolean enlist) This method returns either a JDOConnection whose underlying native =20 connection is enlisted in the native datastore transaction in use by =20 the persistence manager; or a JDOConnection whose underlying native =20 connection is not enlisted in any native transaction. An unenlisted =20 connection is set to auto-commit if using a data source that has this =20= concept (e.g. JDBC). If this method is called outside an active transaction, with the =20 enlist parameter false, the object returned will not be enlisted in =20 any transaction. If this method is called outside an active =20 transaction, with the enlist parameter true, JDOUserException is thrown. If this method is called while a datastore transaction is active, =20 with the enlist parameter false, the object returned will not be =20 enlisted in any transaction. If this method is called while a =20 datastore transaction is active, with the enlist parameter true, the =20 object returned will be enlisted in the current native datastore =20 transaction. If this method is called while an optimistic transaction is active, =20 with the enlist parameter false, the object returned will not be =20 enlisted in any transaction. If this method is called while an =20 optimistic transaction is active, and the enlist parameter is true, a =20= native datastore transaction is begun if not already begun, and the =20 object returned will be enlisted in the current native datastore =20 transaction. Craig > > Guido. >> >> Craig >> >> On Apr 8, 2007, at 1:49 PM, Erik Bengtson wrote: >> >>> >>> Hi, >>> >>> This is a change proposal to the spec with regards to enlistment of >>> native >>> connections when optimistic transactions are used. >>> >>> The enlistment of native connections into a JDO transaction is >>> conditioned to >>> the fact that a flush call has been performed before the =20 >>> connection is >>> obtained. >>> >>> The flush call is a JDO implementation decision which can differ =20 >>> between >>> different implementations. See the example: >>> >>> 1. tx.begin(); >>> 2. //more operations here.... >>> 3. JDOConnection conn =3D pm.getDataStoreConnection(); >>> 4. Connection sqlconn =3D (Connection) conn.getNativeConnection(); >>> 5. sqlconn.execute("DELETE FROM ANIMAL WHERE NAME =3D 'CAT'") >>> 5. conn.close(); >>> 6. tx.rollback(); >>> >>> There are two possible behaviors: >>> >>> - The JDO implementation decides to perform a flush between 1 and =20= >>> 3: the >>> connection is enlisted, and DELETE all CATS from ANIMAL is rolled =20= >>> back >>> - The JDO implementation decides to NOT perform a flush between 1 =20= >>> and >>> 3: the >>> connection is not enlisted, and DELETE all CATS from ANIMAL is not >>> rolled back >>> >>> As you can see, this is not portable and not ACID, so I would =20 >>> like to >>> propose >>> that enlistment of connections is done whenever a transaction is =20 >>> opened. >>> >>> The change is to the following paragraph: >>> >>> The JDO spec =A712.16 - getDataStoreConnection: >>> >>> "If this method is called while a datastore transaction is active, >>> the object >>> returned will be enlisted in the current transaction. If called =20 >>> in an >>> optimistic transaction before flush has been called, or outside an >>> active >>> transaction, the object returned will not be enlisted in any >>> transaction." >>> >>> AS: >>> >>> "If this method is called while a datastore or optimistc transaction >>> is active, >>> the object returned will be enlisted in the current transaction. If >>> called >>> outside an active transaction, the object returned will not be >>> enlisted in any >>> transaction." >>> >>> >> >> Craig Russell >> Architect, Sun Java Enterprise System http://java.sun.com/products/=20= >> jdo >> 408 276-5638 mailto:Craig.Russell@sun.com >> P.S. A good JDO? O, Gasp! >> > Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:Craig.Russell@sun.com P.S. A good JDO? O, Gasp! --Apple-Mail-10-613674902 Content-Transfer-Encoding: base64 Content-Type: application/pkcs7-signature; name=smime.p7s Content-Disposition: attachment; filename=smime.p7s MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIGUDCCAwkw ggJyoAMCAQICECpJVMO68ii+Xfsc1O1YYFIwDQYJKoZIhvcNAQEFBQAwYjELMAkGA1UEBhMCWkEx JTAjBgNVBAoTHFRoYXd0ZSBDb25zdWx0aW5nIChQdHkpIEx0ZC4xLDAqBgNVBAMTI1RoYXd0ZSBQ ZXJzb25hbCBGcmVlbWFpbCBJc3N1aW5nIENBMB4XDTA2MTIwOTE5NTEwNVoXDTA3MTIwOTE5NTEw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