use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class BecomePrimaryBucketMessage method operateOnPartitionedRegion.
@Override
protected 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;
}
use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class DeposePrimaryBucketMessage method operateOnPartitionedRegion.
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion region, long startTime) throws ForceReattemptException {
BucketAdvisor bucketAdvisor = region.getRegionAdvisor().getBucketAdvisor(this.bucketId);
bucketAdvisor.deposePrimary();
region.getPrStats().endPartitionMessagesProcessing(startTime);
DeposePrimaryBucketReplyMessage.send(getSender(), getProcessorId(), dm, (ReplyException) null);
return false;
}
use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class AcceptorImpl method notifyCacheMembersOfClose.
private void notifyCacheMembersOfClose() {
if (!this.cache.forcedDisconnect()) {
for (PartitionedRegion pr : this.cache.getPartitionedRegions()) {
Map<Integer, BucketAdvisor.BucketProfile> profiles = new HashMap<>();
// get all local real bucket advisors
Map<Integer, BucketAdvisor> advisors = pr.getRegionAdvisor().getAllBucketAdvisors();
for (Map.Entry<Integer, BucketAdvisor> entry : advisors.entrySet()) {
BucketAdvisor advisor = entry.getValue();
BucketProfile bp = (BucketProfile) advisor.createProfile();
advisor.updateServerBucketProfile(bp);
profiles.put(entry.getKey(), bp);
}
Set recipients = pr.getRegionAdvisor().adviseAllPRNodes();
// send it to all in one message
ReplyProcessor21 reply = AllBucketProfilesUpdateMessage.send(recipients, pr.getDistributionManager(), pr.getPRId(), profiles, true);
if (reply != null) {
reply.waitForRepliesUninterruptibly();
}
if (logger.isDebugEnabled()) {
logger.debug("sending messages to all peers for removing this server..");
}
}
}
}
use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class SizedBasedLoadProbe method getLoad.
public PRLoad getLoad(PartitionedRegion pr) {
PartitionedRegionDataStore ds = pr.getDataStore();
int configuredBucketCount = pr.getTotalNumberOfBuckets();
PRLoad prLoad = new PRLoad(configuredBucketCount, pr.getLocalMaxMemory());
// key: bid, value: size
for (Integer bidInt : ds.getAllLocalBucketIds()) {
int bid = bidInt.intValue();
long bucketSize = ds.getBucketSize(bid);
if (bucketSize < MIN_BUCKET_SIZE) {
bucketSize = MIN_BUCKET_SIZE;
}
BucketAdvisor bucketAdvisor = pr.getRegionAdvisor().getBucket(bid).getBucketAdvisor();
// Wait for a primary to exist for this bucket, because
// it might be this member.
bucketAdvisor.getPrimary();
boolean isPrimary = pr.getRegionAdvisor().getBucket(bid).getBucketAdvisor().isPrimary();
prLoad.addBucket(bid, bucketSize, isPrimary ? 1 : 0);
}
return prLoad;
}
use of org.apache.geode.internal.cache.BucketAdvisor in project geode by apache.
the class ResourceManagerDUnitTest method testBecomePrimaryBucketMessage.
@Test
public void testBecomePrimaryBucketMessage() {
final String[] regionPath = new String[] { getUniqueName() + "-PR-0" };
final int[] numBuckets = new int[] { 1 };
final int[] redundantCopies = new int[] { 1 };
// localMaxMemory config to use for two members
final int[] localMaxMemory = new int[] { 100, 100, 0 };
// bucketKeys to use for making one bucket
final Integer[] bucketKeys = new Integer[] { Integer.valueOf(0) };
createRegion(Host.getHost(0).getVM(0), regionPath[0], localMaxMemory[0], numBuckets[0], redundantCopies[0]);
createRegion(Host.getHost(0).getVM(1), regionPath[0], localMaxMemory[1], numBuckets[0], redundantCopies[0]);
createRegion(Host.getHost(0).getVM(2), regionPath[0], localMaxMemory[2], numBuckets[0], redundantCopies[0]);
// 2 MB in size
final byte[] value = new byte[1];
createBucket(0, regionPath[0], bucketKeys[0], value);
// identify the members and their config values
final InternalDistributedMember[] members = new InternalDistributedMember[2];
final long[] memberSizes = new long[members.length];
final int[] memberBucketCounts = new int[members.length];
final int[] memberPrimaryCounts = new int[members.length];
fillValidationArrays(members, memberSizes, memberBucketCounts, memberPrimaryCounts, regionPath[0]);
int primaryVM = -1;
int otherVM = -1;
for (int i = 0; i < memberPrimaryCounts.length; i++) {
if (memberPrimaryCounts[i] == 0) {
otherVM = i;
} else if (memberPrimaryCounts[i] == 1) {
// found the primary
primaryVM = i;
}
}
assertTrue(primaryVM > -1);
assertTrue(otherVM > -1);
assertTrue(primaryVM != otherVM);
int accessorVM = 2;
assertTrue(accessorVM != primaryVM && accessorVM != otherVM);
final int finalOtherVM = otherVM;
boolean becamePrimary = ((Boolean) Host.getHost(0).getVM(accessorVM).invoke(new SerializableCallable() {
public Object call() {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
BecomePrimaryBucketResponse response = BecomePrimaryBucketMessage.send(members[finalOtherVM], pr, 0, false);
if (response != null) {
return Boolean.valueOf(response.waitForResponse());
} else {
return Boolean.FALSE;
}
}
})).booleanValue();
assertTrue(becamePrimary);
// do a put from all three members to ensure primary is identified
for (int i = 0; i < localMaxMemory.length; i++) {
final int vm = i;
performPuts(vm, regionPath[0], bucketKeys, value);
}
// use BucketAdvisor on all three members to assert that otherVM is now the primary
for (int i = 0; i < localMaxMemory.length; i++) {
final int vm = i;
Host.getHost(0).getVM(vm).invoke(new SerializableRunnable() {
public void run() {
PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(regionPath[0]);
BucketAdvisor advisor = pr.getRegionAdvisor().getBucketAdvisor(0);
assertEquals(members[finalOtherVM], advisor.getPrimary());
}
});
}
}
Aggregations