Exemple #1
0
        private void Enlist(Transaction transaction)
        {
            if (transaction == null)
            {
                // no enlistment as we are not in a TransactionScope
                return;
            }

            // try to enlist as a PSPE
            if (!transaction.EnlistPromotableSinglePhase(this))
            {
                // our enlistmente fail so we need to enlist ourselves as durable.

                // we create a transaction directly instead of using BeginTransaction that GraphClient
                // doesn't store it in its stack of scopes.
                var localTransaction = new Neo4jRestTransaction(client);
                localTransaction.ForceKeepAlive();
                transactionId = localTransaction.Id;
                var resourceManager  = GetResourceManager();
                var propagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
                var transactionExecutionEnvironment = new TransactionExecutionEnvironment(client.ExecutionConfiguration)
                {
                    TransactionId           = localTransaction.Id,
                    TransactionBaseEndpoint = client.TransactionEndpoint
                };
                resourceManager.Enlist(transactionExecutionEnvironment, propagationToken);
                localTransaction.Cancel();
            }

            enlistedInTransactions.Add(transaction);
        }
Exemple #2
0
        public byte[] Promote()
        {
            // we have been promoted to MSTDC, so we have to clean the local resources
            if (transaction == null)
            {
                transaction = new Neo4jRestTransaction(client);
            }

            // do a keep alive in case the promotion takes too long or in case we don't have an ID
            transaction.ForceKeepAlive();
            transactionId = transaction.Id;
            transaction.Cancel();
            transaction = null;

            if (transactionId == 0)
            {
                throw new InvalidOperationException("For some reason we don't have a TransactionContext ID");
            }

            var resourceManager = GetResourceManager();

            return(resourceManager.Promote(new TransactionExecutionEnvironment(client.ExecutionConfiguration)
            {
                TransactionId = transactionId,
                TransactionBaseEndpoint = client.TransactionEndpoint
            }));
        }
Exemple #3
0
 public void Initialize()
 {
     // enlistment has completed successfully.
     // For now we can use local transactions
     // we create it directly instead of using BeginTransaction that GraphClient
     // doesn't store it in its stack of scopes.
     transaction = new Neo4jRestTransaction(client);
 }
Exemple #4
0
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     try
     {
         Neo4jRestTransaction.DoKeepAlive(transactionExecutionEnvironment);
         preparingEnlistment.Prepared();
     }
     catch (Exception e)
     {
         preparingEnlistment.ForceRollback(e);
     }
 }
Exemple #5
0
 public void Rollback(Enlistment enlistment)
 {
     try
     {
         Neo4jRestTransaction.DoRollback(transactionExecutionEnvironment);
     }
     finally
     {
         // always have to call Done() or we clog the resources
         enlistment.Done();
     }
 }
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     try
     {
         Neo4jRestTransaction.DoCommit(transactionExecutionEnvironment);
         singlePhaseEnlistment.Committed();
     }
     finally
     {
         singlePhaseEnlistment.Aborted();
     }
 }
Exemple #7
0
        public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
        {
            // we receive a commit message
            // if we own a local transaction, then commit that transaction
            if (transaction != null)
            {
                transaction.Rollback();
                transaction = null;
            }
            else if (transactionId > 0)
            {
                GetResourceManager().RollbackTransaction(transactionId);
            }
            singlePhaseEnlistment.Aborted();

            enlistedInTransactions.Remove(Transaction.Current);
        }
Exemple #8
0
 public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
 {
     try
     {
         Neo4jRestTransaction.DoCommit(transactionExecutionEnvironment);
         singlePhaseEnlistment.Committed();
     }
     catch (Exception e)
     {
         singlePhaseEnlistment.Aborted(e);
         // TODO: Should we rethrow?
     }
     finally
     {
         singlePhaseEnlistment.Done();
     }
 }
Exemple #9
0
        public byte[] Promote()
        {
            // we have been promoted to MSTDC, so we have to clean the local resources
            if (transaction == null)
            {
                transaction = new Neo4jRestTransaction(client);
            }

            // do a keep alive in case the promotion takes too long or in case we don't have an ID
            transaction.ForceKeepAlive();
            transactionId = transaction.Id;
            transaction.Cancel();
            transaction = null;

            if (transactionId == 0)
            {
                throw new InvalidOperationException("For some reason we don't have a TransactionContext ID");
            }

            // BUG: .NET 4.7.1 introduced a bug where the current transaction wouldn't get restored
            // after a call which crosses AppDomain boundaries. We have to restore it ourselves.
            // Ref https://github.com/Microsoft/dotnet-framework-early-access/issues/7
            var tx = Transaction.Current;
            var resourceManager = GetResourceManager();
            var res             = resourceManager.Promote(new TransactionExecutionEnvironment(client.ExecutionConfiguration)
            {
                TransactionId           = transactionId,
                TransactionBaseEndpoint = client.TransactionEndpoint
            });

            // Only restore if the bug exists to avoid any potentially side-effects
            // of setting the transaction
            if (Transaction.Current == null)
            {
                Transaction.Current = tx;
            }
            return(res);
        }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     Neo4jRestTransaction.DoKeepAlive(transactionExecutionEnvironment);
     preparingEnlistment.Done();
 }