public DLockGrantor getGrantor() { Assert.assertHoldsLock(this.destroyLock, false); synchronized (this.lockGrantorIdLock) { return this.grantor; } }
/** * Returns true if locking has been suspended. * <p> * Caller must synchronize on suspendLock. * * Concurrency: protected by synchronization of {@link #suspendLock} * * @return true if locking has been suspended */ protected boolean isLockingSuspended() { if (DEBUG_SUSPEND_LOCK) { Assert.assertHoldsLock(this.suspendLock, true); } return this.lockingSuspendedBy != null; }
private void basicRemoveIndex(int index) { Assert.assertHoldsLock(this, true); // minimize volatile reads by copying ref to local var Profile[] oldProfiles = this.profiles; // volatile read Profile[] newProfiles = new Profile[oldProfiles.length - 1]; System.arraycopy(oldProfiles, 0, newProfiles, 0, index); System.arraycopy(oldProfiles, index + 1, newProfiles, index, newProfiles.length - index); this.profiles = newProfiles; // volatile write if (this.numActiveProfiles > 0) { this.numActiveProfiles--; } }
/** * Returns true if <code>someLockGrantor</code> equals the current {@link #lockGrantorId}. * * @return true if someLockGrantor equals the current lockGrantorId */ private boolean equalsLockGrantorId(LockGrantorId someLockGrantor) { Assert.assertHoldsLock(this.lockGrantorIdLock, true); if (someLockGrantor == null) { return this.lockGrantorId == null; } return someLockGrantor.equals(this.lockGrantorId); }
/** * Returns true if {@link #lockGrantorId} is the same as the specified LockGrantorId. Caller must * synchronize on {@link #lockGrantorIdLock}. * * @param someLockGrantorId the LockGrantorId to check */ private boolean checkLockGrantorId(LockGrantorId someLockGrantorId) { Assert.assertHoldsLock(this.lockGrantorIdLock, true); if (this.lockGrantorId == null) { return false; } return this.lockGrantorId.sameAs(someLockGrantorId); }
/** * Resume locking after it has been suspended. * <p> * Caller must synchronize on suspendLock. */ private void resumeLocking() { if (DEBUG_SUSPEND_LOCK) { Assert.assertHoldsLock(this.suspendLock, true); } if (logger.isTraceEnabled(LogMarker.DLS_VERBOSE)) { logger.trace(LogMarker.DLS_VERBOSE, "Resume locking of {}", this.dlock); } this.lockingSuspendedBy = null; this.suspendedLockId = INVALID_LOCK_ID; }
/** * Returns true if locking has been suspended by the remote thread. * <p> * Caller must synchronize on suspendLock. * * Concurrency: protected by synchronization of {@link #suspendLock} * * @return true if locking has been suspended by the remote thread */ protected boolean isLockingSuspendedBy(final RemoteThread rThread) { if (DEBUG_SUSPEND_LOCK) { Assert.assertHoldsLock(this.suspendLock, true); } if (rThread == null) return false; return rThread.equals(this.lockingSuspendedBy); }
/** * Debugging method * * guarded.By {@link #suspendLock} */ private void checkTotalReadLockCount() { if (!DEBUG_SUSPEND_LOCK) { return; } Assert.assertHoldsLock(this.suspendLock, true); int result = 0; Iterator it = readLockCountMap.values().iterator(); while (it.hasNext()) { result += ((Integer) it.next()).intValue(); } Assert.assertTrue(result == totalReadLockCount); }
/** * Verify the waiters (for debugging) * * guarded.By {@link #suspendLock} */ private void checkWriteLockWaiters() { if (!DEBUG_SUSPEND_LOCK) { return; } Assert.assertHoldsLock(this.suspendLock, true); int result = 0; Iterator it = this.suspendQueue.iterator(); while (it.hasNext()) { DLockRequestMessage r = (DLockRequestMessage) it.next(); if (r.isSuspendLockingRequest()) { result++; } } // while Assert.assertTrue(result == this.writeLockWaiters); }
/** exchange profiles to initialize this advisor */ public void exchangeProfiles() { Assert.assertHoldsLock(this, false); // causes deadlock Assert.assertHoldsLock(this.initializeLock, true); new UpdateAttributesProcessor(getAdvisee()).distribute(true); setInitialized(); }
boolean isCurrentlyOrIsMakingLockGrantor() { Assert.assertHoldsLock(this.destroyLock, false); synchronized (this.lockGrantorIdLock) { return this.lockGrantorId != null && this.lockGrantorId.isLocal(getSerialNumber()); } }
boolean isMakingLockGrantor() { Assert.assertHoldsLock(this.destroyLock, false); synchronized (this.lockGrantorIdLock) { return this.lockGrantorId != null && this.lockGrantorId.isLocal(getSerialNumber()) && this.grantor != null && this.grantor.isInitializing(); } }
protected int indexOfMemberId(ProfileId id) { Assert.assertHoldsLock(this, true); Profile[] profs = this.profiles; // volatile read for (int i = 0; i < profs.length; i++) { Profile p = profs[i]; if (id instanceof InternalDistributedMember) { if (p.getDistributedMember().equals(id)) return i; } else { if (p.getId().equals(id)) return i; } } return -1; }
boolean isCurrentlyLockGrantor() { Assert.assertHoldsLock(this.destroyLock, false); synchronized (this.lockGrantorIdLock) { return this.lockGrantorId != null && this.lockGrantorId.isLocal(getSerialNumber()) && this.grantor != null && this.grantor.isReady(); } }
/** * Factory method for creating a new instance of <code>DLockService</code>. This ensures that * adding the {@link #disconnectListener} is done while synchronized on the fully constructed * instance. * <p> * Caller must be synchronized on {@link DLockService#services}. * * @see org.apache.geode.distributed.DistributedLockService#create(String, DistributedSystem) */ static DLockService basicCreate(String serviceName, InternalDistributedSystem ds, boolean isDistributed, boolean destroyOnDisconnect, boolean automateFreeResources) throws IllegalArgumentException { Assert.assertHoldsLock(services, true); if (logger.isTraceEnabled(LogMarker.DLS_VERBOSE)) { logger.trace(LogMarker.DLS_VERBOSE, "About to create DistributedLockService <{}>", serviceName); } DLockService svc = new DLockService(serviceName, ds, isDistributed, destroyOnDisconnect, automateFreeResources); svc.init(); return svc; }
/** * Early check for resources. This code may be executed for every put operation if there are no * datastores present, limit excessive logging. * * @since GemFire 5.8 */ private void earlySufficientStoresCheck(String partitionName) { assert Assert.assertHoldsLock(this, false); Set currentStores = getAllStores(partitionName); if (currentStores.isEmpty()) { if (shouldLogInsufficientStores()) { insufficientStores(currentStores, Collections.EMPTY_LIST, true); } insufficientStores(currentStores, Collections.EMPTY_LIST, false); } }
/** * Suspends locking by the remote thread and lease id. * <p> * Caller must synchronize on suspendLock. * * Concurrency: protected by synchronization of {@link #suspendLock} * * @param myRThread the remote thread that is about to suspend locking * @param lockId the id of the lock request used to suspend locking */ protected void suspendLocking(final RemoteThread myRThread, final int lockId) { if (DEBUG_SUSPEND_LOCK) { Assert.assertHoldsLock(this.suspendLock, true); } if (logger.isTraceEnabled(LogMarker.DLS_VERBOSE)) { logger.trace(LogMarker.DLS_VERBOSE, "Suspend locking of {} by {} with lockId of {}", this.dlock, myRThread, lockId); } Assert.assertTrue(myRThread != null, "Attempted to suspend locking for null RemoteThread"); Assert.assertTrue(this.lockingSuspendedBy == null || this.lockingSuspendedBy.equals(myRThread), "Attempted to suspend locking for " + myRThread + " but locking is already suspended by " + this.lockingSuspendedBy); this.suspendedLockId = lockId; this.lockingSuspendedBy = myRThread; }
/** * Callback for IndexManager to update indexes Called from AbstractRegionMap. * * @param entry the RegionEntry being updated * @param action action to be taken (IndexManager.ADD_ENTRY, IndexManager.UPDATE_ENTRY, * IndexManager.REMOVE_ENTRY) * @param opCode one of IndexProtocol.OTHER_OP, BEFORE_UPDATE_OP, AFTER_UPDATE_OP. */ public void updateIndexes(RegionEntry entry, int action, int opCode, boolean isDiskRecoveryInProgress) throws QueryException { if (isDiskRecoveryInProgress) { assert !((LocalRegion) this.region).isInitialized(); } else { assert Assert.assertHoldsLock(entry, true); } if (logger.isDebugEnabled()) { logger.debug("IndexManager.updateIndexes {} + action: {}", entry.getKey(), action); } if (entry == null) return; if (isIndexMaintenanceTypeSynchronous()) { // System.out.println("Synchronous update"); processAction(entry, action, opCode); } else { // System.out.println("Aynchronous update"); updater.addTask(action, entry, opCode); } }
/** * Set {@link #lockGrantorId} to the <code>localLockGrantorId</code> if current value is null or * is an older grantor version. This also atomically sets {@link #grantor} to ensure that the two * fields are kept in sync. Caller must hold {@link #lockGrantorIdLock}. * * @param localLockGrantorId the new value for lockGrantorId * @param localGrantor the new local intance of DLockGrantor */ private boolean setLockGrantorId(LockGrantorId localLockGrantorId, DLockGrantor localGrantor) { Assert.assertHoldsLock(this.lockGrantorIdLock, true); Assert.assertTrue(localLockGrantorId.isLocal(getSerialNumber())); if (setLockGrantorId(localLockGrantorId)) { this.grantor = localGrantor; return true; } return false; }
/** * Set {@link #lockGrantorId} to the given new value if the current value is null or is an older * grantor version. Caller must hold {@link #lockGrantorIdLock}. * * @param newLockGrantorId the new value for lockGrantorId */ private boolean setLockGrantorId(LockGrantorId newLockGrantorId) { Assert.assertHoldsLock(this.lockGrantorIdLock, true); if (equalsLockGrantorId(newLockGrantorId)) { return true; } else if (!newLockGrantorId.hasLockGrantorVersion()) { // proceed with temporary placeholder used by become grantor this.lockGrantorId = newLockGrantorId; return true; } else if (newLockGrantorId.isRemote() && this.lockGrantorId != null && this.lockGrantorId.hasLockGrantorVersion()) { if (logger.isTraceEnabled(LogMarker.DLS_VERBOSE)) { logger.trace(LogMarker.DLS_VERBOSE, "[setLockGrantorId] tried to replace {} with {}", this.lockGrantorId, newLockGrantorId); } return false; } else if (newLockGrantorId.isNewerThan(this.lockGrantorId)) { this.lockGrantorId = newLockGrantorId; return true; } else { return false; } }