Example #1
0
        public Task <TransactionalStatus> CommitReadOnly(Guid transactionId, AccessCounter accessCount, DateTime timeStamp)
        {
            // validate the lock
            var valid = ValidateLock(transactionId, accessCount, out var status, out var record);

            record.Timestamp    = timeStamp;
            record.Role         = CommitRole.ReadOnly;
            record.PromiseForTA = new TaskCompletionSource <TransactionalStatus>();

            if (!valid)
            {
                NotifyOfAbort(record, status);
            }
            else
            {
                MergeClock(record.Timestamp);
            }

            lockWorker.Notify();
            return(record.PromiseForTA.Task);
        }
Example #2
0
        public Task Prepare(Guid transactionId, AccessCounter accessCount, DateTime timeStamp, ITransactionParticipant transactionManager)
        {
            var valid = ValidateLock(transactionId, accessCount, out var status, out var record);

            record.Timestamp          = timeStamp;
            record.Role               = CommitRole.RemoteCommit; // we are not the TM
            record.TransactionManager = transactionManager;
            record.LastSent           = null;
            record.PrepareIsPersisted = false;

            if (!valid)
            {
                NotifyOfAbort(record, status);
            }
            else
            {
                MergeClock(record.Timestamp);
            }

            lockWorker.Notify();
            return(Task.CompletedTask); // one-way, no response
        }
Example #3
0
        // blocks until the given operation for this transaction can be executed.
        private Task <TResult> EnterLock <TResult>(Guid transactionId, DateTime priority,
                                                   AccessCounter counter, bool isRead, Task <TResult> task)
        {
            bool rollbacksOccurred = false;

            // search active transactions
            if (Find(transactionId, isRead, out var group, out var record))
            {
                // check if we lost some reads or writes already
                if (counter.Reads > record.NumberReads || counter.Writes > record.NumberWrites)
                {
                    throw new OrleansBrokenTransactionLockException(transactionId.ToString(), "when re-entering lock");
                }

                // check if the operation conflicts with other transactions in the group
                if (HasConflict(isRead, priority, transactionId, group, out var resolvable))
                {
                    if (!resolvable)
                    {
                        throw new OrleansTransactionLockUpgradeException(transactionId.ToString());
                    }
                    else
                    {
                        // rollback all conflicts
                        var conflicts = Conflicts(transactionId, group).ToList();

                        if (conflicts.Count > 0)
                        {
                            foreach (var r in conflicts)
                            {
                                Rollback(r, "wait-die on conflict", true);
                                rollbacksOccurred = true;
                            }
                        }
                    }
                }
            }
Example #4
0
        public Task <TransactionalStatus> PrepareAndCommit(Guid transactionId, AccessCounter accessCount, DateTime timeStamp, List <ITransactionParticipant> writeParticipants, int totalParticipants)
        {
            // validate the lock
            var valid = ValidateLock(transactionId, accessCount, out var status, out var record);

            record.Timestamp         = timeStamp;
            record.Role              = CommitRole.LocalCommit; // we are the TM
            record.WaitCount         = totalParticipants - 1;
            record.WaitingSince      = DateTime.UtcNow;
            record.WriteParticipants = writeParticipants;
            record.PromiseForTA      = new TaskCompletionSource <TransactionalStatus>();

            if (!valid)
            {
                NotifyOfAbort(record, status);
            }
            else
            {
                MergeClock(record.Timestamp);
            }

            lockWorker.Notify();
            return(record.PromiseForTA.Task);
        }
 public Task <TransactionalStatus> PrepareAndCommit(string resourceId, Guid transactionId, AccessCounter accessCount, DateTime timeStamp, List <ParticipantId> writeResources, int totalResources)
 {
     return(GetManager(resourceId).PrepareAndCommit(transactionId, accessCount, timeStamp, writeResources, totalResources));
 }
 public Task Prepare(string resourceId, Guid transactionId, AccessCounter accessCount, DateTime timeStamp, ParticipantId transactionManager)
 {
     return(GetResource(resourceId).Prepare(transactionId, accessCount, timeStamp, transactionManager));
 }
Example #7
0
 public Task <TransactionalStatus> PrepareAndCommit(string resourceId, Guid transactionId, AccessCounter accessCount, DateTime timeStamp, List <ITransactionParticipant> writeParticipants, int totalParticipants)
 {
     return(localParticipants[resourceId].PrepareAndCommit(transactionId, accessCount, timeStamp, writeParticipants, totalParticipants));
 }
Example #8
0
 public Task Prepare(string resourceId, Guid transactionId, AccessCounter accessCount, DateTime timeStamp, ITransactionParticipant transactionManager)
 {
     return(localParticipants[resourceId].Prepare(transactionId, accessCount, timeStamp, transactionManager));
 }
Example #9
0
 public Task <TransactionalStatus> CommitReadOnly(string resourceId, Guid transactionId, AccessCounter accessCount, DateTime timeStamp)
 {
     return(localParticipants[resourceId].CommitReadOnly(transactionId, accessCount, timeStamp));
 }
Example #10
0
 public Task <TransactionalStatus> PrepareAndCommit(Guid transactionId, AccessCounter accessCount, DateTime timeStamp, List <ITransactionParticipant> writeParticipants, int totalParticipants)
 {
     return(this.transactionManager.PrepareAndCommit(transactionId, accessCount, timeStamp, writeParticipants, totalParticipants));
 }
Example #11
0
 public Task <TransactionalStatus> CommitReadOnly(Guid transactionId, AccessCounter accessCount, DateTime timeStamp)
 {
     return(this.transactionManager.CommitReadOnly(transactionId, accessCount, timeStamp));
 }
Example #12
0
 public Task Prepare(Guid transactionId, AccessCounter accessCount, DateTime timeStamp, ITransactionParticipant transactionManager)
 {
     return(this.resource.Prepare(transactionId, accessCount, timeStamp, transactionManager));
 }
 public Task <TransactionalStatus> CommitReadOnly(string resourceId, Guid transactionId, AccessCounter accessCount, DateTime timeStamp)
 {
     return(GetResource(resourceId).CommitReadOnly(transactionId, accessCount, timeStamp));
 }