Search in sources :

Example 46 with DistributionManager

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());
}
Also used : TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) ServerToClientFunctionResultSender65(org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender65) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) FunctionException(org.apache.geode.cache.execute.FunctionException) LowMemoryException(org.apache.geode.cache.LowMemoryException) IOException(java.io.IOException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)

Example 47 with DistributionManager

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;
}
Also used : GMSMembershipManager(org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipManager) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionManager(org.apache.geode.distributed.internal.DistributionManager)

Example 48 with DistributionManager

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;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) CancelException(org.apache.geode.CancelException) ReplyException(org.apache.geode.distributed.internal.ReplyException) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 49 with DistributionManager

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());
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) DM(org.apache.geode.distributed.internal.DM) DistributionManager(org.apache.geode.distributed.internal.DistributionManager)

Example 50 with DistributionManager

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);
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) TombstoneMessage(org.apache.geode.internal.cache.DistributedTombstoneOperation.TombstoneMessage) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DistributionManager (org.apache.geode.distributed.internal.DistributionManager)60 Test (org.junit.Test)44 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)36 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)29 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)29 VM (org.apache.geode.test.dunit.VM)29 Host (org.apache.geode.test.dunit.Host)28 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)25 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)15 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)12 Cache (org.apache.geode.cache.Cache)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)11 IOException (java.io.IOException)9 IgnoredException (org.apache.geode.test.dunit.IgnoredException)9 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 Properties (java.util.Properties)8 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 Region (org.apache.geode.cache.Region)6