示例#1
0
        internal static ActiveTxnRecord GetOldestRecord(TxnContext upTo)
        {
            var             context      = TxnContext.Head;
            ActiveTxnRecord oldestRecord = null;
            TxnContext      prevContext  = null;

            while (context != upTo)
            {
                var contextOldest = context.OldestRequiredRecord;
                if (oldestRecord == null || (contextOldest != null && oldestRecord.TxNumber > contextOldest.TxNumber))
                {
                    oldestRecord = contextOldest;
                }

                if (!context.OwningThread.IsAlive && prevContext != null)
                {
                    prevContext.Next = context.Next;
                }

                prevContext = context;
                context     = context.Next;
            }

            return(oldestRecord);
        }
示例#2
0
        private void EnsureCommitStatus()
        {
            ActiveTxnRecord recToCommit = ActiveTxnRecord.LastCommitted.Next;

            while (recToCommit != null && recToCommit.TxNumber <= _commitTxnRecord.TxNumber)
            {
                if (!recToCommit.IsCommited)
                {
                    var writeMap = recToCommit.WriteMap;
                    writeMap.HelpWriteBack(recToCommit.TxNumber);
                    ActiveTxnRecord.FinishCommit(recToCommit);
                }
                recToCommit = recToCommit.Next;
            }

            /*
             * while (ActiveTxnRecord.First.Next != _commitTxnRecord)
             * {
             *
             * }
             *
             * foreach (var kvpair in WriteMap)
             * {
             *  kvpair.Key.Install(kvpair.Value, _commitTxnRecord.TxNumber);
             * }
             * ActiveTxnRecord.FinishCommit(_commitTxnRecord);*/
        }
示例#3
0
 private JVTransaction(TransactionStatus status, ActiveTxnRecord txnRecord, JVTransaction parent, ReadMap readMap, WriteMap writeMap)
 {
     Number     = txnRecord.TxNumber;
     Parent     = parent;
     ReadMap    = readMap;
     WriteMap   = writeMap;
     Status     = status;
     _txnRecord = txnRecord;
     //Commutes = new List<BaseCommute>();
 }
示例#4
0
        private ActiveTxnRecord Validate(ActiveTxnRecord record)
        {
            var next = record.Next;

            if (next != null)
            {
                return(ValidateInternal(next));
            }

            return(record);
        }
示例#5
0
        public void ValidateCommitAndEnqueue()
        {
            ActiveTxnRecord lastValid = _txnRecord;

            do
            {
                lastValid        = Validate(lastValid);
                _commitTxnRecord = new ActiveTxnRecord(lastValid.TxNumber + 1,
                                                       this.WriteMap);
            } while (!lastValid.TrySetNext(_commitTxnRecord));
        }
示例#6
0
        private ActiveTxnRecord ValidateInternal(ActiveTxnRecord record)
        {
            var valid = record.WriteMap.Validate(this.ReadMap);

            if (!valid)
            {
                throw new STMCommitException();
            }

            var next = record.Next;

            if (next != null)
            {
                return(ValidateInternal(next));
            }

            return(record);
        }
示例#7
0
        public static void StartGC()
        {
            if (!GC_Status)
            {
                GC_Status = true;
                var gc_thread = new Thread(() =>
                {
                    while (GC_Status)
                    {
                        var rec               = FindOldestRecordInUse();
                        lasCleanedTo          = CleanUpTo(rec, lasCleanedTo);
                        ActiveTxnRecord.First = null;
                        Thread.Sleep(2);
                    }
                });

                gc_thread.IsBackground = true;
                gc_thread.Start();
            }
        }
示例#8
0
        internal static ActiveTxnRecord CleanUpTo(ActiveTxnRecord cleanTo, ActiveTxnRecord lastCleanTo)
        {
            if (cleanTo.TxNumber < lastCleanTo.TxNumber)
            {
                return(lastCleanTo);
            }

            var rec = lastCleanTo;

            while (rec != cleanTo)
            {
                rec.Clean();
                if (!rec.Next.IsCommited)
                {
                    break;
                }

                rec = rec.Next;
            }


            return(rec);
        }
示例#9
0
 internal static void InsertNewRecord(ActiveTxnRecord record)
 {
     LastCommitted.Next = record;
     LastCommitted      = record;
 }
示例#10
0
 internal static void FinishCommit(ActiveTxnRecord recToCommit)
 {
     recToCommit.SetCommitted();
     LastCommitted = recToCommit;
 }
示例#11
0
 internal bool TrySetNext(ActiveTxnRecord record)
 {
     return(Interlocked.CompareExchange <ActiveTxnRecord>(ref this.Next, record, null) == null);
 }
示例#12
0
 public static JVTransaction Start()
 {
     return(new JVTransaction(ActiveTxnRecord.StartTransaction()));
     //return new JVTransaction(_lastCommitted);
 }
示例#13
0
 private JVTransaction()
     : this(TransactionStatus.Active, ActiveTxnRecord.StartTransaction(), null, new ReadMap(), new WriteMap())
 {
 }
示例#14
0
 private JVTransaction(ActiveTxnRecord txnRecord) : this(TransactionStatus.Active, txnRecord, null, new ReadMap(), new WriteMap())
 {
 }
示例#15
0
        public bool Commit()
        {
            return(CommitLockFree());

            if (WriteMap.Count == 0)
            {
                Status = TransactionStatus.Committed;
                //_txnRecord.FinishTransaction();
                return(true);
            }

            bool            result;
            ActiveTxnRecord commitRecord = null;

            lock (CommitLock)
            {
                var newNumber = ActiveTxnRecord.LastCommitted.TxNumber + 1;

                var valid = ReadMap.Validate();
                if (!valid)
                {
                    result = false;
                }
                else
                {
                    if (IsNested)
                    {
                        Parent.ReadMap.Merge(ReadMap);
                        Parent.WriteMap.Merge(WriteMap);
                    }
                    else
                    {
                        //var bodies = new BaseVBoxBody[WriteMap.Count];
                        var i = 0;
                        foreach (var kvpair in WriteMap)
                        {
                            //bodies[i] = kvpair.Key.Install(kvpair.Value, newNumber);
                            kvpair.Key.Install(kvpair.Value, newNumber);
                            i++;
                        }

                        //commitRecord = new ActiveTxnRecord(newNumber, bodies);
                        commitRecord = new ActiveTxnRecord(newNumber);
                        ActiveTxnRecord.InsertNewRecord(commitRecord);
                    }

                    Status = TransactionStatus.Committed;
                    result = true;
                }
            }

            /*
             * if (result && !IsNested)
             * {
             *  _txnRecord.FinishTransaction();
             *
             *  if (commitRecord != null)
             *  {
             *      Interlocked.Decrement(ref commitRecord.Running);
             *  }
             * }*/

            return(result);;
        }