Is there an aspect to get a transaction retry in case of deadlock? (like in DO 3.X)

This would be useful for us to have a systematic way of getting a retry in case of deadlock for webservices, ...


Updated at 17.05.2010 8:35:42

Well, this is not required for us ASAP, but this is important for us for webservice scenarios (etc...) : we could implement it "manually" for each service, but this introduce some duplicated code, so an aspect would be really welcome, especially if it is supported by Xtensive. We will need it for release : could this be done for your next release (4.3)?

By the way, this is really useful to give us the ticket's URL : with this we can know when a feature/bug is fixed without testing the latest nightly build ;) Could your team put the ticket's URL in forum posts when available?

Regards,

This thread was imported from our support forum. The original discussion may contain more detailed answer.


EDIT 25 February 2011

Here is a very simple implementation of a transaction retry aspect. Obviously it's not adapted for general use (do not work if session is already opened, use log4net, always commit transaction, ...)

Do you think this implementation will work in every case (if Session/transaction is not opened yet) ?

  [Serializable]
  [ProvideAspectRole(StandardRoles.Persistence)]
  public sealed class OpenSessionAndTrasactionWithRetry : MethodInterceptionAspect
  {
    private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    private const int MaxRetryCount = 3;

    public override void OnInvoke(MethodInterceptionArgs args)
    {
      if (Session.Current != null)
      {
        log.Warn("Aspect OpenSession has been used, but a session is already opened, not opening session (no retry behavior)");
        args.Proceed();
        return;
      }

      for (int retry = 0; ; retry++)
      {
        try
        {
          using (Session session = Session.Open(Agent.Current.GetKernelModule<PersistenceModule>().Domain))
          using (TransactionScope t = Transaction.Open())
          {
            args.Proceed();
            t.Complete();
          }
          // call success : we can return here
          return;
        }
        catch (Exception ex)
        {
          if (ex is DeadlockException || ex is TransactionSerializationFailureException)
          {
            if (retry + 1 < MaxRetryCount)
            {
              log.Info("Deadlock detected : retrying transactional method");
              continue;
            }
            else
            {
              log.Warn("Deadlock detected on last try : giving up on transactional method");
              throw;
            }
          }
          else
          {
            throw;
          }
        }

      }
    }
  }

asked May 12 '10 at 12:57

olorin's gravatar image

olorin
356838489

edited Feb 25 '11 at 10:47


One Answer:

Alex (Xtensive) wrote:

There is fully working ReprocessMethodBoundaryAspect, but it isn't used for now; moreover, we removed it from PostSharp 2.0 branch to simplify porting (there are significant API changes).

So automatic reprocessing behavior will be available soon (most likely - for all transactional methods), but right now you can't achieve this automatically.

For now I created an issue for this: http://code.google.com/p/dataobjectsdot ... ail?id=651

If you need this ASAP, please leave a comment here (features that are really necessary for customers get high priorities).


Dmitri Maximov (Xtensive) wrote:

The ticket url is the following: http://code.google.com/p/dataobjectsdot ... ail?id=653

What about the schedule, I'm afraid that there is quite low probability that the feature will be included into the upcoming 4.3 release as the correspondent branch is already frozen for new features.

answered May 13 '10 at 14:52

Editor's gravatar image

Editor
46148156157

olorin wrote: Well that's not a problem : I would be happy with a nightly build ;)

(May 13 '10 at 14:52) Editor Editor's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×569

Asked: May 12 '10 at 12:57

Seen: 2,901 times

Last updated: Feb 25 '11 at 10:47

powered by OSQA