コード例 #1
0
 internal Lock(LockingQueue queue, LockingMode mode, AccessType accessType)
 {
     Queue      = queue;
     AccessType = accessType;
     Mode       = mode;
     Queue.Acquire(this);
 }
コード例 #2
0
ファイル: Lock.cs プロジェクト: ArsenShnurkov/deveeldb
 internal Lock(LockingQueue queue, LockingMode mode, AccessType accessType)
 {
     Queue = queue;
     AccessType = accessType;
     Mode = mode;
     Queue.Acquire(this);
 }
コード例 #3
0
ファイル: LockEvent.cs プロジェクト: deveel/deveeldb
 internal LockEvent(LockEventType eventType, IEnumerable<ObjectName> references, LockingMode mode, AccessType accessType)
 {
     EventType = eventType;
     References = references;
     Mode = mode;
     AccessType = accessType;
 }
コード例 #4
0
ファイル: Locker.cs プロジェクト: prepare/deveeldb
        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;
        }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
ファイル: LockingQueue.cs プロジェクト: deveel/deveeldb
 public Lock NewLock(LockingMode mode, AccessType accessType)
 {
     lock (this) {
         var @lock = new Lock(this, mode, accessType);
         Acquire(@lock);
         @lock.OnAcquired();
         return @lock;
     }
 }
コード例 #7
0
        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);
        }
コード例 #8
0
 public Lock NewLock(LockingMode mode, AccessType accessType)
 {
     lock (this) {
         var @lock = new Lock(this, mode, accessType);
         Acquire(@lock);
         @lock.OnAcquired();
         return(@lock);
     }
 }
コード例 #9
0
ファイル: LockTableStatement.cs プロジェクト: deveel/deveeldb
        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;
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
ファイル: Locker.cs プロジェクト: meikeric/deveeldb
        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);
            }
        }
コード例 #12
0
        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
        }
コード例 #13
0
        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;
        }
コード例 #14
0
        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.");
        }
コード例 #15
0
ファイル: Locker.cs プロジェクト: ArsenShnurkov/deveeldb
        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;
            }
        }
コード例 #16
0
ファイル: Session.cs プロジェクト: meikeric/deveeldb
        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);
            }
        }
コード例 #17
0
        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));
            }
        }
コード例 #18
0
 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);
 }
コード例 #19
0
 public void Lock(IEnumerable<IDbObject> objects, AccessType accessType, LockingMode mode)
 {
     // A system session does not hold any lock
 }
コード例 #20
0
 internal Lock(LockingQueue queue, LockingMode mode, AccessType accessType)
 {
     Queue      = queue;
     AccessType = accessType;
     Mode       = mode;
 }
コード例 #21
0
ファイル: UserSession.cs プロジェクト: prepare/deveeldb
        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);
            }
        }
コード例 #22
0
 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);
 }
コード例 #23
0
ファイル: SystemUserSession.cs プロジェクト: prepare/deveeldb
 public void Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode)
 {
 }
コード例 #24
0
ファイル: Locker.cs プロジェクト: ArsenShnurkov/deveeldb
 public LockHandle LockWrite(ILockable[] lockables, LockingMode mode)
 {
     return Lock(lockables, AccessType.Write, mode);
 }
コード例 #25
0
ファイル: Locker.cs プロジェクト: ArsenShnurkov/deveeldb
 public LockHandle Lock(ILockable lockable, AccessType accessType, LockingMode mode)
 {
     return Lock(new[] {lockable}, accessType, mode);
 }
コード例 #26
0
ファイル: Session.cs プロジェクト: ArsenShnurkov/deveeldb
        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);
            }
        }
コード例 #27
0
ファイル: SessionExtensions.cs プロジェクト: deveel/deveeldb
        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);
        }
コード例 #28
0
ファイル: Locker.cs プロジェクト: ArsenShnurkov/deveeldb
        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;
            }
        }
コード例 #29
0
        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);
                    }
                }
            }
        }
