internal Lock(LockingQueue queue, LockingMode mode, AccessType accessType) { Queue = queue; AccessType = accessType; Mode = mode; Queue.Acquire(this); }
internal LockEvent(LockEventType eventType, IEnumerable<ObjectName> references, LockingMode mode, AccessType accessType) { EventType = eventType; References = references; Mode = mode; AccessType = accessType; }
public LockHandle Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode) { // Set up the local constants. int lockCount = toRead.Length + toWrite.Length; LockHandle handle = new LockHandle(lockCount); lock (this) { Lock @lock; LockingQueue queue; // Add Read and Write locks to cache and to the handle. for (int i = toWrite.Length - 1; i >= 0; --i) { var toWriteLock = toWrite[i]; queue = GetQueueFor(toWriteLock); // slightly confusing: this will add Lock to given table queue @lock = new Lock(queue, mode, AccessType.Write); @lock.Acquire(); handle.AddLock(@lock); } for (int i = toRead.Length - 1; i >= 0; --i) { var toReadLock = toRead[i]; queue = GetQueueFor(toReadLock); // slightly confusing: this will add Lock to given table queue @lock = new Lock(queue, mode, AccessType.Read); @lock.Acquire(); handle.AddLock(@lock); } } return handle; }
public static void Lock(this ISession session, IEnumerable <ObjectName> objectNames, AccessType accessType, LockingMode mode, int timeout) { if (session.Transaction != null) { session.Transaction.Lock(objectNames, accessType, mode, timeout); } }
public Lock NewLock(LockingMode mode, AccessType accessType) { lock (this) { var @lock = new Lock(this, mode, accessType); Acquire(@lock); @lock.OnAcquired(); return @lock; } }
public void LockingModeAsync_GivenInvalidLockingModeValue_ThrowsArgumentException() { var connection = CreateConnectionFactory(); var dbPragma = CreateDatabasePragma(connection, MainSchema); const LockingMode newValue = (LockingMode)55; Assert.That(() => dbPragma.LockingModeAsync(newValue), Throws.ArgumentException); }
public Lock NewLock(LockingMode mode, AccessType accessType) { lock (this) { var @lock = new Lock(this, mode, accessType); Acquire(@lock); @lock.OnAcquired(); return(@lock); } }
public LockTableStatement(ObjectName tableName, LockingMode mode, int timeout) { if (tableName == null) throw new ArgumentNullException("tableName"); if (timeout < Timeout.Infinite) throw new ArgumentException("Invalid wait timeout specified", "timeout"); TableName = tableName; Mode = mode; WaitTimeout = timeout; }
internal Lock Lock(LockingMode mode, AccessType accessType) { lock (this) { var @lock = new Lock(this, mode, accessType); Locked.Locked(@lock); locks.Add(@lock); @lock.Acquire(); return(@lock); } }
public LockHandle Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode) { lock (this) { int lockCount = toRead.Length + toWrite.Length; LockHandle handle = new LockHandle(lockCount); AddToHandle(handle, toWrite, AccessType.Write, mode); AddToHandle(handle, toRead, AccessType.Read, mode); return(handle); } }
public async Task LockingModeAsync_GetAndSet_InvokesProperly() { var connection = CreateConnectionFactory(); var dbPragma = CreateDatabasePragma(connection, MainSchema); _ = await dbPragma.LockingModeAsync().ConfigureAwait(false); // should be normal const LockingMode newValue = LockingMode.Exclusive; await dbPragma.LockingModeAsync(newValue).ConfigureAwait(false); _ = await dbPragma.LockingModeAsync().ConfigureAwait(false); Assert.Pass(); // not checking value as it's a once-only effect }
public LockTableStatement(ObjectName tableName, LockingMode mode, int timeout) { if (tableName == null) { throw new ArgumentNullException("tableName"); } if (timeout < Timeout.Infinite) { throw new ArgumentException("Invalid wait timeout specified", "timeout"); } TableName = tableName; Mode = mode; WaitTimeout = timeout; }
public void CombinedTest() { lockingMode = LockingMode.None; isolationLevel = IsolationLevel.ReadCommitted; Run("Counter isn't isolated."); isolationLevel = IsolationLevel.RepeatableRead; Run("There are deadlocks or version conflicts, but counter is isolated."); lockingMode = LockingMode.EntityLock; Run("Still can be a deadlock, since lock happen after read."); lockingMode = LockingMode.QueryLock; Run("No deadlocks, counter isolation."); }
public LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode) { lock (this) { int count = 0; if ((accessType & AccessType.Read) != 0) count += lockables.Length; if ((accessType & AccessType.Write) != 0) count += lockables.Length; var handle = new LockHandle(count); if ((accessType & AccessType.Read) != 0) AddToHandle(handle, lockables, AccessType.Read, mode); if ((accessType & AccessType.Write) != 0) AddToHandle(handle, lockables, AccessType.Write, mode); return handle; } }
public void Lock(IEnumerable <IDbObject> objects, AccessType accessType, LockingMode mode) { lock (Database) { var lockables = objects.OfType <ILockable>().ToArray(); if (lockables.Length == 0) { return; } // Before we can lock the objects, we must wait for them // to be available... CheckAccess(lockables, accessType); var handle = Database.Locker.Lock(lockables, accessType, mode); if (lockHandles == null) { lockHandles = new List <LockHandle>(); } lockHandles.Add(handle); } }
private void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode) { if (lockables == null) { return; } for (int i = lockables.Length - 1; i >= 0; --i) { var lockable = lockables[i]; var queue = GetQueueFor(lockable); handle.AddLock(queue.NewLock(mode, accessType)); } }
public static LockHandle LockWrite(this ITransaction transaction, IEnumerable<ObjectName> tableNames, LockingMode mode) { var tables = tableNames.Select(transaction.GetTable).OfType<ILockable>().ToArray(); return transaction.Database.DatabaseContext.Locker.Lock(tables, new ILockable[0], mode); }
public void Lock(IEnumerable<IDbObject> objects, AccessType accessType, LockingMode mode) { // A system session does not hold any lock }
internal Lock(LockingQueue queue, LockingMode mode, AccessType accessType) { Queue = queue; AccessType = accessType; Mode = mode; }
public void Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode) { lock (Database) { if (lockHandles == null) lockHandles = new List<LockHandle>(); var handle = Database.DatabaseContext.Locker.Lock(toWrite, toRead, mode); if (handle != null) lockHandles.Add(handle); } }
public static void Lock(this ITransaction transaction, IEnumerable<ObjectName> tableNames, AccessType accessType, LockingMode mode, int timeout) { var lockables = tableNames.Select(transaction.FindObject); transaction.Lock(lockables.ToArray(), mode, timeout); }
public void Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode) { }
public LockHandle LockWrite(ILockable[] lockables, LockingMode mode) { return Lock(lockables, AccessType.Write, mode); }
public LockHandle Lock(ILockable lockable, AccessType accessType, LockingMode mode) { return Lock(new[] {lockable}, accessType, mode); }
public void Lock(IEnumerable<IDbObject> objects, AccessType accessType, LockingMode mode) { lock (Database) { var lockables = objects.OfType<ILockable>().ToArray(); if (lockables.Length == 0) return; // Before we can lock the objects, we must wait for them // to be available... CheckAccess(lockables, accessType); var handle = Database.Locker.Lock(lockables, accessType, mode); if (lockHandles == null) lockHandles = new List<LockHandle>(); lockHandles.Add(handle); } }
public static void Lock(this ISession session, IEnumerable<ObjectName> objectNames, AccessType accessType, LockingMode mode, int timeout) { if (session.Transaction != null) session.Transaction.Lock(objectNames, accessType, mode, timeout); }
public LockHandle Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode) { lock (this) { int lockCount = toRead.Length + toWrite.Length; LockHandle handle = new LockHandle(lockCount); AddToHandle(handle, toWrite, AccessType.Write, mode); AddToHandle(handle, toRead, AccessType.Read, mode); return handle; } }
protected virtual IQueryResponse[] ExecuteQuery(string text, IEnumerable <SqlQueryParameter> parameters) { // Log this Query if Query logging is enabled if (Logger.IsInterestedIn(LogLevel.Debug)) { // Output the instruction to the _queries log. Logger.DebugFormat(this, "[CLIENT] [{0}] - Query: {1}", Session.User.UserName, text); } // Write debug message (Info level) if (Logger.IsInterestedIn(LogLevel.Debug)) { Logger.DebugFormat(this, "Query From User: {0}", Session.User.UserName); Logger.DebugFormat(this, "Query: {0}", text.Trim()); } // Get the locking mechanism. LockingMechanism locker = Session.Connection.LockingMechanism; LockingMode lockMode = LockingMode.None; IQueryResponse[] response = null; try { try { // For simplicity - all database locking is now exclusive inside // a transaction. This means it is not possible to execute // queries concurrently inside a transaction. However, we are // still able to execute queries concurrently from different // connections. // // It's debatable whether we even need to perform this Lock anymore // because we could change the contract of this method so that // it is not thread safe. This would require that the callee ensures // more than one thread can not execute queries on the connection. lockMode = LockingMode.Exclusive; locker.SetMode(lockMode); // Execute the Query (behaviour for this comes from super). response = CoreExecuteQuery(text, parameters); // Return the result. return(response); } finally { try { // This is executed no matter what happens. Very important we // unlock the tables. if (lockMode != LockingMode.None) { locker.FinishMode(lockMode); } } catch (Exception e) { // If this throws an exception, we should output it to the debug // log and screen. Logger.Error(this, "Exception finishing locks"); Logger.Error(this, e); // Note, we can't throw an error here because we may already be in // an exception that happened in the above 'try' block. } } } finally { // This always happens after tables are unlocked. // Also guarenteed to happen even if something fails. // If we are in auto-commit mode then commit the Query here. // Do we auto-commit? if (Session.Connection.AutoCommit) { // Yes, so grab an exclusive Lock and auto-commit. try { // Lock into exclusive mode. locker.SetMode(LockingMode.Exclusive); // If an error occured then roll-back if (response == null) { // Rollback. Session.Connection.Rollback(); } else { try { // Otherwise commit. Session.Connection.Commit(); } catch (Exception e) { foreach (IQueryResponse queryResponse in response) { // Dispose this response if the commit failed. DisposeResult(queryResponse.ResultId); } // And throw the SQL Exception throw; } } } finally { locker.FinishMode(LockingMode.Exclusive); } } } }
public LockTableStatement(ObjectName tableName, LockingMode mode) : this(tableName, mode, Timeout.Infinite) { }
private void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode) { if (lockables == null) return; for (int i = lockables.Length - 1; i >= 0; --i) { var lockable = lockables[i]; var queue = GetQueueFor(lockable); handle.AddLock(queue.NewLock(mode, accessType)); } }
public LockHandle LockWrite(ILockable lockable, LockingMode mode) { return(Lock(lockable, AccessType.Write, mode)); }
public static void LockTable(this IRequest request, ObjectName tableName, LockingMode mode, int timeout) { request.ExecuteStatement(new LockTableStatement(tableName, mode, timeout)); }
public LockHandle LockRead(ILockable[] lockables, LockingMode mode) { return Lock(lockables, AccessType.Read, mode); }
public static void Lock(this ITransaction transaction, IEnumerable <ObjectName> tableNames, AccessType accessType, LockingMode mode, int timeout) { var lockables = tableNames.Select(transaction.FindObject); transaction.Lock(lockables.ToArray(), mode, timeout); }
public static void LockTable(this IRequest request, ObjectName tableName, LockingMode mode) { LockTable(request, tableName, mode, Timeout.Infinite); }
public static LockHandle LockTables(this ITransaction transaction, IEnumerable <ObjectName> tableNames, AccessType accessType, LockingMode mode) { var tables = tableNames.Select(transaction.GetTable).OfType <ILockable>(); return(transaction.Database.Locker.Lock(tables.ToArray(), accessType, mode)); }
public static LockHandle LockTables(this ITransaction transaction, IEnumerable<ObjectName> tableNames, AccessType accessType, LockingMode mode) { var tables = tableNames.Select(transaction.GetTable).OfType<ILockable>(); return transaction.Database.Locker.Lock(tables.ToArray(), accessType, mode); }
public static void Lock(this IUserSession session, LockingMode mode) { var lockable = new ILockable[] { session.Transaction }; session.Lock(lockable, lockable, LockingMode.Exclusive); }
private void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode) { if (lockables == null) return; for (int i = lockables.Length - 1; i >= 0; --i) { var lockable = lockables[i]; var queue = GetQueueFor(lockable); // slightly confusing: this will add Lock to given table queue var @lock = new Lock(queue, mode, accessType); @lock.Acquire(); handle.AddLock(@lock); } }
public Lock(LockingQueue queue, LockingMode mode, AccessType accessType) { this.queue = queue; this.mode = mode; AccessType = accessType; }
private void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode) { if (lockables == null) { return; } for (int i = lockables.Length - 1; i >= 0; --i) { var lockable = lockables[i]; var queue = GetQueueFor(lockable); // slightly confusing: this will add Lock to given table queue var @lock = new Lock(queue, mode, accessType); @lock.Acquire(); handle.AddLock(@lock); } }
public LockHandle Lock(ILockable lockable, AccessType accessType, LockingMode mode) => Lock(new[] { lockable }, accessType, mode);
public LockHandle Lock(ILockable lockable, AccessType accessType, LockingMode mode) { return(Lock(new[] { lockable }, accessType, mode)); }
public void Lock(IEnumerable <IDbObject> objects, AccessType accessType, LockingMode mode) { // A system session does not hold any lock }
public LockHandle LockRead(ILockable[] lockables, LockingMode mode) { return(Lock(lockables, AccessType.Read, mode)); }
public void LockTable(ObjectName tableName, LockingMode mode, int waitTimeout) { Session.Lock(new [] { tableName }, AccessType.ReadWrite, mode, waitTimeout); }
internal LockEvent(LockEventType eventType, IEnumerable <ObjectName> references, LockingMode mode, AccessType accessType) { EventType = eventType; References = references; Mode = mode; AccessType = accessType; }
public void Lock(IEnumerable<IDbObject> objects, LockingMode mode, int timeout) { lock (Database) { var lockables = objects.OfType<ILockable>().ToArray(); if (lockables.Length == 0) return; // Before we can lock the objects, we must wait for them // to be available... if (lockables.Any(x => Database.Locker.IsLocked(x))) Database.Locker.CheckAccess(lockables, AccessType.ReadWrite, timeout); var handle = Database.Locker.Lock(lockables, AccessType.ReadWrite, mode); if (lockHandles == null) lockHandles = new List<LockHandle>(); lockHandles.Add(handle); var lockedNames = objects.Where(x => x is ILockable).Select(x => x.ObjectInfo.FullName); Context.OnEvent(new LockEvent(LockEventType.Lock, lockedNames, LockingMode.Exclusive, AccessType.ReadWrite)); } }