/** Do the real work of dumpLockTableInternal. */ void dumpLockTableInternal(StatGroup tableStats, int i, boolean clear) { StatGroup oneTable = new StatGroup("Single lock table", "Temporary stat group"); IntStat totalLocks = new IntStat(oneTable, LOCK_TOTAL); IntStat waiters = new IntStat(oneTable, LOCK_WAITERS); IntStat owners = new IntStat(oneTable, LOCK_OWNERS); IntStat readLocks = new IntStat(oneTable, LOCK_READ_LOCKS); IntStat writeLocks = new IntStat(oneTable, LOCK_WRITE_LOCKS); Map<Long, Lock> lockTable = lockTables[i]; totalLocks.add(lockTable.size()); for (Lock lock : lockTable.values()) { waiters.add(lock.nWaiters()); owners.add(lock.nOwners()); /* Go through all the owners for a lock. */ for (LockInfo info : lock.getOwnersClone()) { if (info.getLockType().isWriteLock()) { writeLocks.increment(); } else { readLocks.increment(); } } } tableStats.addAll(oneTable); }
/** Unlock the VFS lock only */ @Override public boolean unlock(VFSItem item, Identity identity, Roles roles) { if (item instanceof MetaTagged) { MetaInfoFileImpl info = (MetaInfoFileImpl) ((MetaTagged) item).getMetaInfo(); if (info == null) return false; info.setLockedBy(null); info.setLockedDate(null); info.setLocked(false); info.write(); boolean unlocked = false; File file = extractFile(item); if (file != null && fileLocks.containsKey(file)) { LockInfo lock = fileLocks.get(file); if (lock.isWebDAVLock()) { lock.setVfsLock(false); } else { if (lock.getWebPath() != null) { // LOCK resourceLocks.remove(lock.getWebPath()); } fileLocks.remove(file); unlocked = true; } } else { unlocked = true; } return unlocked; } return false; }
public int lock(String userName) throws ClientException { LockInfo lockInfo = getLockInfo(); boolean canLock = false; int returnCode = LOCKED_OK; if (lockInfo != null) { // document is already locked String lockingUser = lockInfo.getUserName(); if (lockingUser == null) { canLock = true; } else { if (lockingUser.equals(userName)) { canLock = true; return ALREADY_LOCKED_BY_YOU; } else { if (isLockExpired()) { canLock = true; returnCode = LOCK_BORROWED; } else { canLock = false; return CAN_NOT_BORROW_LOCK; } } } } CoreSession session = getSessionFromDoc(targetDoc); session.setLock(targetDoc.getRef(), getLockToken(userName)); session.save(); return returnCode; }
public int unlock(String userName) throws ClientException { LockInfo lockInfo = getLockInfo(); boolean canUnLock = false; int returnCode = NOT_LOCKED; if (lockInfo != null) { // document is already locked String lockingUser = lockInfo.getUserName(); if (lockingUser == null) { canUnLock = true; returnCode = NOT_LOCKED; } else { if (lockingUser.equals(userName)) { canUnLock = true; returnCode = ALREADY_LOCKED_BY_YOU; } else { if (isLockExpired()) { canUnLock = true; returnCode = LOCK_EXPIRED; } else { canUnLock = false; return CAN_NOT_UNLOCK; } } } } if (canUnLock) { getSessionFromDoc(targetDoc).unlock(targetDoc.getRef()); } return returnCode; }
public boolean isLocked() throws ClientException { LockInfo info = getLockInfo(); if (info == null || info.getUserName() == null) { return false; } return !isLockExpired(); }
public boolean isLockExpired() throws ClientException { LockInfo lockInfo = getLockInfo(); double lockAgeInHour = (new Date().getTime() - lockInfo.getLockDate().getTime()) / (3600.0 * 1000.0); return lockAgeInHour > LOCK_TIMEOUT_IN_HOURS; }
private long[] getTxnIds(Collection<LockInfo> c) { long[] ret = new long[c.size()]; Iterator<LockInfo> iter = c.iterator(); int i = 0; while (iter.hasNext()) { LockInfo info = iter.next(); ret[i++] = info.getLocker().getId(); } return ret; }
public void removeResourceLock(WebResource resource) { // LOCK File file = extractFile(resource); if (file != null) { LockInfo lock = fileLocks.get(file); if (lock != null) { if (lock.isVfsLock()) { lock.setWebDAVLock(false); } else { fileLocks.remove(file); } } } }
@Override public boolean isLocked(VFSItem item) { File file = extractFile(item); if (file != null && fileLocks.containsKey(file)) { LockInfo lock = fileLocks.get(file); if (lock != null && lock.hasExpired()) { // LOCK resourceLocks.remove(lock.getWebPath()); fileLocks.remove(file); } else { return true; } } Long lockedBy = getMetaLockedBy(item); return (lockedBy != null); }
/** @return true If the lock owner is someone else or if it's a WebDAV lock */ @Override public boolean isLockedForMe(VFSItem item, Identity me, Roles roles) { File file = extractFile(item); if (file != null && fileLocks.containsKey(file)) { LockInfo lock = fileLocks.get(file); if (lock != null && lock.hasExpired()) { // LOCK resourceLocks.remove(lock.getWebPath()); fileLocks.remove(file); } else { Long lockedBy = lock.getLockedBy(); return (lockedBy != null && !lockedBy.equals(me.getKey())) || lock.isWebDAVLock(); } } Long lockedBy = getMetaLockedBy(item); return (lockedBy != null && !lockedBy.equals(me.getKey())); }
/** * Return a lock info base on the VFS lock * * @param resource * @return */ public LockInfo getVFSLock(WebResource resource) { VFSItem item = extractItem(resource); MetaInfoFileImpl info = getMetaInfo(item); if (info != null && info.isLocked()) { File file = extractFile(item); LockInfo lock = null; if (fileLocks.containsKey(file)) { lock = fileLocks.get(file); if (lock != null) { lock.setVfsLock(true); } } if (lock == null) { lock = new LockInfo(info.getLockedBy(), false, true); lock.setWebResource(resource); lock.setCreationDate(info.getLockedDate()); lock.setOwner(Settings.getServerContextPathURI() + "/Identity/" + info.getLockedBy()); lock.setDepth(1); lock.addToken(generateLockToken(lock, info.getLockedBy())); fileLocks.put(file, lock); } return lock; } return null; }
public LockInfo getLockInfo() throws ClientException { String existingLock = session.getLock(targetDoc.getRef()); if (existingLock == null || existingLock.equals("")) { return null; } String[] info = existingLock.split(":"); LockInfo lockInfo; try { lockInfo = new LockInfo(info[0], info[1]); lockInfo.setToken(existingLock); } catch (ParseException e) { throw new ClientException( "Unable to parse lockInfo for document " + targetDoc.getPathAsString(), e); } return lockInfo; }
@Override public boolean lock(VFSItem item, Identity identity, Roles roles) { if (item instanceof MetaTagged) { MetaInfoFileImpl info = (MetaInfoFileImpl) ((MetaTagged) item).getMetaInfo(); info.setLockedBy(identity.getKey()); info.setLockedDate(new Date()); info.setLocked(true); info.write(); File file = extractFile(item); if (file != null && fileLocks.containsKey(file)) { LockInfo lock = fileLocks.get(file); if (lock != null) { lock.setVfsLock(true); } } return true; } return false; }
/** * Check to see if a resource is currently write locked. * * @param path Path of the resource * @param ifHeader "If" HTTP header which was included in the request * @return boolean true if the resource is locked (and no appropriate lock token has been found * for at least one of the non-shared locks which are present on the resource). */ public boolean isLocked(WebResource resource, String ifHeader, Identity identity) { // Checking resource locks String path = resource.getPath(); // check if someone else as not set a lock on the resource if (resource instanceof VFSResource) { VFSResource vfsResource = (VFSResource) resource; Long lockedBy = getMetaLockedBy(vfsResource.getItem()); if (lockedBy != null && !lockedBy.equals(identity.getKey())) { return true; } } File file = extractFile(resource); if (file == null) { return false; // lock only file } LockInfo lock = fileLocks.get(file); if (lock != null && lock.hasExpired()) { fileLocks.remove(file); } else if (lock != null) { // At least one of the tokens of the locks must have been given Iterator<String> tokenList = lock.tokens(); boolean tokenMatch = false; while (tokenList.hasNext()) { String token = tokenList.next(); if (ifHeader.indexOf(token) != -1) { tokenMatch = true; break; } } if (!tokenMatch) return true; } // Checking inheritable collection locks Enumeration<LockInfo> collectionLocksList = collectionLocks.elements(); while (collectionLocksList.hasMoreElements()) { lock = collectionLocksList.nextElement(); if (lock.hasExpired()) { collectionLocks.removeElement(lock); } else if (path.startsWith(lock.getWebPath())) { Iterator<String> tokenList = lock.tokens(); boolean tokenMatch = false; while (tokenList.hasNext()) { String token = tokenList.next(); if (ifHeader.indexOf(token) != -1) { tokenMatch = true; break; } } if (!tokenMatch) return true; } } return false; }
@Override public LockInfo getLock(VFSItem item) { File file = extractFile(item); if (file != null && fileLocks.containsKey(file)) { LockInfo lock = fileLocks.get(file); if (lock != null) { return lock; } } MetaInfoFileImpl info = getMetaInfo(item); if (info != null && info.isLocked()) { LockInfo lock = new LockInfo(info.getLockedBy(), false, true); lock.setCreationDate(info.getLockedDate()); lock.setOwner(Settings.getServerContextPathURI() + "/Identity/" + info.getLockedBy()); lock.setDepth(1); lock.addToken(generateLockToken(lock, info.getLockedBy())); fileLocks.put(file, lock); return lock; } return null; }
private StringBuilder findDeadlock1(Set<Locker> ownerSet, Lock lock, Locker rootLocker) { Iterator<LockInfo> ownerIter = lock.getOwnersClone().iterator(); while (ownerIter.hasNext()) { LockInfo info = ownerIter.next(); Locker locker = info.getLocker(); Lock waitsFor = locker.getWaitingFor(); if (ownerSet.contains(locker) || locker == rootLocker) { /* Found a cycle. */ StringBuilder ret = new StringBuilder(); ret.append("Transaction ").append(locker.toString()); ret.append(" owns LockAddr:").append(System.identityHashCode(lock)); ret.append(" ").append(info).append("\n"); ret.append("Transaction ").append(locker.toString()); ret.append(" waits for"); if (waitsFor == null) { ret.append(" nothing"); } else { ret.append(" LockAddr:"); ret.append(System.identityHashCode(waitsFor)); } ret.append("\n"); return ret; } if (waitsFor != null) { ownerSet.add(locker); StringBuilder sb = findDeadlock1(ownerSet, waitsFor, rootLocker); if (sb != null) { String waitInfo = "Transaction " + locker + " waits for " + waitsFor + "\n"; sb.insert(0, waitInfo); return sb; } ownerSet.remove(locker); // is this necessary? } } return null; }
// During parsing, GSON will try. Which means sometimes we get 'empty' objects // They're non-null, but don't have any information. public LockInfo getLockInfo() { if (lock_info == null || lock_info.isEmpty()) { return null; } return lock_info; }
/** Process notifications of mutable property changes. */ public void envConfigUpdate(DbConfigManager configMgr, EnvironmentMutableConfig ignore) { LockInfo.setDeadlockStackTrace( configMgr.getBoolean(EnvironmentParams.TXN_DEADLOCK_STACK_TRACE)); setLockTableDump(configMgr.getBoolean(EnvironmentParams.TXN_DUMPLOCKS)); }