public boolean isHosting() { return this.advisor.isHosting(); }
public boolean isHosting() { return this.advisor.isHosting(); }
/** * Returns the real BucketRegion that is currently being locally hosted. * Returns null if the real bucket is null or if it is still being * initialized. After the bucket is intialized isHosting will be flagged * true and future calls to this method will return the bucket. * * @return the real bucket if currently hosted or null */ public BucketRegion getHostedBucketRegion() { if (this.advisor.isHosting()) { return this.realBucket; } else { return null; } }
/** * Returns the real BucketRegion that is currently being locally hosted. * Returns null if the real bucket is null or if it is still being * initialized. After the bucket is intialized isHosting will be flagged * true and future calls to this method will return the bucket. * * @return the real bucket if currently hosted or null */ public BucketRegion getHostedBucketRegion() { if (this.advisor.isHosting()) { return this.realBucket; } else { return null; } }
/** * Get the number of members that are hosting the bucket, and have * finished initialization. * * This method is currently only used to check the bucket * redundancy just before creating the bucket. If it is used * more frequently, it might be better to cache this count. */ private int getNumInitializedBuckets() { Profile[] locProfiles = this.profiles; // grab current profiles int count = 0; for(Profile profile: locProfiles) { BucketProfile bucketProfile = (BucketProfile) profile; if(bucketProfile.isHosting) { count++; } } if(isHosting()) { count++; } return count; }
/** * Get the number of members that are hosting the bucket, and have * finished initialization. * * This method is currently only used to check the bucket * redundancy just before creating the bucket. If it is used * more frequently, it might be better to cache this count. */ private int getNumInitializedBuckets() { Profile[] locProfiles = this.profiles; // grab current profiles int count = 0; for(Profile profile: locProfiles) { BucketProfile bucketProfile = (BucketProfile) profile; if(bucketProfile.isHosting) { count++; } } if(isHosting()) { count++; } return count; }
public boolean isHosting() { return getBucketAdvisor().isHosting(); }
public final boolean isHosting() { return getBucketAdvisor().isHosting(); }
public boolean areAllBucketsHosted(final Set<Integer> bucketSet) { // boolean arr[] = new boolean[]{false, true, false, true , false , false , false , false }; // Random random = new Random(); // int num = random.nextInt(7); // System.out.println("PRDS.verifyBuckets returning " + arr[num]); // return arr[num]; for (Integer bucket : bucketSet) { if (!this.partitionedRegion.getRegionAdvisor().getBucketAdvisor(bucket) .isHosting()) { return false; } } return true; }
/** * Returns true if there exists a member with uninitialized bucket i.e. in the * process of creation and GII (including self). */ public boolean hasUninitialized() { final Profile[] locProfiles = this.profiles; // grab current profiles for (Profile profile : locProfiles) { BucketProfile bucketProfile = (BucketProfile)profile; if (!bucketProfile.isHosting) { return true; } } if (!isHosting() && getProxyBucketRegion() .getCreatedBucketRegion() != null) { return true; } return false; }
/** * Sets primaryMember and notifies all. Caller must be synced on this. * * @param id the member to use as primary for this bucket */ void setPrimaryMember(InternalDistributedMember id) { if (!getDistributionManager().getId().equals(id)) { // volunteerForPrimary handles primary state change if its our id if (isHosting()) { requestPrimaryState(OTHER_PRIMARY_HOSTING); } else { requestPrimaryState(OTHER_PRIMARY_NOT_HOSTING); } } this.primaryMember.set(id); this.everHadPrimary = true; if(id != null && id.equals(primaryElector)) { primaryElector = null; } this.notifyAll(); // wake up any threads in waitForPrimaryMember }
/** * Sets primaryMember and notifies all. Caller must be synced on this. * * @param id the member to use as primary for this bucket */ void setPrimaryMember(InternalDistributedMember id) { if (!getDistributionManager().getId().equals(id)) { // volunteerForPrimary handles primary state change if its our id if (isHosting()) { requestPrimaryState(OTHER_PRIMARY_HOSTING); } else { requestPrimaryState(OTHER_PRIMARY_NOT_HOSTING); } } this.primaryMember.set(id); this.everHadPrimary = true; if(id != null && id.equals(primaryElector)) { primaryElector = null; } this.notifyAll(); // wake up any threads in waitForPrimaryMember }
/** * Notify this proxy of the real bucket as its target. Future calls to this instance will then proxy * them back to the real bucket. * @param br the real bucket which will be the target for this proxy */ public void setBucketRegion(BucketRegion br) { Assert.assertTrue(this.realBucket == null); Assert.assertTrue( ! this.advisor.isHosting()); this.realBucket = br; // fix several bugs including 36881... creation of BR may be occurring // at same time another thread is destroying the PR and now that this // BR is visible to the destroy thread we want to prevent sending bogus // CreateRegion or profile update messages this.partitionedRegion.checkReadiness(); this.partitionedRegion.checkClosed(); }
/** * Notify this proxy of the real bucket as its target. Future calls to this instance will then proxy * them back to the real bucket. * @param br the real bucket which will be the target for this proxy */ public void setBucketRegion(BucketRegion br) { Assert.assertTrue(this.realBucket == null); Assert.assertTrue( ! this.advisor.isHosting()); this.realBucket = br; // fix several bugs including 36881... creation of BR may be occurring // at same time another thread is destroying the PR and now that this // BR is visible to the destroy thread we want to prevent sending bogus // CreateRegion or profile update messages this.partitionedRegion.checkReadiness(); this.partitionedRegion.checkClosed(); }
/** * Return (and possibly choose) a thread-sticky member from whose data store * this bucket's values should be read * @return member to use for reads, null if none available */ public InternalDistributedMember getPreferredNode() { if (isHosting()) { getPartitionedRegionStats().incPreferredReadLocal(); return getDistributionManager().getId(); } Profile locProfiles[] = this.profiles; // volatile read if (locProfiles.length == 0) { return null; } getPartitionedRegionStats().incPreferredReadRemote(); if (locProfiles.length == 1) { // only one choice! return locProfiles[0].peerMemberId; } // Pick one at random. int i = myRand.nextInt(locProfiles.length); return locProfiles[i].peerMemberId; }
public int areAllBucketsHosted(final Set<Integer> bucketSet, boolean optimizeForWrite) { // boolean arr[] = new boolean[]{false, true, false, true , false , false , false , false }; // Random random = new Random(); // int num = random.nextInt(7); // System.out.println("PRDS.verifyBuckets returning " + arr[num]); // return arr[num]; for (int bucket : bucketSet) { if (optimizeForWrite) { if (!this.partitionedRegion.getRegionAdvisor().getBucketAdvisor(bucket) .isPrimary()) { return bucket; } } else { if (!this.partitionedRegion.getRegionAdvisor().getBucketAdvisor(bucket) .isHosting()) { return bucket; } } } return -1; }
@Override protected final boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion region, long startTime) throws ForceReattemptException { // this is executing in the WAITING_POOL_EXECUTOR byte responseCode = BecomePrimaryBucketReplyMessage.NOT_SECONDARY; BucketAdvisor bucketAdvisor = region.getRegionAdvisor().getBucketAdvisor(this.bucketId); if (bucketAdvisor.isHosting()) { if (bucketAdvisor.becomePrimary(this.isRebalance)) { // sends a request/reply message responseCode = BecomePrimaryBucketReplyMessage.OK; } } region.getPrStats().endPartitionMessagesProcessing(startTime); BecomePrimaryBucketReplyMessage.send( getSender(), getProcessorId(), dm, null, responseCode); return false; }
@Override protected final boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion region, long startTime) throws ForceReattemptException { // this is executing in the WAITING_POOL_EXECUTOR byte responseCode = BecomePrimaryBucketReplyMessage.NOT_SECONDARY; BucketAdvisor bucketAdvisor = region.getRegionAdvisor().getBucketAdvisor(this.bucketId); if (bucketAdvisor.isHosting()) { if (bucketAdvisor.becomePrimary(this.isRebalance)) { // sends a request/reply message responseCode = BecomePrimaryBucketReplyMessage.OK; } } region.getPrStats().endPartitionMessagesProcessing(startTime); BecomePrimaryBucketReplyMessage.send( getSender(), getProcessorId(), dm, null, responseCode); return false; }
@Override public final void checkAllBucketsHosted() throws BucketMovedException { // check if bucket has moved if (this.pr != null) { final BucketAdvisor bucAdvisor = this.pr.getRegionAdvisor() .getBucketAdvisor(this.bucketId); if (optimizeForWrite()) { if (!bucAdvisor.isPrimary()) { this.pr.checkReadiness(); InternalDistributedMember primaryHolder = bucAdvisor .basicGetPrimaryMember(); throw new PrimaryBucketException("Bucket " + this.pr.getBucketName(this.bucketId) + " is not primary. Current primary holder is " + primaryHolder); } } else if (!bucAdvisor.isHosting()) { throw new BucketMovedException( LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE .toLocalizedString(), this.bucketId, this.pr.getFullPath()); } } }
@Override public final void checkAllBucketsHosted() throws BucketMovedException { // check if bucket has moved if (this.pr != null) { final BucketAdvisor bucAdvisor = this.pr.getRegionAdvisor() .getBucketAdvisor(this.bucketId); if (optimizeForWrite()) { if (!bucAdvisor.isPrimary()) { this.pr.checkReadiness(); InternalDistributedMember primaryHolder = bucAdvisor .basicGetPrimaryMember(); throw new PrimaryBucketException("Bucket " + this.pr.getBucketName(this.bucketId) + " is not primary. Current primary holder is " + primaryHolder); } } else if (!bucAdvisor.isHosting()) { throw new BucketMovedException( LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE .toLocalizedString(), this.bucketId, this.pr.getFullPath()); } } }