use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class ExecuteFunction66 method executeFunctionaLocally.
private void executeFunctionaLocally(final Function fn, final FunctionContext cx, final ServerToClientFunctionResultSender65 sender, DM dm, final FunctionStats stats) throws IOException {
long startExecution = stats.startTime();
stats.startFunctionExecution(fn.hasResult());
if (fn.hasResult()) {
fn.execute(cx);
if (!((ServerToClientFunctionResultSender65) sender).isLastResultReceived() && fn.hasResult()) {
throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId()));
}
} else {
/*
* if dm is null it mean cache is also null. Transactional function without cache cannot be
* executed.
*/
final TXStateProxy txState = TXManagerImpl.getCurrentTXState();
Runnable functionExecution = new Runnable() {
public void run() {
InternalCache cache = null;
try {
if (txState != null) {
cache = GemFireCacheImpl.getExisting("executing function");
cache.getTxManager().masqueradeAs(txState);
if (cache.getLoggerI18n().warningEnabled() && !ASYNC_TX_WARNING_ISSUED) {
ASYNC_TX_WARNING_ISSUED = true;
cache.getLoggerI18n().warning(LocalizedStrings.ExecuteFunction66_TRANSACTIONAL_FUNCTION_WITHOUT_RESULT);
}
}
fn.execute(cx);
} catch (InternalFunctionInvocationTargetException internalfunctionException) {
// Fix for #44709: User should not be aware of
// InternalFunctionInvocationTargetException. No instance of
// InternalFunctionInvocationTargetException is giving useful
// information to user to take any corrective action hence logging
// this at fine level logging
// 1> Incase of HA FucntionInvocationTargetException thrown. Since
// it is HA, function will be reexecuted on right node
// 2> in case of HA member departed
stats.endFunctionExecutionWithException(fn.hasResult());
if (logger.isDebugEnabled()) {
logger.debug(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, new Object[] { fn }), internalfunctionException);
}
} catch (FunctionException functionException) {
stats.endFunctionExecutionWithException(fn.hasResult());
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, fn), functionException);
} catch (Exception exception) {
stats.endFunctionExecutionWithException(fn.hasResult());
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, fn), exception);
} finally {
if (txState != null && cache != null) {
cache.getTxManager().unmasquerade(txState);
}
}
}
};
if (dm == null) {
/**
* Executing the function in its own thread pool as FunctionExecution Thread pool of
* DisributionManager is not yet available.
*/
execService.execute(functionExecution);
} else {
final DistributionManager newDM = (DistributionManager) dm;
newDM.getFunctionExcecutor().execute(functionExecution);
}
}
stats.endFunctionExecution(startExecution, fn.hasResult());
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class MembershipManagerHelper method getMembershipManager.
/** returns the JGroupMembershipManager for the given distributed system */
public static MembershipManager getMembershipManager(DistributedSystem sys) {
InternalDistributedSystem isys = (InternalDistributedSystem) sys;
DistributionManager dm = (DistributionManager) isys.getDM();
MembershipManager mgr = dm.getMembershipManager();
return mgr;
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class MissingPersistentIDsRequest method send.
public static Set<PersistentID> send(DM dm) {
Set recipients = dm.getOtherDistributionManagerIds();
MissingPersistentIDsRequest request = new MissingPersistentIDsRequest();
request.setRecipients(recipients);
MissingPersistentIDProcessor replyProcessor = new MissingPersistentIDProcessor(dm, recipients);
request.msgId = replyProcessor.getProcessorId();
dm.putOutgoing(request);
try {
replyProcessor.waitForReplies();
} catch (ReplyException e) {
if (!(e.getCause() instanceof CancelException)) {
throw e;
}
} catch (InterruptedException e) {
logger.warn(e);
}
Set<PersistentID> results = replyProcessor.missing;
Set<PersistentID> existing = replyProcessor.existing;
MissingPersistentIDsResponse localResponse = (MissingPersistentIDsResponse) request.createResponse((DistributionManager) dm);
results.addAll(localResponse.getMissingIds());
existing.addAll(localResponse.getLocalIds());
results.removeAll(existing);
return results;
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class MemberMessenger method broadcastManagerInfo.
public void broadcastManagerInfo() {
Set<DistributedMember> otherMemberSet = system.getDistributionManager().getAllOtherMembers();
String levelName = jmxAdapter.getDistributedSystemMXBean().getAlertLevel();
int alertCode = LogLevel.getLogWriterLevel(levelName);
ManagerStartupMessage msg = ManagerStartupMessage.create(alertCode);
if (otherMemberSet != null && otherMemberSet.size() > 0) {
msg.setRecipients(otherMemberSet);
}
sendAsync(msg);
DM dm = system.getDistributionManager();
if (dm instanceof DistributionManager) {
msg.process((DistributionManager) system.getDistributionManager());
}
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class GIIDeltaDUnitTest method testTombstoneGCDuringFullGII.
/**
* Test case to make sure that if a tombstone GC occurs during a full GII, we still have the
* correct RVV on the GII recipient at the end.
*
* @throws Throwable
*/
// GEODE-1137: orphaned AsyncInvocations, time sensitive, GC,
@Category(FlakyTest.class)
// waitForCriterion, thread unsafe test hooks/observers, expiration
@Test
public void testTombstoneGCDuringFullGII() throws Throwable {
prepareForEachTest();
// Create the region in 1 more VM to to a tombstone GC.
VM vm2 = Host.getHost(0).getVM(2);
createDistributedRegion(vm2);
final DiskStoreID memberP = getMemberID(P);
final DiskStoreID memberR = getMemberID(R);
assertEquals(0, DistributedCacheOperation.SLOW_DISTRIBUTION_MS);
prepareCommonTestData(6);
// All members should have "key5" at this point
// shutdown R
closeCache(R);
final VM vmR = R;
// Destroy key5, this will leave a tombstone
doOneDestroy(P, 7, "key5");
// Set tesk hook so that R will pause GII after getting the RVV
R.invoke(new SerializableRunnable() {
public void run() {
// Add hooks before and after receiving the RVV
Mycallback myAfterSavedReceivedRVV = new Mycallback(GIITestHookType.AfterCalculatedUnfinishedOps, REGION_NAME);
InitialImageOperation.setGIITestHook(myAfterSavedReceivedRVV);
}
});
// Set a trigger in vm2 so that it will start up R after determining
// the recipients for a tombstone GC message. vm2 will wait until
// R has already received the RVV before sending the message.
vm2.invoke(new SerializableRunnable() {
@Override
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof TombstoneMessage && ((TombstoneMessage) message).regionPath.contains(REGION_NAME)) {
System.err.println("DAN DEBUG about to send tombstone message, starting up R - " + message.getSender());
AsyncInvocation async3 = createDistributedRegionAsync(vmR);
// Wait for R to finish requesting the RVV before letting the tombstone GC proceeed.
waitForCallbackStarted(vmR, GIITestHookType.AfterCalculatedUnfinishedOps);
System.err.println("DAN DEBUG R has received the RVV, sending tombstone message");
DistributionMessageObserver.setInstance(null);
}
}
});
}
});
P.invoke(new SerializableRunnable() {
@Override
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof TombstoneMessage && ((TombstoneMessage) message).regionPath.contains(REGION_NAME)) {
System.err.println("DAN DEBUG P has processed the tombstone message, allowing R to proceed with the GII");
vmR.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterCalculatedUnfinishedOps, true));
DistributionMessageObserver.setInstance(null);
}
}
});
}
});
// Force tombstone GC, this will trigger the R to be started, etc.
vm2.invoke(new SerializableRunnable() {
@Override
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
try {
cache.getTombstoneService().forceBatchExpirationForTests(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
// Wait for P to perform the tombstone GC
waitForToVerifyRVV(P, memberP, 7, null, 7);
System.err.println("DAN DEBUG P has finished the tombstone GC, waiting for R to get the correct RVV");
// Make sure that Rs RVV now reflects the update from P
// P's rvv=r7, gc=7
waitForToVerifyRVV(R, memberP, 7, null, 7);
}
Aggregations