public async Task <Releaser> AcquireLock(ulong pageId, LockTypeEnum lockType) { int lockId = lockManager.LockIdForPage(pageId); if (lockType != LockTypeEnum.Shared) { throw new ReadOnlyTranCantAcquireExLockException(); } lock (lck) { if (locksHeld.ContainsKey(lockId)) { // Return dummy leaser. You don't really own this lock. // This probably needs to change. throw new TranAlreadyHoldingLock(); } } var releaser = await lockManager.AcquireLock(lockType, pageId, this.transactionId); lock (lck) { locksHeld.Add(lockId, lockType); } releaser.SetReleaseCallback(() => this.ReleaseLock(lockId)); return(releaser); }
public ObservableImmutableList(IEnumerable <T> items, LockTypeEnum lockType) : base(lockType) { SyncRoot = new object(); _items = ImmutableList <T> .Empty.AddRange(items); BindingOperations.EnableCollectionSynchronization(this, SyncRoot); }
public static void HeadLockType(string rAddress, string hAddress, LockTypeEnum lockType) { if (OnHeadLockType != null) { OnHeadLockType(rAddress, hAddress, lockType); } }
/// <summary> /// Get Paged Records /// </summary> /// <param name="query"></param> /// <param name="source"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="cursorType"></param> /// <param name="lockType"></param> /// <param name="options"></param> /// <param name="cursorLocation"></param> /// <returns></returns> public Recordset GetPagedRecords(string query, DataSource source, int pageIndex, int pageSize = 100, CursorTypeEnum cursorType = CursorTypeEnum.adOpenDynamic, LockTypeEnum lockType = LockTypeEnum.adLockOptimistic, CommandTypeEnum options = CommandTypeEnum.adCmdText, CursorLocationEnum cursorLocation = CursorLocationEnum.adUseClient) { _connection = new Connection(); var cnStr = GetConnectionString(source); _connection.Open(cnStr, null, null, 0); _recordSet = new Recordset { CursorLocation = cursorLocation, CacheSize = pageSize, PageSize = pageSize }; //_recordSet.Open(query,_connection, cursorType, lockType, (int)options); _recordSet.Open(query, _connection); if (_recordSet.RecordCount != 0) { _recordSet.AbsolutePage = (PositionEnum)pageIndex; } return(_recordSet); }
public static void 机头锁定状态报告(string hAddress, string rAddress, LockTypeEnum lockTypeData) { TransmiteObject.机头解锁结构 obj = new TransmiteObject.机头解锁结构() { lockType = lockTypeData, HeadAdress = hAddress, RouteAddress = rAddress }; Client.Send(TransmiteEnum.机头锁定状态报告, obj); }
public async Task <Releaser> AcquireLock(LockTypeEnum lockType, ulong pageId, ulong ownerId) { return(lockType switch { LockTypeEnum.Shared => await this.locks[pageId % (ulong)locks.Length].ReaderLockAsync(ownerId).ConfigureAwait(false), LockTypeEnum.Exclusive => await this.locks[pageId % (ulong)locks.Length].WriterLockAsync(ownerId).ConfigureAwait(false), _ => throw new ArgumentException() });
public Recordset CreateRecordset(SqlFrag frag, CommandTypeEnum eCmdType = CommandTypeEnum.adCmdText, CursorLocationEnum eCursorLoc = CursorLocationEnum.adUseClient, CursorTypeEnum eCursorType = CursorTypeEnum.adOpenDynamic, LockTypeEnum eLockType = LockTypeEnum.adLockOptimistic, ExecuteOptionEnum eExecOptions = ExecuteOptionEnum.adOptionUnspecified) { ADODB.Command SqlCmd = GenerateCommand(eCmdType, frag); Recordset rRecords = new Recordset(); rRecords.CursorLocation = eCursorLoc; rRecords.Open(SqlCmd, Type.Missing, eCursorType, eLockType, (int)eExecOptions); return(rRecords); }
protected void CheckRecursiveLock(ulong ownerId, int lockId, LockTypeEnum lockType) { this.lockMonitorRecords.TryGetValue(ownerId, out Dictionary <int, LockTypeEnum> myLocks); if (myLocks != null) { if (myLocks.ContainsKey(lockId)) { throw new RecursiveLockNotSupportedException(); } } }
private async Task <Releaser> AcquireLockInternal(ulong pageId, LockTypeEnum lockType, bool forceCallerOwnership) { ILockManager lockManager = this.pageManager.GetLockManager(); int lockId = lockManager.LockIdForPage(pageId); lock (lck) { if (locksHeld.ContainsKey(lockId)) { return(new Releaser()); } } var releaser = await lockManager.AcquireLock(lockType, pageId, this.transactionId).ConfigureAwait(continueOnCapturedContext: false); lock (lck) { locksHeld.Add(lockId, lockType); } releaser.SetReleaseCallback(() => this.ReleaseLockCallback(lockId)); if (forceCallerOwnership) { return(releaser); } // TODO: Implement Isolation Level strategy. if (this.isolationLevel == IsolationLevelEnum.ReadCommitted) { // If this is a read lock return to caller. // If write transaction is the owner. if (lockType == LockTypeEnum.Shared) { return(releaser); } else if (lockType == LockTypeEnum.Exclusive) { this.myLocks.Add(releaser); return(new Releaser()); } else { throw new InvalidProgramException(); } } else { throw new InvalidProgramException(); } }
public bool AmIHoldingALock(ulong pageId, out LockTypeEnum lockType) { ILockManager lockManager = this.pageManager.GetLockManager(); int lockId = lockManager.LockIdForPage(pageId); lock (lck) { if (locksHeld.TryGetValue(lockId, out LockTypeEnum myLock)) { lockType = myLock; return(true); } } lockType = LockTypeEnum.Shared; return(false); }
public void VerifyLock(ulong pageId, LockTypeEnum expectedLock) { int lockId = this.pageManager.GetLockManager().LockIdForPage(pageId); lock (lck) { if (this.locksHeld.TryGetValue(lockId, out LockTypeEnum lockHeld)) { if ((int)lockHeld < (int)expectedLock) { throw new TranNotHoldingLock(); } } else { throw new TranNotHoldingLock(); } } }
/// <summary> /// Get Records /// </summary> /// <param name="query"></param> /// <param name="source"></param> /// <param name="cursorType"></param> /// <param name="lockType"></param> /// <param name="options"></param> /// <param name="cursorLocation"></param> /// <returns>RecordSet</returns> public Recordset GetRecords(string query, DataSource source, CursorTypeEnum cursorType = CursorTypeEnum.adOpenDynamic, LockTypeEnum lockType = LockTypeEnum.adLockOptimistic, CommandTypeEnum options = CommandTypeEnum.adCmdText, CursorLocationEnum cursorLocation = CursorLocationEnum.adUseClient) { _connection = new Connection(); var cnStr = GetConnectionString(source); _connection.Open(cnStr, null, null, 0); _recordSet = new Recordset { CursorLocation = cursorLocation }; _recordSet.Open(query, _connection, cursorType, lockType, (int)options); return(_recordSet); }
/// <summary> /// Get the record count /// </summary> /// <param name="query"></param> /// <param name="source"></param> /// <param name="cursorType"></param> /// <param name="lockType"></param> /// <param name="options"></param> /// <param name="cursorLocation"></param> /// <returns></returns> public short GetRecordCount(string query, DataSource source, CursorTypeEnum cursorType = CursorTypeEnum.adOpenDynamic, LockTypeEnum lockType = LockTypeEnum.adLockOptimistic, CommandTypeEnum options = CommandTypeEnum.adCmdText, CursorLocationEnum cursorLocation = CursorLocationEnum.adUseClient) { _connection = new Connection(); var cnStr = GetConnectionString(source); _connection.Open(cnStr, null, null, 0); _recordSet = new Recordset { CursorLocation = cursorLocation }; _recordSet.Open(query, _connection); var returnValue = (short)_recordSet.RecordCount; _recordSet = null; return(returnValue); }
public LockStatsRecord(int lockId, TimeSpan waitDuration, LockTypeEnum lockType) { this.LockId = lockId; this.WaitDuration = waitDuration; this.LockType = lockType; }
protected MultiThreadObservableCollection(LockTypeEnum lockType) { _lockType = lockType; _lockObj = new object(); }
/// <summary> /// Opens this ADORecordsetHelper using the provided parameters. /// </summary> /// <param name="connection">Connection object to be use by this ADORecordsetHelper.</param> /// <param name="lockType">The LockTypeEnum of this ADORecordsetHelper object.</param> public void Open(DbConnection connection, LockTypeEnum lockType) { ActiveConnection = connection; Open(lockType); }
public Reference[] @lock(Predicate items, bool lockChildren, LockTypeEnum lockType) { object[] results = this.Invoke("lock", new object[] { items, lockChildren, lockType}); return ((Reference[])(results[0])); }
/// <summary> /// Opens this ADORecordsetHelper using the provided parameters. /// </summary> /// <param name="command">A command containing the query to be execute to load the ADORecordsetHelper object.</param> /// <param name="lockType">The LockTypeEnum of this ADORecordsetHelper object.</param> public void Open(DbCommand command, LockTypeEnum lockType) { Validate(); source = command; activeCommand = command; Open(lockType); }
public ObservableImmutableDictionary(IEnumerable <KeyValuePair <T, V> > items, LockTypeEnum lockType) : base(lockType) { SyncRoot = new object(); _items = ImmutableDictionary <T, V> .Empty.AddRange(items); }
/// <summary> /// Opens this ADORecordsetHelper using the provided parameters. /// </summary> /// <param name="SQLstr">The string containing the SQL query to be loaded into this ADORecodsetHelper object.</param> /// <param name="connectionString">Strings that contains information about how to connect to the database.</param> /// <param name="lockType">The LockTypeEnum of this ADORecordsetHelper object.</param> public void Open(String SQLstr, String connectionString, LockTypeEnum lockType) { Open(SQLstr, GetConnection(connectionString), lockType); }
public async Task <Releaser> AcquireLockWithCallerOwnership(ulong pageId, LockTypeEnum lockType) { return(await AcquireLockInternal(pageId, lockType, true).ConfigureAwait(false)); }
public LockMonitorRecord(ulong ownerId, int lockId, LockTypeEnum lockType) { this.ownerId = ownerId; this.lockId = lockId; this.lockType = lockType; }
/// <summary> /// Opens this ADORecordsetHelper using the provided parameters. /// NOTE: It is better to provide the CommandType when executing the command /// If the command type is not given, performance would be affected due to several /// request to the DB schema /// </summary> /// <param name="SQLstr">The string containing the SQL query to be loaded into this ADORecodsetHelper object.</param> /// <param name="connection">Connection object to be use by this ADORecordsetHelper.</param> /// <param name="lockType">The LockTypeEnum of this ADORecordsetHelper object.</param> public void Open(String SQLstr, DbConnection connection, LockTypeEnum lockType) { ActiveConnection = connection; List<DbParameter> parameters; CommandType commandType = getCommandType((string)SQLstr, out parameters); Open(SQLstr, connection, lockType, commandType, parameters); }
/// <remarks/> public void lockAsync(Predicate items, bool lockChildren, LockTypeEnum lockType, object userState) { if ((this.lockOperationCompleted == null)) { this.lockOperationCompleted = new System.Threading.SendOrPostCallback(this.OnlockOperationCompleted); } this.InvokeAsync("lock", new object[] { items, lockChildren, lockType}, this.lockOperationCompleted, userState); }
/// <remarks/> public void lockAsync(Predicate items, bool lockChildren, LockTypeEnum lockType) { this.lockAsync(items, lockChildren, lockType, null); }
protected ObservableCollectionObject(LockTypeEnum lockType) { LockType = lockType; _lockObj = new object(); }
public ObservableImmutableDictionary(LockTypeEnum lockType) : this(new KeyValuePair <T, V> [0], lockType) { }
/// <summary> /// Opens this ADORecordsetHelper using the provided parameters. /// </summary> /// <param name="str">The string containing the SQL query to be loaded into this ADORecodsetHelper object.</param> /// <param name="lockType">The LockTypeEnum of this ADORecordsetHelper object.</param> /// <param name="type">StringParameterType of the str.</param> public void Open(String str, LockTypeEnum lockType, StringParameterType type) { Validate(); if (type == StringParameterType.Source) { List<DbParameter> parameters; CommandType commandType = getCommandType(str, out parameters); Open(CreateCommand(str, commandType,parameters), lockType); } else { Open(GetConnection(str), lockType); } }
public void Open(object value, object missing, CursorTypeEnum adOpenStatic, LockTypeEnum adLockOptimistic, int i) { throw new System.NotImplementedException(); }
public ObservableImmutableList(LockTypeEnum lockType) : this(new T[0], lockType) { }
/// <summary> /// Opens this ADORecordsetHelper using the provided parameters. /// </summary> /// <param name="lockType">The LockTypeEnum of this ADORecordsetHelper object.</param> public void Open(LockTypeEnum lockType) { Validate(); this.lockType = lockType; Open(); }
public void VerifyLock(ulong pageId, LockTypeEnum expectedLock) { }
private LockTicket(LockObject <T> lockObject, LockTypeEnum lockType) : base(lockObject.Locker, lockType) { LockObject = lockObject; }
/// <summary> /// Opens this ADORecordsetHelper using the provided parameters. /// This is the preferred Open method for performance reasons. However this call might required /// some extra parameters like CommandType and ParameterList. /// For most scenerios just provide a null parameter for the parameter list; /// </summary> /// <param name="SQLstr">The string containing the SQL query to be loaded into this ADORecodsetHelper object.</param> /// <param name="connection">Connection object to be use by this ADORecordsetHelper.</param> /// <param name="lockType">The LockTypeEnum of this ADORecordsetHelper object.</param> /// <param name="commandType">The CommandType of this ADORecordsetHelper object.</param> /// <param name="parameters">The list of parameters.</param> public void Open(String SQLstr, DbConnection connection, LockTypeEnum lockType, CommandType commandType, List<DbParameter> parameters) { // A RecordSet can be openned with a series of staments separated by ;. However each type an open is done, this collection is reseted */ commands = null; ActiveConnection = connection; Open(CreateCommand(SQLstr, commandType, parameters), lockType); }
public async Task <Releaser> AcquireLock(ulong pageId, LockTypeEnum lockType) { return(await AcquireLockInternal(pageId, lockType, false).ConfigureAwait(false)); }
internal static LockTicket <T> Create(LockObject <T> lockObject, LockTypeEnum lockType, TimeSpan timeout) { return(TryLock(lockObject.Locker, lockType, ref timeout) ? new LockTicket <T>(lockObject, lockType) : null); }
public async Task <Releaser> AcquireLock(ulong pageId, LockTypeEnum lockType) { // TODO: Even not logged tran needs to go through locks.. return(await Task.FromResult(new Releaser())); }
public async Task <Releaser> AcquireLockWithCallerOwnership(ulong pageId, LockTypeEnum lockType) { return(await Task.FromResult(new Releaser())); }
protected void VerifyDeadlock(ulong reqOwnerId, int reqLockId, LockTypeEnum reqLockType) { // TODO: This needs to be optimized. // Only aiming for correctness here. lock (lck) { Dictionary <int, LockTypeEnum> locksVisited = new Dictionary <int, LockTypeEnum>(); Queue <(int, LockTypeEnum)> locksToCheck = new Queue <(int, LockTypeEnum)>(); { Dictionary <int, LockTypeEnum> lockToCheckBuilder = new Dictionary <int, LockTypeEnum>(); foreach ((ulong depOwnerId, Dictionary <int, LockTypeEnum> depLocks) in this.lockMonitorRecords) { if (depLocks.ContainsKey(reqLockId)) { foreach ((int lockId, LockTypeEnum lockType) in depLocks) { if (lockId != reqLockId) { if (!(lockType == LockTypeEnum.Shared && reqLockType == LockTypeEnum.Shared)) { if (lockToCheckBuilder.TryGetValue(lockId, out LockTypeEnum insertedLockType)) { if (insertedLockType < lockType) { lockToCheckBuilder[lockId] = insertedLockType; } } else { lockToCheckBuilder.Add(lockId, lockType); } } } } } } foreach (var lck in lockToCheckBuilder) { locksToCheck.Enqueue((lck.Key, lck.Value)); } } Debug.Assert(!locksVisited.Any()); while (locksToCheck.Any()) { (int lockToCheck, LockTypeEnum lockTypeToCheck) = locksToCheck.Dequeue(); foreach ((ulong depOwnerId, Dictionary <int, LockTypeEnum> depLocks) in this.lockMonitorRecords) { if (depLocks.ContainsKey(lockToCheck)) { if (depOwnerId == reqOwnerId) { // We came back to the original owner. This means that this is a deadlock. // TODO: This doesn't take into account lock type. // E.g., even for a circle of readonly locks it will detect cycle. throw new DeadlockException(reqOwnerId, depOwnerId, reqLockId); } // Find all the locks that haven't been in the to visit list so far. foreach ((int depLockId, LockTypeEnum depLockType) in depLocks) { if (locksVisited.TryGetValue(depLockId, out LockTypeEnum visitedLockType)) { // If this is an upgrade I will need to visit it. if (visitedLockType < depLockType) { locksToCheck.Enqueue((depLockId, depLockType)); locksVisited[depLockId] = depLockType; } } else { locksToCheck.Enqueue((depLockId, depLockType)); locksVisited.Add(depLockId, depLockType); } } } } } return; } }
public bool AmIHoldingALock(ulong pageId, out LockTypeEnum lockType) { lockType = LockTypeEnum.Shared; return(true); }
public ObservableImmutableList(IEnumerable <T> items, LockTypeEnum lockType) : base(lockType) { _syncRoot = new object(); _items = ImmutableList <T> .Empty.AddRange(items); }
/// <summary> /// This method clones the recordset instance /// </summary> /// <param name="lockType">The lock type to be used by the cloned recorset</param> /// <returns>The cloned recordset</returns> public ADORecordSetHelper Clone(LockTypeEnum lockType) { ADORecordSetHelper result = new ADORecordSetHelper(); result.DatabaseType = DatabaseType; result.ProviderFactory = ProviderFactory; result.opened = true; result.isClone = true; result.LockType = lockType; result.ActiveConnection = ActiveConnection; result.activeCommand = activeCommand; result.currentView = new DataView(Tables[0]); result.State = State; result.CursorLocation = CursorLocation; if (FieldChangeComplete != null) { result.FieldChangeComplete = FieldChangeComplete; } if (RecordChangeComplete != null) { result.RecordChangeComplete = RecordChangeComplete; } if (WillChangeField != null) { result.WillChangeField = WillChangeField; } if (WillChangeRecord != null) { result.WillChangeRecord = WillChangeRecord; } if (result.currentView.Count > 0) { result.index = 0; result.eof = false; } return result; }