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); }
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);*/ }
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>(); }
private ActiveTxnRecord Validate(ActiveTxnRecord record) { var next = record.Next; if (next != null) { return(ValidateInternal(next)); } return(record); }
public void ValidateCommitAndEnqueue() { ActiveTxnRecord lastValid = _txnRecord; do { lastValid = Validate(lastValid); _commitTxnRecord = new ActiveTxnRecord(lastValid.TxNumber + 1, this.WriteMap); } while (!lastValid.TrySetNext(_commitTxnRecord)); }
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); }
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(); } }
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); }
internal static void InsertNewRecord(ActiveTxnRecord record) { LastCommitted.Next = record; LastCommitted = record; }
internal static void FinishCommit(ActiveTxnRecord recToCommit) { recToCommit.SetCommitted(); LastCommitted = recToCommit; }
internal bool TrySetNext(ActiveTxnRecord record) { return(Interlocked.CompareExchange <ActiveTxnRecord>(ref this.Next, record, null) == null); }
public static JVTransaction Start() { return(new JVTransaction(ActiveTxnRecord.StartTransaction())); //return new JVTransaction(_lastCommitted); }
private JVTransaction() : this(TransactionStatus.Active, ActiveTxnRecord.StartTransaction(), null, new ReadMap(), new WriteMap()) { }
private JVTransaction(ActiveTxnRecord txnRecord) : this(TransactionStatus.Active, txnRecord, null, new ReadMap(), new WriteMap()) { }
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);; }