internal void LogWrite <T>(StmObject <T> stmObject, T newValue) { var newStmObject = new StmObject <T>(newValue); var txEntry = _txLog.GetObject(stmObject); if (txEntry == null) { txEntry = TransactionLogEntry <T> .LogWriteEntry(stmObject, newStmObject); _txLog.Add(txEntry); return; } txEntry.UpdateNewStmObject(newStmObject); }
private bool IsValidVersion <T>(TransactionLogEntry <T> txEntry) { //// validate on each read only if //// a.) serializability is asked for //// b.) the object´s data working set //// could have changed since the last read. that´s only the case if clonemode=cloneOnWrite. //// (no validation for PassingReadOnly reads!) //if (txEntry.ReadOption > StmReadOption.PassingReadOnly // && _isolationLevel == StmTransactionIsolationLevel.Serializable // && _cloneMode == StmTransactionCloneMode.CloneOnWrite) //{ // // isolevel "serializable": the value must not have changed since it was last read // return stmObject.Version == txEntry.Version; //} //// isolevel "readcommitted": the value is allowed to be changed by another tx //return true; var versionId = txEntry.OriginalObject.Element.Version; //var loop = 0; //while (versionId is int == false && loop < 3) //{ // Thread.Sleep(300); // loop++; //} bool waitMore; do { if (versionId is int) { return((int)versionId == (int)txEntry.OriginalVersionId); } waitMore = txEntry.OriginalObject.ResetEvent.Wait(1000); versionId = txEntry.OriginalObject.Element.Version; } while (versionId is int == false && waitMore); throw new StmObjectBusyException("StmObject busy could not read"); }
internal T LogRead <T>(StmObject <T> stmObject) { var txEntry = _txLog.GetObject(stmObject); if (txEntry == null) { // first read on object: create txlog entry... var newStmObject = stmObject.Clone(); txEntry = TransactionLogEntry <T> .LogReadEntry(stmObject, newStmObject); _txLog.Add(txEntry); // return new value return(newStmObject.Value); } if (IsValidVersion(txEntry)) { return(txEntry.NewObject.Value); } throw new StmObjectValueChangedException("StmObject value has been changed by another transaction since it was last read. (Use isolation level 'ReadCommitted' to allow such changes to happen.)"); }