コード例 #30
0
ファイル: LockTableStatement.cs プロジェクト: deveel/deveeldb
 public LockTableStatement(ObjectName tableName, LockingMode mode)
     : this(tableName, mode, Timeout.Infinite)
 {
 }
コード例 #31
0
ファイル: Locker.cs プロジェクト: deveel/deveeldb
        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));
            }
        }
コード例 #32
0
ファイル: Locker.cs プロジェクト: meikeric/deveeldb
 public LockHandle LockWrite(ILockable lockable, LockingMode mode)
 {
     return(Lock(lockable, AccessType.Write, mode));
 }
コード例 #33
0
 public static void LockTable(this IRequest request, ObjectName tableName, LockingMode mode, int timeout)
 {
     request.ExecuteStatement(new LockTableStatement(tableName, mode, timeout));
 }
コード例 #34
0
ファイル: Locker.cs プロジェクト: ArsenShnurkov/deveeldb
 public LockHandle LockRead(ILockable[] lockables, LockingMode mode)
 {
     return Lock(lockables, AccessType.Read, mode);
 }
コード例 #35
0
        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);
        }
コード例 #36
0
 public static void LockTable(this IRequest request, ObjectName tableName, LockingMode mode)
 {
     LockTable(request, tableName, mode, Timeout.Infinite);
 }
コード例 #37
0
 public LockTableStatement(ObjectName tableName, LockingMode mode)
     : this(tableName, mode, Timeout.Infinite)
 {
 }
コード例 #38
0
        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));
        }
コード例 #39
0
 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);
 }
コード例 #40
0
 public static void Lock(this IUserSession session, LockingMode mode)
 {
     var lockable = new ILockable[] { session.Transaction };
     session.Lock(lockable, lockable, LockingMode.Exclusive);
 }
コード例 #41
0
ファイル: Locker.cs プロジェクト: ArsenShnurkov/deveeldb
        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);
            }
        }
コード例 #42
0
 public Lock(LockingQueue queue, LockingMode mode, AccessType accessType)
 {
     this.queue = queue;
     this.mode  = mode;
     AccessType = accessType;
 }
コード例 #43
0
ファイル: Locker.cs プロジェクト: meikeric/deveeldb
        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);
            }
        }
コード例 #44
0
 public LockHandle Lock(ILockable lockable, AccessType accessType, LockingMode mode)
 => Lock(new[] { lockable }, accessType, mode);
コード例 #45
0
ファイル: Locker.cs プロジェクト: meikeric/deveeldb
 public LockHandle Lock(ILockable lockable, AccessType accessType, LockingMode mode)
 {
     return(Lock(new[] { lockable }, accessType, mode));
 }
コード例 #46
0
 public void Lock(IEnumerable <IDbObject> objects, AccessType accessType, LockingMode mode)
 {
     // A system session does not hold any lock
 }
コード例 #47
0
ファイル: Locker.cs プロジェクト: meikeric/deveeldb
 public LockHandle LockRead(ILockable[] lockables, LockingMode mode)
 {
     return(Lock(lockables, AccessType.Read, mode));
 }
コード例 #48
0
 public void LockTable(ObjectName tableName, LockingMode mode, int waitTimeout)
 {
     Session.Lock(new [] { tableName }, AccessType.ReadWrite, mode, waitTimeout);
 }
コード例 #49
0
ファイル: Lock.cs プロジェクト: deveel/deveeldb
 internal Lock(LockingQueue queue, LockingMode mode, AccessType accessType)
 {
     Queue = queue;
     AccessType = accessType;
     Mode = mode;
 }
コード例 #50
0
 internal LockEvent(LockEventType eventType, IEnumerable <ObjectName> references, LockingMode mode, AccessType accessType)
 {
     EventType  = eventType;
     References = references;
     Mode       = mode;
     AccessType = accessType;
 }
コード例 #51
0
ファイル: Transaction.cs プロジェクト: deveel/deveeldb
        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));
            }
        }