private void updateServerBucketProfile() { // check to see if it is clientBucketProfile add it to the RegionAdvisor // data structure which maintains the newly created clientBucketProfile // don't add more than once, but replace existing profile int bucketId = this.getBucket().getId(); Set<ServerBucketProfile> serverProfiles = this.regionAdvisor .getClientBucketProfiles(bucketId); if (serverProfiles == null) { serverProfiles = newSetFromMap(new ConcurrentHashMap<ServerBucketProfile, Boolean>()); this.regionAdvisor.setClientBucketProfiles(bucketId, serverProfiles); } serverProfiles.clear(); for (Profile p : this.profiles) { if (p instanceof ServerBucketProfile) { serverProfiles.add((ServerBucketProfile)p); } } }
private void updateServerBucketProfile() { // check to see if it is clientBucketProfile add it to the RegionAdvisor // data structure which maintains the newly created clientBucketProfile // don't add more than once, but replace existing profile int bucketId = this.getBucket().getId(); Set<ServerBucketProfile> serverProfiles = this.regionAdvisor .getClientBucketProfiles(bucketId); if (serverProfiles == null) { serverProfiles = newSetFromMap(new ConcurrentHashMap<ServerBucketProfile, Boolean>()); this.regionAdvisor.setClientBucketProfiles(bucketId, serverProfiles); } serverProfiles.clear(); for (Profile p : this.profiles) { if (p instanceof ServerBucketProfile) { serverProfiles.add((ServerBucketProfile)p); } } }
/** * @guarded.By 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(); } }
/** * 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. * @param profile */ public void checkForLostPrimaryElector(Profile profile) { //If the member that went away was in the middle of creating //the bucket, finish the bucket creation. if(this.primaryElector != null && this.primaryElector.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() { public void run() { getBucket().getPartitionedRegion().getRedundancyProvider().finishIncompleteBucketCreation(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()); } } }
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()); } } }
/** * @guarded.By 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(); } }
/** * @guarded.By 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(); } }
@Override protected Profile instantiateProfile(InternalDistributedMember memberId, int version) { if (!this.pRegion.isShadowPR()) { GemFireCacheImpl c = getProxyBucketRegion().getCache(); List servers = null; servers = c.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()); }
@Override protected Profile instantiateProfile(InternalDistributedMember memberId, int version) { if (!this.pRegion.isShadowPR()) { GemFireCacheImpl c = getProxyBucketRegion().getCache(); List servers = null; servers = c.getCacheServers(); HashSet<BucketServerLocation66> serverLocations = new HashSet<BucketServerLocation66>(); for (Object object : servers) { BridgeServerImpl server = (BridgeServerImpl)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()); }
/** * 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. * @param profile */ public void checkForLostPrimaryElector(Profile profile) { //If the member that went away was in the middle of creating //the bucket, finish the bucket creation. if(this.primaryElector != null && this.primaryElector.equals(profile.getDistributedMember())) { LogWriterI18n log = getLogWriter(); if(log.fineEnabled()) { log.fine("Bucket " + getBucket().getFullPath() + " lost the member responsible for electing the primary. Finishing bucket creation"); } this.primaryElector = getBucket().getDistributionManager().getId(); this.getBucket().getDistributionManager().getWaitingThreadPool().execute(new Runnable() { public void run() { getBucket().getPartitionedRegion().getRedundancyProvider().finishIncompleteBucketCreation(getBucket().getId()); } }); } }
/** * @guarded.By 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); LogWriterI18n log = getLogWriter(); if (log.fineEnabled()) { log.fine("Profile updated " + getBucket().getFullPath() + " Profile : " + profile); } synchronized (this) { updateServerBucketProfile(); } }
/** * @guarded.By 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); LogWriterI18n log = getLogWriter(); if (log.fineEnabled()) { log.fine("Profile added " + getBucket().getFullPath() + " Profile : " + profile); } synchronized (this){ updateServerBucketProfile(); } }
/** * @guarded.By this */ @Override protected void profileRemoved(Profile profile) { if (profile != null) { this.regionAdvisor.updateBucketStatus(this.getBucket().getId(), profile.getDistributedMember(), true); this.regionAdvisor.decrementsBucketCount(profile); } updateRedundancy(); LogWriterI18n log = getLogWriter(); if (log.fineEnabled()) { log.fine("Profile removed " + getBucket().getFullPath() + " the member lost " + profile.getDistributedMember() + " Profile : " + profile); } synchronized (this) { updateServerBucketProfile(); } }
private void assignStartingBucketAdvisor() { 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; } } } } }
private void assignStartingBucketAdvisor() { 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; } } } } }
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; }
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; }
/** * 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() { if (primaryElector != null) { return; } initializationGate(); synchronized (this) { if (isVolunteering() || isClosed() || !isHosting()) { // only one thread should be attempting to volunteer at one time return; } // if member is still not initialized then don't volunteer for primary final GemFireCacheImpl cache = (GemFireCacheImpl)getBucket().getCache(); if (!cache.doVolunteerForPrimary(this)) { return; } if (this.volunteeringDelegate == null) { this.volunteeringDelegate = new VolunteeringDelegate(); } this.volunteeringDelegate.volunteerForPrimary(); } }
/** * 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() { if (primaryElector != null) { return; } initializationGate(); synchronized (this) { if (isVolunteering() || isClosed() || !isHosting()) { // only one thread should be attempting to volunteer at one time return; } // if member is still not initialized then don't volunteer for primary final GemFireCacheImpl cache = (GemFireCacheImpl)getBucket().getCache(); if (!cache.doVolunteerForPrimary(this)) { return; } if (this.volunteeringDelegate == null) { this.volunteeringDelegate = new VolunteeringDelegate(); } this.volunteeringDelegate.volunteerForPrimary(); } }