forum.vmspython.org Forum Index forum.vmspython.org
Forum system
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with "transaction already started" in Rdb.

 
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS
View previous topic :: View next topic  
Author Message
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Sun Jul 05, 2015 2:24 pm    Post subject: Problem with "transaction already started" in Rdb. Reply with quote

I think this issue has been raised before, but I can not find the old posts...

I just updated both Python and the PYRTE to the latest versions as available from the Python site and the WASD homepage.

Now I seems to have got back an old issue where the PYRTE "hangs" with an open transaction, and when a script reruns and try a simple rdb.read_only() statement it crashed with a "transaction alread started" error message.

This is a problem if one script doesn't run to end and never comes to the commit. Next run will then crasch. And this is permanent until the PYRTE process times out or I stop/id it manually.

I think there was a test added in the Rdb interface code to check this and insert a commit automaticly, if needed, wasn't there?

There is nothing in the __init__.py file in <local.rdb> anyway.

I do not think it was in PYRTE as such...

EDIT:
This is easy to reproduce by having two rdb.read_only() statements after each other:
Code:

$ python
import rdb
rdb.attachDB('test')
rdb.read_only()
rdb.read_only()
exit()
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/python_root/local/rdb/__init__.py", line 97, in read_only
    Statement('set transaction read only').execute()
  File "/python_root/local/rdb/__init__.py", line 93, in execute
    _rdb.Statement.execute(self, *args)
rdb._rdb_exceptions.Error: (-1, '%SQL-F-BAD_TXN_STATE, Invalid transaction state. Transaction already started.', 'RR000')

Maybe the second statement could just do a commit behind the scenes if there is a transaction opened.
This is the same thing for two rdb.read_write() or a mix of them...
Back to top
View user's profile Send private message
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Mon Jul 06, 2015 12:27 pm    Post subject: Reply with quote

Hi.
Some of these issues was discussed in this thread:
http://forum.vmspython.org/viewtopic.php?t=191
including the "transaction already started" issue...

Reaging the old "fix", I think it was around these defines in __init__.py in <local.rdb>:
Code:

def read_only():
   """Start a read only transaction"""
   Statement('set transaction read only').execute()

def read_write():
   """Start a read write transaction"""
   Statement('set transaction read write').execute()

def commit():
   Statement('commit').execute()

Some test in the first two to see if a transaction was already open and a call to
commit() is so, can that be right? Was that never included in the main distribution?
Back to top
View user's profile Send private message
jfp



Joined: 12 Jul 2004
Posts: 618

PostPosted: Tue Jul 07, 2015 11:23 am    Post subject: Reply with quote

You will have same error if you do in any program an
Code:
set transaction read only

twice without a commit.

You cannot open a transaction without rollback or commit the previous one.
For each transaction started you need a rollback or a commit.

JF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Tue Jul 07, 2015 12:29 pm    Post subject: Reply with quote

> You will have same error if you do in any program an...

Yes, of course! But you miss the point here... Smile

The problem is that if a script crasches, the RTE process stays alive with an open transaction pending.
And next time the same (or any) script runs in the same RTE instance, it get the "transaction already started" error...

If one simply add a dummy "commit" in the script before the set transaction, you will get an "%SQL-F-NO_TXNOUT, No transaction outstanding" instead.

This is *not* a real error in the specific script as such...

I'm quite sure that there was some "if" added to the two set transaction funtions that did an commit *if* there was an open/pending transaction.
I might come up with the code myself, I just thought it was still available somewhere...
Back to top
View user's profile Send private message
jfp



Joined: 12 Jul 2004
Posts: 618

PostPosted: Wed Jul 08, 2015 7:58 am    Post subject: Reply with quote

IMHO a script which "crash" and let a transaction open is buggy.

A correct script should trap the error and clean it's environment.
A global try/except block is needed.

If, at the beginning of script, you want to rollback any outstanding transaction you can embedded the rollback into a try/except block, or check if there is a active transaction before rollback it.
But I really think that it's better to catch any error and rollback before exiting the script.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Wed Jul 08, 2015 3:10 pm    Post subject: Reply with quote

OK, fine. I understand what you are saying... Smile
We'll drop it here. I can of course fix it in my scripts.
Maybe through an own wrapper to the read_write()
and read_only() functions...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group