def add_lock(self, clientId, lock, locktype, mid): ''' First check if the lock already exists ''' indx = get_hash_index(lock, MAX_PARTITIONS, BITWISEAND) alllocks = self.alllocks[indx] partlock = self.partitionlock[indx] with partlock: if lock in alllocks: lck = alllocks[lock] ret = self.check_existing_lock(lck, clientId, locktype) if ret == StatusMsg.WRITE_LOCK_QUEUED or ret == StatusMsg.READ_LOCK_QUEUED: if clientId not in self.clientlocks: self.clientlocks[clientId] = {} self.clientlocks[clientId][lock] = (lck, mid) else: '''We need to send the response now!!!!''' response = get_Response_msg(mid, ret) eobj = event(common.RESPONSE_TOPIC, (clientId, response)) self.ebus.post(eobj) return ret ''' Lock doesn't exist, get the new lock ''' logging.debug('Client ' + clientId + ' taking the new lock ' + lock + ' ' + str(locktype)) lck = LockDef(lock, clientId, locktype) alllocks[lock] = lck if clientId not in self.clientlocks: self.clientlocks[clientId] = {} self.clientlocks[clientId][lock] = (lck, mid) response = get_Response_msg(mid, StatusMsg.LOCK_GRANTED) eobj = event(common.RESPONSE_TOPIC, (clientId, response)) self.ebus.post(eobj) return StatusMsg.SUCCESS
def add_lock(self, clientId, lock, locktype, mid): ''' First check if the lock already exists ''' indx = get_hash_index(lock, MAX_PARTITIONS, BITWISEAND) alllocks = self.alllocks[indx] partlock = self.partitionlock[indx] with partlock: if lock in alllocks: lck = alllocks[lock] ret = self.check_existing_lock(lck, clientId, locktype) if ret == StatusMsg.WRITE_LOCK_QUEUED or ret == StatusMsg.READ_LOCK_QUEUED: if clientId not in self.clientlocks: self.clientlocks[clientId] = {} self.clientlocks[clientId][lock] = (lck, mid) else: '''We need to send the response now!!!!''' response = get_Response_msg(mid, ret) eobj = event(common.RESPONSE_TOPIC, (clientId, response)) self.ebus.post(eobj) return ret ''' Lock doesn't exist, get the new lock ''' logging.debug('Client ' + clientId + ' taking the new lock ' + lock + ' ' + str(locktype)) lck = LockDef(lock, clientId, locktype) alllocks[lock] = lck if clientId not in self.clientlocks: self.clientlocks[clientId] = {} self.clientlocks[clientId][lock] = (lck , mid) response = get_Response_msg(mid, StatusMsg.LOCK_GRANTED) eobj = event(common.RESPONSE_TOPIC, (clientId, response)) self.ebus.post(eobj) return StatusMsg.SUCCESS
def getLockDetails(self, lock): ''' Returns the details of the lock with the name 'lock' it will return FAIL status message if the lock is not found in this lock container ''' logging.debug('Trying to get LockDetails for ' + lock) retval = LockDetails() retval.lockName = lock indx = get_hash_index(lock, MAX_PARTITIONS, BITWISEAND) partlock = None partallocks = None self.biglock.acquire() with self.biglock: if indx not in self.alllocks: retval.sm.sv = StatusMsg.FAIL return retval partlock = self.partitionlock[indx] partallocks = self.alllocks[indx] partlock.acquire() if lock in partallocks: lck = partallocks[lock] if lck.writeLocker is not None: retval.currentWriter = lck.writeLocker retval.currentReaders.extend(lck.readers) retval.currentWriteWaits.extend(lck.write_waits) if lck.locktype == LockOperation.WRITELOCK: retval.lockType = 'WRITE' else: retval.lockType = 'READ' partlock.release() if retval is None: logging.debug('Lock details not found' + lock) retval.sm.sv = StatusMsg.FAIL else: retval.sm.sv = StatusMsg.SUCCESS logging.debug('Lock details ' + str(retval)) return retval