Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void ensureSufficientLockHeld(LockContext lockContext, LockType lockType) {
- // TODO(hw4_part2): implement
- TransactionContext transaction = TransactionContext.getTransaction(); // current transaction
- if(transaction == null){
- return;
- }
- //ensuring that we have the appropriate locks on ancestors,
- LockType currLockType = lockContext.getEffectiveLockType(transaction);
- if(hasSufficient(currLockType, lockType)){
- return;
- }
- //handle parent stuff
- if(lockContext.parent != null){
- //need to acquire proper parent locks from top >> bottom
- getCorrectParentLocks(lockContext.parent, LockType.parentLock(lockType));
- }
- //
- currLockType = lockContext.getExplicitLockType(transaction);
- if(currLockType.equals(LockType.IX) && lockType.equals(LockType.S)){
- lockContext.promote(transaction, LockType.SIX);
- }
- else if(currLockType.equals(LockType.NL)){
- lockContext.acquire(transaction, lockType);
- }
- else{
- lockContext.escalate(transaction);
- currLockType = lockContext.getExplicitLockType(transaction);
- if(currLockType.equals(LockType.S) && lockType.equals(LockType.X)){
- lockContext.promote(transaction, lockType);
- }
- }
- //and acquiring the lock on the resource
- return;
- }
- public static void getCorrectParentLocks(LockContext lockContext, LockType lockType){
- if(lockContext.parent != null){
- // LockType parentLock = lockContext.parent.getEffectiveLockType(transaction);
- //need to acquire proper parent locks from top >> bottom
- LockUtil.getCorrectParentLocks(lockContext.parent, LockType.parentLock(lockType));
- //acquire promote escalate
- }
- TransactionContext transaction = TransactionContext.getTransaction();
- LockType currLockType = lockContext.getExplicitLockType(transaction);
- if(currLockType.equals(LockType.X) || LockType.substitutable(currLockType ,lockType)){
- return;
- }
- if(currLockType.equals(LockType.S) && lockType.equals(LockType.IX)){
- lockContext.promote(transaction, LockType.SIX);
- }
- else if(lockContext.getEffectiveLockType(transaction).equals(LockType.NL)){
- lockContext.acquire(transaction, lockType);
- }
- else{
- lockContext.promote(transaction, lockType);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement