Hi,

I wanted to draw your attention to something I found out while fixing a bug 
involving the use of transactions in commands.

When calling a command using getBackend().runAction() when another transaction 
is open, by default the command will become part of the open transaction 
because by default CommandBase specifies TransactionScopeOption.Required as the 
default 'scope'.

Unfortunately, validation function(formerly CanDoAction()) will not be aware of 
the opened transaction. This get be problematic in cases where the validation() 
method check things that are fixed in the opened transaction and not committed 
yet. 

For example, In my case I'm using the AddVdsGroupCommand which creates a new 
cluster (In an open tranasction) and then, calls the AddCpuProfileCommand which 
creates a default cpu profile. The default cpu profile validation() check then, 
Check if the cluster exists which fails because it's not part of the opened 
transaction.

They way to over come this is to add the validation() method to the open 
transaction by adding @ValidateSupportsTransaction annotation on the command.

The associated part of the code in CommandBase(line 817) :
"""
if (!isValidateSupportsTransaction()) {
                transaction = TransactionSupport.suspend();
            }
"""

isValidateSupportsTransaction() - Checks that the annotation exists and if it's 
not it suspends the TransactionSupport.

FYI, 
Tomer 

_______________________________________________
Devel mailing list
Devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/devel

Reply via email to