Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 1BDC3476D43 for ; Wed, 22 Jan 2003 01:10:18 -0500 (EST) Received: from rtlocal.trade-india.com (mail-relay.trade-india.com [203.196.129.235]) by postgresql.org (Postfix) with SMTP id 1EE5F476B58 for ; Wed, 22 Jan 2003 01:08:48 -0500 (EST) Received: (qmail 2019 invoked from network); 22 Jan 2003 06:04:03 -0000 Received: from unknown (HELO system67.trade-india-local.com) (192.168.0.67) by infocom-236-129-del.trade-india.com with SMTP; 22 Jan 2003 06:04:03 -0000 From: "Rajesh Kumar Mallah." Organization: Infocom Network Limited. To: Raj Mathur , pgsql-admin@postgresql.org Subject: Re: Transactions and HTTP Date: Wed, 22 Jan 2003 11:43:44 +0530 User-Agent: KMail/1.5 References: <15916.52618.390720.567048@mail.linux-delhi.org> <3E2DAA7A.60009@idigx.com> <15918.11595.192700.577364@mail.linux-delhi.org> In-Reply-To: <15918.11595.192700.577364@mail.linux-delhi.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200301221143.44321.mallah@trade-india.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/239 X-Sequence-Number: 7081 since its not possible/simple to have transactions spanning multiple HTTP requests may be (if requirements permits) 1,2,3 can be merged in a single step (transaction). regds mallah. On Wednesday 22 January 2003 11:04 am, Raj Mathur wrote: > Hi Thomas, > > >>>>> "Thomas" == Thomas Swan writes: > > Thomas> Raj Mathur wrote: > >> Hi, > >> > >> Writing a web-based application using PostgreSQL as the > >> back-end database. The master create functions look something > >> like this: > >> > >> 1. Accept ID from user. > >> > >> 2. Verify that ID doesn't exist in database. Start > >> transaction. Create blank record with ID as key. > >> > >> 3. Accept remaining data for record from user. > >> > >> 4. Enter data into newly-created blank record. End > >> transaction. > >> > >> Firstly,is it possible to have a transaction spanning multiple > >> instances of the CGI/mod_perl invocations? > > Thomas> Not easily. You are not always guaranteed the same httpd > Thomas> process when connecting. HTTP is stateless. > > Tell me about it :) > > >> Second, there are issues if the user session terminates for > >> some reason (e.g. user goes offline after the blank record has > >> been created, etc.) and I end up with a locked blank record in > >> the database. Would appreciate pointers to best practises in > >> handling this paradigm. > > Thomas> It is basically a poor design when using HTTP operations. > Thomas> You are better off using server-side session data to store > Thomas> all the information you will need for the complete > Thomas> database operation and then at your final stage of data > Thomas> entry do the record addtion inside of a transaction > Thomas> (i.e. one POST operation), if you want to rollback on > Thomas> error. This should eliminate your concerns over lost > Thomas> locks and hanging transactions. > > This is infeasible from the application point of view, since once the > user selects an ID to add to the database no other user must be > permitted to use that ID. Hence the two-stage process: creating a > blank record with the desired key, and populating that record. The > first phase ensures that no other user gets the key. > Off the top of my head I see two solutions to this: > > 1. Have a process that regularly goes through the database and deletes > blank records created more than (say) 30 minutes ago. Contrived, > inefficient and unmaintainable. > > 2. Hand off all database operations to a server process using (say) > SOAP. Then it's the responsibility of the server process to keep > track of created blank records and automatically rollback transactions > that exceed some fixed amount of time. Elegant but requires more > programming. I presume this would work... > > Time to go learn SOAP, I guess. > > Regards, > > -- Raju -- Rajesh Kumar Mallah, Project Manager (Development) Infocom Network Limited, New Delhi phone: +91(11)6152172 (221) (L) ,9811255597 (M) Visit http://www.trade-india.com , India's Leading B2B eMarketplace.