예제 #1
0
 /// <summary>
 ///   11/7/2011
 ///   Checks whether a write lock requests conflicts with existing locks.
 ///   In the case that the item is locked due to recovery, we unlock the item and return false i.e. there are no conflicts.
 /// </summary>
 /// <param name = "requestedLock">The requested lock.</param>
 /// <param name = "entry">The lock table entry to test.</param>
 /// <returns>True if the requested write lock conflicts with any existing locks</returns>
 /// <remarks>
 ///   Side effect: if the lock was held by the LM due to recovery, the lock will be removed
 /// </remarks>
 private bool WriteLockConflicts(Lock requestedLock, LockManagerTableEntry entry)
 {
     int? conflictingTransaction = entry.FindConflictsToWriteLock(requestedLock.TransactionId);
     if (conflictingTransaction == null)
         return false;
     if (conflictingTransaction == int.MinValue)
     {
         entry.RemoveLock(int.MinValue);
         return false;
     }
     return true;
 }
예제 #2
0
 /// <summary>
 ///   Creates a new object that is a copy of the current instance.
 /// </summary>
 /// <returns>
 ///   A new object that is a copy of this instance.
 /// </returns>
 public object Clone()
 {
     LockManagerTableEntry entry = new LockManagerTableEntry();
     entry.activeLocks = new List<Lock>(activeLocks);
     return entry;
 }
예제 #3
0
 /// <summary>
 ///   11/7/2011
 ///   A method to get a list of IDs for all transactions currently locking a data item
 /// </summary>
 /// <param name = "entry">The entry corresponding to the data item in request.</param>
 /// <returns>A list of IDs of all transactions holding the data item</returns>
 private List<int> GetListOfTransactionsLockingTheItem(LockManagerTableEntry entry)
 {
     List<int> activeLockTransactions = new List<int>();
     foreach (Lock @lock in entry.ActiveLocks)
         if (!activeLockTransactions.Contains(@lock.TransactionId))
             activeLockTransactions.Add(@lock.TransactionId);
     return activeLockTransactions;
 }
예제 #4
0
 /// <summary>
 ///   11/7/2011
 ///   Checks whether a read lock request conflicts with existing locks.
 /// </summary>
 /// <param name = "requestedLock">The requested lock.</param>
 /// <param name = "entry">The entry.</param>
 /// <returns>True if the requested read lock conflicts with any existing locks</returns>
 private bool ReadLockConflicts(Lock requestedLock, LockManagerTableEntry entry)
 {
     int? conflictingTransaction = entry.FindConflictsToReadLock(requestedLock.TransactionId);
     if (conflictingTransaction == null)
     {
         return false;
     }
     return true;
 }
예제 #5
0
 /// <summary>
 ///   Date: 10/16/2011
 ///   Adds a new LockManagerTableEntry object to the lock entries dictionary
 /// </summary>
 /// <param name = "transId">The trans id.</param>
 /// <param name = "dataItem">The data item.</param>
 /// <param name = "operationMode">The operation mode.</param>
 /// <remarks>
 ///   Side effects: a new lock entry is added to the dictionary
 /// </remarks>
 private void AddLock(int transId, int dataItem, Enumerations.OperationMode operationMode)
 {
     var entry = new LockManagerTableEntry();
     entry.AddToActiveLocks(transId, operationMode);
     lockEntries[dataItem] = entry;
 }
예제 #6
0
 /// <summary>
 ///   Date: 10/16/2011
 ///   Removes all locks which a transaction holds on a data item
 /// </summary>
 /// <param name = "entry">The lock entry.</param>
 /// <param name = "transId">The transaction'd ID.</param>
 /// <remarks>
 ///   Side effects: All locks held by this transaction for this data item are removed
 /// </remarks>
 private static void RemoveLock(LockManagerTableEntry entry, int transId)
 {
     entry.RemoveLock(transId);
 }
예제 #7
0
 /// <summary>
 ///   Date: 10/16/2011
 ///   Tests to see if the entry has any more active locks or if it can be deleted
 /// </summary>
 /// <param name = "entry">The entry.</param>
 /// <returns>True if there are no more active locks held in the entry</returns>
 private static bool NoMoreLocks(LockManagerTableEntry entry)
 {
     return (entry.GetNumberOfLocks()) == 0;
 }
예제 #8
0
 /// <summary>
 ///   Date: 10/16/2011
 ///   Checks whether a lock request conflicts with existing locks
 /// </summary>
 /// <param name = "requestedLock">The requested lock.</param>
 /// <param name = "entry">The lock entries entry corresponding to the data item the lock wishes to lock.</param>
 /// <returns>true if requested lock conflicts with any existing locks</returns>
 internal bool LockConflicts(Lock requestedLock, LockManagerTableEntry entry)
 {
     if (requestedLock.Mode == Enumerations.OperationMode.Read)
     {
         if (!ReadLockConflicts(requestedLock, entry)) return false;
     }
     else if (requestedLock.Mode == Enumerations.OperationMode.Write)
     {
         if (!WriteLockConflicts(requestedLock, entry)) return false;
     }
     return true;
 }
예제 #9
0
        /// <summary>
        ///   11/7/2011
        ///   Simulates recovery by removing all lock information and then locking any replicated data items with a "fake lock"
        /// </summary>
        /// <remarks>
        ///   Side effects: all previous lock information is destroyed and all replicated data items are locked for reading until written into
        /// </remarks>
        public void Recover()
        {
            lockEntries = new Dictionary<int, LockManagerTableEntry>();
            LockManagerTableEntry entry;

            // Lock all replicated data items
            for (int i = 2; i <= TransactionManager.NumberOfDataItems; i += 2)
            {
                entry = new LockManagerTableEntry();
                entry.ActiveLocks.Add(new Lock(int.MinValue, Enumerations.OperationMode.Write));
                lockEntries[i] = entry;
            }
        }