use of org.apache.geode.distributed.internal.DistributionAdvisor in project geode by apache.
the class DistributedAckRegionCCEDUnitTest method testConcurrentOpWithGII.
/**
* test for bug #45564. a create() is received by region creator and then a later destroy() is
* received in initial image and while the version info from the destroy is recorded we keep the
* value from the create event
*/
@Test
public void testConcurrentOpWithGII() {
if (this.getClass() != DistributedAckRegionCCEDUnitTest.class) {
// not really a scope-related thing
return;
}
final String name = this.getUniqueName() + "-CC";
final String key = "mykey";
VM vm1 = Host.getHost(0).getVM(1);
VM vm2 = Host.getHost(0).getVM(2);
// create some destroyed entries so the GC service is populated
SerializableCallable create = new SerializableCallable("create region") {
public Object call() {
RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
CCRegion = (LocalRegion) f.create(name);
return CCRegion.getDistributionManager().getDistributionManagerId();
}
};
// do conflicting update() and destroy() on the region. We want the update() to
// be sent with a message and the destroy() to be transferred in the initial image
// and be the value that we want to keep
InternalDistributedMember vm1ID = (InternalDistributedMember) vm1.invoke(create);
AsyncInvocation partialCreate = vm2.invokeAsync(new SerializableCallable("create region with stall") {
public Object call() throws Exception {
final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
RegionFactory f = cache.createRegionFactory(getRegionAttributes());
InitialImageOperation.VMOTION_DURING_GII = true;
// this will stall region creation at the point of asking for an initial image
VMotionObserverHolder.setInstance(new VMotionObserver() {
@Override
public void vMotionBeforeCQRegistration() {
}
@Override
public void vMotionBeforeRegisterInterest() {
}
@Override
public void vMotionDuringGII(Set recipientSet, LocalRegion region) {
InitialImageOperation.VMOTION_DURING_GII = false;
int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
LocalRegion ccregion = cache.getRegionByPath("/" + name);
try {
// happen
while (!ccregion.isDestroyed() && ccregion.getRegionEntry(key) == null) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
return;
}
}
} finally {
LocalRegion.setThreadInitLevelRequirement(oldLevel);
}
}
});
try {
CCRegion = (LocalRegion) f.create(name);
// at this point we should have received the update op and then the GII, which should
// overwrite
// the conflicting update op
assertFalse("expected initial image transfer to destroy entry", CCRegion.containsKey(key));
} finally {
InitialImageOperation.VMOTION_DURING_GII = false;
}
return null;
}
});
vm1.invoke(new SerializableRunnable("create conflicting events") {
public void run() {
// wait for the other to come on line
long waitEnd = System.currentTimeMillis() + 45000;
DistributionAdvisor adv = ((DistributedRegion) CCRegion).getCacheDistributionAdvisor();
while (System.currentTimeMillis() < waitEnd && adv.adviseGeneric().isEmpty()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
return;
}
}
if (adv.adviseGeneric().isEmpty()) {
fail("other member never came on line");
}
// inhibit all messaging
DistributedCacheOperation.LOSS_SIMULATION_RATIO = 200.0;
try {
CCRegion.put("mykey", "initialValue");
CCRegion.destroy("mykey");
} finally {
DistributedCacheOperation.LOSS_SIMULATION_RATIO = 0.0;
}
// generate a fake version tag for the message
VersionTag tag = CCRegion.getRegionEntry(key).getVersionStamp().asVersionTag();
// create a fake member ID that will be < mine and lose a concurrency check
NetMember nm = CCRegion.getDistributionManager().getDistributionManagerId().getNetMember();
InternalDistributedMember mbr = null;
try {
mbr = new InternalDistributedMember(nm.getInetAddress().getCanonicalHostName(), nm.getPort() - 1, "fake_id", "fake_id_ustring", DistributionManager.NORMAL_DM_TYPE, null, null);
tag.setMemberID(mbr);
} catch (UnknownHostException e) {
org.apache.geode.test.dunit.Assert.fail("could not create member id", e);
}
// generate an event to distribute that contains the fake version tag
EntryEventImpl event = EntryEventImpl.create(CCRegion, Operation.UPDATE, key, false, mbr, true, false);
event.setNewValue("newValue");
event.setVersionTag(tag);
// this should update the controller's cache with the updated value but leave this cache
// alone
DistributedCacheOperation op = new UpdateOperation(event, tag.getVersionTimeStamp());
op.distribute();
event.release();
}
});
try {
partialCreate.getResult();
} catch (Throwable e) {
org.apache.geode.test.dunit.Assert.fail("async invocation in vm2 failed", e);
}
}
use of org.apache.geode.distributed.internal.DistributionAdvisor in project geode by apache.
the class CreateRegionProcessor method getAdvice.
private Set getAdvice() {
if (this.newRegion instanceof BucketRegion) {
return ((Bucket) this.newRegion).getBucketAdvisor().adviseProfileExchange();
} else {
DistributionAdvisee rgn = this.newRegion.getParentAdvisee();
DistributionAdvisor advisor = rgn.getDistributionAdvisor();
return advisor.adviseGeneric();
}
}
use of org.apache.geode.distributed.internal.DistributionAdvisor in project geode by apache.
the class UpdateAttributesProcessor method sendProfileUpdate.
public void sendProfileUpdate(boolean exchangeProfiles) {
DM mgr = this.advisee.getDistributionManager();
DistributionAdvisor advisor = this.advisee.getDistributionAdvisor();
this.profileExchange = exchangeProfiles;
if (!exchangeProfiles) {
if (this.removeProfile) {
if (!advisor.isInitialized()) {
// never got initialized.
return;
}
} else if (advisor.initializationGate()) {
// it just did the profile exchange so we are done
return;
}
}
final Set recipients;
if (this.removeProfile) {
recipients = advisor.adviseProfileRemove();
} else if (exchangeProfiles) {
recipients = advisor.adviseProfileExchange();
} else {
recipients = advisor.adviseProfileUpdate();
}
if (recipients.isEmpty()) {
return;
}
ReplyProcessor21 processor = null;
// Scope scope = this.region.scope;
// always require an ack to prevent misordering of messages
InternalDistributedSystem system = this.advisee.getSystem();
processor = new UpdateAttributesReplyProcessor(system, recipients);
UpdateAttributesMessage message = getUpdateAttributesMessage(processor, recipients);
mgr.putOutgoing(message);
this.processor = processor;
}
Aggregations