/** * repopulates the RegionAdvisor's location information for this bucket */ private void updateServerBucketProfile() { int bucketId = this.getBucket().getId(); Set<ServerBucketProfile> serverProfiles = newSetFromMap(new HashMap<ServerBucketProfile, Boolean>()); for (Profile p : this.profiles) { if (p instanceof ServerBucketProfile) { serverProfiles.add((ServerBucketProfile) p); } } this.regionAdvisor.setClientBucketProfiles(bucketId, serverProfiles); }
final InternalCache cache = getBucket().getCache(); if (cache != null && cache.isCacheAtShutdownAll()) { throw cache.getCacheClosedException("Cache is shutting down");
/** * Called by the RegionAdvisor.profileRemoved, this method tests to see if the missing member is * the primary elector for this bucket. * * We can't call this method from BucketAdvisor.profileRemoved, because the primaryElector may not * actually host the bucket. * */ public void checkForLostPrimaryElector(Profile profile) { // If the member that went away was in the middle of creating // the bucket, finish the bucket creation. ProfileId elector = this.primaryElector; if (elector != null && elector.equals(profile.getDistributedMember())) { if (logger.isDebugEnabled()) { logger.debug( "Bucket {} lost the member responsible for electing the primary. Finishing bucket creation", getBucket().getFullPath()); } this.primaryElector = getBucket().getDistributionManager().getId(); this.getBucket().getDistributionManager().getWaitingThreadPool().execute(new Runnable() { @Override public void run() { getBucket().getPartitionedRegion().getRedundancyProvider() .finishIncompleteBucketCreation(getBucket().getId()); } }); } }
/** * Concurrency: protected by synchronizing on *this* */ @Override protected void profileUpdated(Profile profile) { super.profileUpdated(profile); if (updateRedundancy() > 0) { // wake up any threads in waitForRedundancy or waitForPrimary this.notifyAll(); } this.regionAdvisor.updateBucketStatus(this.getBucket().getId(), profile.peerMemberId, false); if (logger.isDebugEnabled()) { logger.debug("Profile updated {} Profile : {}", getBucket().getFullPath(), profile); } synchronized (this) { updateServerBucketProfile(); } }
private void invokeAfterSecondaryInPartitionListeners() { PartitionListener[] listeners = this.pRegion.getPartitionListeners(); if (listeners == null || listeners.length == 0) { return; } for (int i = 0; i < listeners.length; i++) { PartitionListener listener = listeners[i]; if (listener != null) { listener.afterSecondary(getBucket().getId()); } } }
private void invokePartitionListeners() { PartitionListener[] listeners = this.pRegion.getPartitionListeners(); if (listeners == null || listeners.length == 0) { return; } for (int i = 0; i < listeners.length; i++) { PartitionListener listener = listeners[i]; if (listener != null) { listener.afterPrimary(getBucket().getId()); } } }
/** * Concurrency: protected by synchronizing on *this* */ @Override protected void profileCreated(Profile profile) { this.regionAdvisor.incrementBucketCount(profile); super.profileCreated(profile); if (updateRedundancy() > 0) { // wake up any threads in waitForRedundancy or waitForPrimary this.notifyAll(); } this.regionAdvisor.updateBucketStatus(this.getBucket().getId(), profile.peerMemberId, false); if (logger.isDebugEnabled()) { logger.debug("Profile added {} Profile : {}", getBucket().getFullPath(), profile); } synchronized (this) { updateServerBucketProfile(); } }
@Override protected Profile instantiateProfile(InternalDistributedMember memberId, int version) { if (!this.pRegion.isShadowPR()) { InternalCache cache = getProxyBucketRegion().getCache(); List servers = null; servers = cache.getCacheServers(); HashSet<BucketServerLocation66> serverLocations = new HashSet<BucketServerLocation66>(); for (Object object : servers) { CacheServerImpl server = (CacheServerImpl) object; if (server.isRunning() && (server.getExternalAddress() != null)) { BucketServerLocation66 location = new BucketServerLocation66(getBucket().getId(), server.getPort(), server.getExternalAddress() /* .getExternalAddress(false/ checkServerRunning ) */, getBucket().isPrimary(), Integer.valueOf(version).byteValue(), server.getCombinedGroups()); serverLocations.add(location); } } if (serverLocations.size() > 0) { return new ServerBucketProfile(memberId, version, getBucket(), serverLocations); } } return new BucketProfile(memberId, version, getBucket()); }
/** * Concurrency: protected by synchronizing on *this* */ @Override protected void profileRemoved(Profile profile) { if (profile != null) { this.regionAdvisor.updateBucketStatus(this.getBucket().getId(), profile.getDistributedMember(), true); this.regionAdvisor.decrementsBucketCount(profile); } updateRedundancy(); if (logger.isDebugEnabled()) { logger.debug("Profile removed {} the member lost {} Profile : {}", getBucket().getFullPath(), profile.getDistributedMember(), profile); } synchronized (this) { updateServerBucketProfile(); } }
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; } }
DeposePrimaryBucketMessage.send(otherPrimary, this.pRegion, getBucket().getId()); if (response != null) { response.waitForRepliesUninterruptibly();
private void assignStartingBucketAdvisorIfFixedPartitioned() { if (startingBucketAdvisor != null) { // already assigned return; } if (this.pRegion.isFixedPartitionedRegion()) { List<FixedPartitionAttributesImpl> fpas = this.pRegion.getFixedPartitionAttributesImpl(); if (fpas != null) { int bucketId = getBucket().getId(); for (FixedPartitionAttributesImpl fpa : fpas) { if (fpa.hasBucket(bucketId) && bucketId != fpa.getStartingBucketID()) { startingBucketAdvisor = this.regionAdvisor.getBucketAdvisor(fpa.getStartingBucketID()); break; } } } } }
protected void acquirePrimaryForRestOfTheBucket() { List<FixedPartitionAttributesImpl> fpas = this.pRegion.getFixedPartitionAttributesImpl(); if (fpas != null) { int bucketId = getBucket().getId(); for (FixedPartitionAttributesImpl fpa : fpas) { if (fpa.getStartingBucketID() == bucketId) { for (int i = bucketId + 1; i <= fpa.getLastBucketID();) { Bucket b = regionAdvisor.getBucket(i++); if (b != null) { BucketAdvisor ba = b.getBucketAdvisor(); ba.primaryMoveWriteLock.lock(); try { if (ba.isHosting()) { if (!ba.isPrimary()) { ba.setVolunteering(); ba.acquiredPrimaryLock(); } } } finally { ba.primaryMoveWriteLock.unlock(); } } } } else { continue; } } } }
if (colocatedWithList != null) { for (PartitionedRegion childPR : colocatedWithList) { Bucket b = childPR.getRegionAdvisor().getBucket(getBucket().getId()); BucketAdvisor childBA = b.getBucketAdvisor(); Assert.assertHoldsLock(childBA, false); logger.debug( "BucketAdvisor.acquirePrimaryRecursivelyForColocated: about to take lock for bucket: {} of PR: {} with isHosting={}", getBucket().getId(), childPR.getFullPath(), childBA.isHosting());
logger.debug("Acquired primary lock for BucketID {} PR : {}", getBucket().getId(), regionAdvisor.getPartitionedRegion().getFullPath()); synchronized (this) { if (isHosting() && (isVolunteering() || isBecomingPrimary())) { Bucket br = this.regionAdvisor.getBucket(getBucket().getId()); if (br != null && br instanceof BucketRegion) { ((BucketRegion) br).beforeAcquiringPrimaryState(); if (logger.isDebugEnabled()) { logger.debug("Acquired primary lock for setting primary now BucketID {} PR : {}", getBucket().getId(), regionAdvisor.getPartitionedRegion().getFullPath()); Bucket br = this.regionAdvisor.getBucket(getBucket().getId()); if (br != null && br instanceof BucketRegion) { ((BucketRegion) br).processPendingSecondaryExpires();
private boolean deposeOtherPrimaryBucketForFixedPartition() { boolean deposedOtherPrimaries = true; int bucketId = getBucket().getId(); List<FixedPartitionAttributesImpl> fpas = this.pRegion.getFixedPartitionAttributesImpl(); if (fpas != null) { for (FixedPartitionAttributesImpl fpa : fpas) { if (fpa.getStartingBucketID() == bucketId) { for (int i = (bucketId + 1); i <= fpa.getLastBucketID(); i++) { Bucket b = regionAdvisor.getBucket(i); if (b != null) { BucketAdvisor ba = b.getBucketAdvisor(); deposedOtherPrimaries = ba.deposePrimary() && deposedOtherPrimaries; } } } else { continue; } } } return deposedOtherPrimaries; }
if (this.pRegion.isFixedPartitionedRegion()) { InternalDistributedMember primaryMember = this.regionAdvisor.adviseFixedPrimaryPartitionDataStore(this.getBucket().getId()); if (primaryMember == null || primaryMember.equals(member)) { needToVolunteerForPrimary = true; if (lostPrimary) { invokeAfterSecondaryInPartitionListeners(); Bucket br = this.regionAdvisor.getBucket(getBucket().getId()); if (br != null && br instanceof BucketRegion) { ((BucketRegion) br).beforeReleasingPrimaryLockDuringDemotion();
if (colocatedChildPRs != null) { for (PartitionedRegion pr : colocatedChildPRs) { Bucket b = pr.getRegionAdvisor().getBucket(getBucket().getId()); if (b != null) { BucketAdvisor ba = b.getBucketAdvisor();