use of org.apache.geode.internal.cache.vmotion.VMotionObserver in project geode by apache.
the class ExecuteCQ61 method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
AcceptorImpl acceptor = serverConnection.getAcceptor();
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
ClientProxyMembershipID id = serverConnection.getProxyID();
CacheServerStats stats = serverConnection.getCacheServerStats();
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
// Retrieve the data from the message parts
String cqName = clientMessage.getPart(0).getString();
String cqQueryString = clientMessage.getPart(1).getString();
int cqState = clientMessage.getPart(2).getInt();
Part isDurablePart = clientMessage.getPart(3);
byte[] isDurableByte = isDurablePart.getSerializedForm();
boolean isDurable = (isDurableByte == null || isDurableByte[0] == 0) ? false : true;
// region data policy
Part regionDataPolicyPart = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
byte[] regionDataPolicyPartBytes = regionDataPolicyPart.getSerializedForm();
if (logger.isDebugEnabled()) {
logger.debug("{}: Received {} request from {} CqName: {} queryString: {}", serverConnection.getName(), MessageType.getString(clientMessage.getMessageType()), serverConnection.getSocketString(), cqName, cqQueryString);
}
// Check if the Server is running in NotifyBySubscription=true mode.
CacheClientNotifier ccn = acceptor.getCacheClientNotifier();
if (ccn != null) {
CacheClientProxy proxy = ccn.getClientProxy(id);
if (proxy != null && !proxy.isNotifyBySubscription()) {
// This should have been taken care at the client.
String err = LocalizedStrings.ExecuteCQ_SERVER_NOTIFYBYSUBSCRIPTION_MODE_IS_SET_TO_FALSE_CQ_EXECUTION_IS_NOT_SUPPORTED_IN_THIS_MODE.toLocalizedString();
sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
return;
}
}
DefaultQueryService qService = null;
CqServiceImpl cqServiceForExec = null;
Query query = null;
Set cqRegionNames = null;
ExecuteCQOperationContext executeCQContext = null;
ServerCQImpl cqQuery = null;
try {
qService = (DefaultQueryService) crHelper.getCache().getLocalQueryService();
// Authorization check
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
query = qService.newQuery(cqQueryString);
cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
executeCQContext = authzRequest.executeCQAuthorize(cqName, cqQueryString, cqRegionNames);
String newCqQueryString = executeCQContext.getQuery();
if (!cqQueryString.equals(newCqQueryString)) {
query = qService.newQuery(newCqQueryString);
cqQueryString = newCqQueryString;
cqRegionNames = executeCQContext.getRegionNames();
if (cqRegionNames == null) {
cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
}
}
}
if (CqServiceProvider.VMOTION_DURING_CQ_REGISTRATION_FLAG) {
VMotionObserver vmo = VMotionObserverHolder.getInstance();
vmo.vMotionBeforeCQRegistration();
}
cqServiceForExec = (CqServiceImpl) qService.getCqService();
// registering cq with serverConnection so that when CCP will require auth info it can access
// that
// registering cq auth before as possibility that you may get event
serverConnection.setCq(cqName, isDurable);
cqQuery = (ServerCQImpl) cqServiceForExec.executeCq(cqName, cqQueryString, cqState, id, ccn, isDurable, true, regionDataPolicyPartBytes[0], null);
} catch (CqException cqe) {
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
serverConnection.removeCq(cqName, isDurable);
return;
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.removeCq(cqName, isDurable);
return;
}
long oldstart = start;
boolean sendResults = false;
boolean successQuery = false;
if (clientMessage.getMessageType() == MessageType.EXECUTECQ_WITH_IR_MSG_TYPE) {
sendResults = true;
}
// if it is a non PR query with execute query and maintain keys flags set
if (sendResults || (CqServiceImpl.EXECUTE_QUERY_DURING_INIT && CqServiceProvider.MAINTAIN_KEYS && !cqQuery.isPR())) {
// Execute the query and send the result-set to client.
try {
if (query == null) {
query = qService.newQuery(cqQueryString);
cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
}
((DefaultQuery) query).setIsCqQuery(true);
successQuery = processQuery(clientMessage, query, cqQueryString, cqRegionNames, start, cqQuery, executeCQContext, serverConnection, sendResults);
// Update the CQ statistics.
cqQuery.getVsdStats().setCqInitialResultsTime((DistributionStats.getStatTime()) - oldstart);
stats.incProcessExecuteCqWithIRTime((DistributionStats.getStatTime()) - oldstart);
// logger.fine("Time spent in execute with initial results :" +
// DistributionStats.getStatTime() + ", " + oldstart);
} finally {
// If failure to execute the query, close the CQ.
if (!successQuery) {
try {
cqServiceForExec.closeCq(cqName, id);
} catch (Exception ex) {
// Ignore.
}
}
}
} else {
// Don't execute query for cq.execute and
// if it is a PR query with execute query and maintain keys flags not set
cqQuery.cqResultKeysInitialized = true;
successQuery = true;
}
if (!sendResults && successQuery) {
// Send OK to client
sendCqResponse(MessageType.REPLY, LocalizedStrings.ExecuteCQ_CQ_CREATED_SUCCESSFULLY.toLocalizedString(), clientMessage.getTransactionId(), null, serverConnection);
long start2 = DistributionStats.getStatTime();
stats.incProcessCreateCqTime(start2 - oldstart);
}
serverConnection.setAsTrue(RESPONDED);
}
use of org.apache.geode.internal.cache.vmotion.VMotionObserver 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.internal.cache.vmotion.VMotionObserver in project geode by apache.
the class RegisterInterest61 method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
Part regionNamePart = null, keyPart = null;
String regionName = null;
Object key = null;
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
// bserverStats.incLong(readDestroyRequestTimeId,
// DistributionStats.getStatTime() - start);
// bserverStats.incInt(destroyRequestsId, 1);
// start = DistributionStats.getStatTime();
// Retrieve the data from the message parts
regionNamePart = clientMessage.getPart(0);
regionName = regionNamePart.getString();
InterestResultPolicy policy = null;
// Retrieve the interest type
int interestType = clientMessage.getPart(1).getInt();
// Retrieve the InterestResultPolicy
try {
policy = (InterestResultPolicy) clientMessage.getPart(2).getObject();
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
boolean isDurable = false;
try {
Part durablePart = clientMessage.getPart(3);
byte[] durablePartBytes = (byte[]) durablePart.getObject();
isDurable = durablePartBytes[0] == 0x01;
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
// region data policy
byte[] regionDataPolicyPartBytes;
boolean serializeValues = false;
try {
Part regionDataPolicyPart = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
regionDataPolicyPartBytes = (byte[]) regionDataPolicyPart.getObject();
if (serverConnection.getClientVersion().compareTo(Version.GFE_80) >= 0) {
// The second byte here is serializeValues
serializeValues = regionDataPolicyPartBytes[1] == (byte) 0x01;
}
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
// Retrieve the key
keyPart = clientMessage.getPart(4);
regionName = regionNamePart.getString();
try {
key = keyPart.getStringOrObject();
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
boolean sendUpdatesAsInvalidates = false;
// time being until refactoring into a new command version.
if (clientMessage.getNumberOfParts() > 5) {
try {
Part notifyPart = clientMessage.getPart(5);
byte[] notifyPartBytes = (byte[]) notifyPart.getObject();
sendUpdatesAsInvalidates = notifyPartBytes[0] == 0x01;
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
}
if (logger.isDebugEnabled()) {
logger.debug("{}: Received register interest 61 request ({} bytes) from {} for region {} key {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key);
}
if (VMOTION_DURING_REGISTER_INTEREST_FLAG) {
VMotionObserver vmo = VMotionObserverHolder.getInstance();
vmo.vMotionBeforeRegisterInterest();
}
// Process the register interest request
if (key == null || regionName == null) {
StringId message = null;
if (key == null) {
message = LocalizedStrings.RegisterInterest_THE_INPUT_KEY_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
}
if (regionName == null) {
message = LocalizedStrings.RegisterInterest_THE_INPUT_REGION_NAME_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
}
logger.warn("{}: {}", serverConnection.getName(), message.toLocalizedString());
writeChunkedErrorResponse(clientMessage, MessageType.REGISTER_INTEREST_DATA_ERROR, message.toLocalizedString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
// input key not null
LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
if (region == null) {
logger.info(LocalizedMessage.create(LocalizedStrings.RegisterInterest_0_REGION_NAMED_1_WAS_NOT_FOUND_DURING_REGISTER_INTEREST_REQUEST, new Object[] { serverConnection.getName(), regionName }));
// writeChunkedErrorResponse(msg,
// MessageType.REGISTER_INTEREST_DATA_ERROR, message);
// responded = true;
}
// Register interest
try {
if (interestType == InterestType.REGULAR_EXPRESSION) {
this.securityService.authorizeRegionRead(regionName);
} else {
this.securityService.authorizeRegionRead(regionName, key.toString());
}
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
RegisterInterestOperationContext registerContext = authzRequest.registerInterestAuthorize(regionName, key, interestType, policy);
key = registerContext.getKey();
}
}
serverConnection.getAcceptor().getCacheClientNotifier().registerClientInterest(regionName, key, serverConnection.getProxyID(), interestType, isDurable, sendUpdatesAsInvalidates, true, regionDataPolicyPartBytes[0], true);
} catch (Exception e) {
// If an interrupted exception is thrown , rethrow it
checkForInterrupt(serverConnection, e);
// Otherwise, write an exception message and continue
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
// System.out.println("Received register interest for " + regionName);
// Update the statistics and write the reply
// bserverStats.incLong(processDestroyTimeId,
// DistributionStats.getStatTime() - start);
// start = DistributionStats.getStatTime();
CacheClientProxy ccp = serverConnection.getAcceptor().getCacheClientNotifier().getClientProxy(serverConnection.getProxyID());
if (ccp == null) {
// fix for 37593
IOException ioex = new IOException(LocalizedStrings.RegisterInterest_CACHECLIENTPROXY_FOR_THIS_CLIENT_IS_NO_LONGER_ON_THE_SERVER_SO_REGISTERINTEREST_OPERATION_IS_UNSUCCESSFUL.toLocalizedString());
writeChunkedException(clientMessage, ioex, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
boolean isPrimary = ccp.isPrimary();
ChunkedMessage chunkedResponseMsg = serverConnection.getRegisterInterestResponseMessage();
if (!isPrimary) {
chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_SECONDARY);
chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
chunkedResponseMsg.sendHeader();
chunkedResponseMsg.setLastChunk(true);
if (logger.isDebugEnabled()) {
logger.debug("{}: Sending register interest response chunk from secondary for region: {} for key: {} chunk=<{}>", serverConnection.getName(), regionName, key, chunkedResponseMsg);
}
chunkedResponseMsg.sendChunk(serverConnection);
} else // !isPrimary
{
// isPrimary
// Send header which describes how many chunks will follow
chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_PRIMARY);
chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
chunkedResponseMsg.sendHeader();
// Send chunk response
try {
fillAndSendRegisterInterestResponseChunks(region, key, interestType, serializeValues, policy, serverConnection);
serverConnection.setAsTrue(RESPONDED);
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection, chunkedResponseMsg);
serverConnection.setAsTrue(RESPONDED);
return;
}
if (logger.isDebugEnabled()) {
// logger.debug(getName() + ": Sent chunk (1 of 1) of register interest
// response (" + chunkedResponseMsg.getBufferLength() + " bytes) for
// region " + regionName + " key " + key);
logger.debug("{}: Sent register interest response for region {} key {}", serverConnection.getName(), regionName, key);
}
// bserverStats.incLong(writeDestroyResponseTimeId,
// DistributionStats.getStatTime() - start);
// bserverStats.incInt(destroyResponsesId, 1);
}
// isPrimary
}
Aggregations