/** * Get the current number of bucket hosts and update the redundancy statistics for the region * * @return number of current bucket hosts */ private int updateRedundancy() { int numBucketHosts = getNumInitializedBuckets(); if (!isClosed()) { redundancyTracker.updateStatistics(numBucketHosts); } return numBucketHosts; }
/** * Called from catch blocks in {@link #doVolunteerForPrimary()}. Handles the exception properly * based on advisor settings and shutdown condition. * * @param e the RuntimeException that was caught while volunteering * @param loggit true if message should be logged if shutdown condition is not met */ private void handleException(Exception e, boolean loggit) { boolean safe = isClosed() || getAdvisee().getCancelCriterion().isCancelInProgress(); if (!safe) { if (ENFORCE_SAFE_CLOSE) { Assert.assertTrue(safe, "BucketAdvisor was not closed properly."); } else if (loggit) { logger.warn("BucketAdvisor was not closed properly.", e); } } }
if (isClosed()) { return false;
public boolean waitForStorage() { synchronized (this) { // let's park this thread and wait for storage! StopWatch timer = new StopWatch(true); try { for (;;) { if (this.regionAdvisor.isBucketLocal(getBucket().getId())) { return true; } getProxyBucketRegion().getPartitionedRegion().checkReadiness(); if (isClosed()) { return false; } long timeLeft = BUCKET_STORAGE_WAIT - timer.elapsedTimeMillis(); if (timeLeft <= 0) { return false; } if (logger.isDebugEnabled()) { logger.debug("Waiting for bucket storage" + this); } this.wait(timeLeft); // spurious wakeup ok } } catch (InterruptedException e) { // abort and return null Thread.currentThread().interrupt(); } return false; } }
private boolean continueVolunteering() { synchronized (BucketAdvisor.this) { // false if caller is not the volunteeringThread if (!Thread.currentThread().equals(this.volunteeringThread)) { return false; } if (!isVolunteering() && !isBecomingPrimary()) { return false; } // false if primaryMember is not null if (!isAggressive() && basicGetPrimaryMember() != null) { return false; } // false if this member is already primary if (isPrimary()) { return false; } // false if closed if (isClosed()) { return false; } // false if no longer hosting if (!isHosting()) { return false; } // must be true... need to continue volunteering return true; } }
/** * Actually close this advisor for real. Called by ProxyBucketRegion only. Calling this method * actually closes this advisor whereas {@link #close()} only sets hosting to false. */ protected void closeAdvisor() { boolean wasPrimary; synchronized (this) { if (isClosed()) { return; } wasPrimary = isPrimary(); super.close(); this.requestPrimaryState(CLOSED); this.redundancyTracker.closeBucket(); this.localProfile = null; } if (wasPrimary) { releasePrimaryLock(); } }
if (isClosed() || !isHosting()) { if (logger.isDebugEnabled()) { logger.debug("Breaking from becomePrimary loop because {} is closed or not hosting",
/** * Releases the primary lock for this bucket. */ protected void releasePrimaryLock() { // We don't have a lock if we have a parent advisor if (parentAdvisor != null) { return; } assignStartingBucketAdvisorIfFixedPartitioned(); if (startingBucketAdvisor != null) { return; } try { DistributedMemberLock thePrimaryLock = getPrimaryLock(false); if (thePrimaryLock != null) { thePrimaryLock.unlock(); } } catch (LockNotHeldException e) { Assert.assertTrue(!isHosting(), "Got LockNotHeldException for Bucket = " + this); } catch (LockServiceDestroyedException e) { Assert.assertTrue(isClosed(), "BucketAdvisor was not closed before destroying PR lock service"); } }
/** * Attempt to acquire lock for primary until a primary exists. Caller hands off responsibility to * an executor (waiting pool) and returns early. */ public void volunteerForPrimary() { InternalDistributedMember elector = primaryElector; if (elector != null && regionAdvisor.hasPartitionedRegion(elector)) { // another server will determine the primary node return; } primaryElector = null; initializationGate(); synchronized (this) { if (isVolunteering() || isClosed() || !isHosting()) { // only one thread should be attempting to volunteer at one time return; } if (this.volunteeringDelegate == null) { setVolunteeringDelegate(new VolunteeringDelegate()); } this.volunteeringDelegate.volunteerForPrimary(); } }
synchronized (this) { wasPrimary = isPrimary(); if (isClosed()) { return;