Search in sources :

Example 26 with DistributedRegion

use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.

the class ExecuteRegionFunction66 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection servConn, long start) throws IOException {
    String regionName = null;
    Object function = null;
    Object args = null;
    MemberMappedArgument memberMappedArg = null;
    final boolean isBucketsAsFilter;
    final byte isReExecute;
    Set<Object> filter = null;
    byte hasResult = 0;
    int removedNodesSize = 0;
    Set<Object> removedNodesSet = null;
    int filterSize = 0, partNumber = 0;
    CachedRegionHelper crHelper = servConn.getCachedRegionHelper();
    byte functionState = 0;
    int functionTimeout = ConnectionImpl.DEFAULT_CLIENT_FUNCTION_TIMEOUT;
    try {
        byte[] bytes = clientMessage.getPart(0).getSerializedForm();
        functionState = bytes[0];
        if (bytes.length >= 5 && servConn.getClientVersion().ordinal() >= Version.GFE_8009.ordinal()) {
            functionTimeout = Part.decodeInt(bytes, 1);
        }
        if (functionState != 1) {
            hasResult = (byte) ((functionState & 2) - 1);
        } else {
            hasResult = functionState;
        }
        if (hasResult == 1) {
            servConn.setAsTrue(REQUIRES_RESPONSE);
            servConn.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
        }
        regionName = clientMessage.getPart(1).getString();
        function = clientMessage.getPart(2).getStringOrObject();
        args = clientMessage.getPart(3).getObject();
        Part part = clientMessage.getPart(4);
        if (part != null) {
            Object obj = part.getObject();
            if (obj instanceof MemberMappedArgument) {
                memberMappedArg = (MemberMappedArgument) obj;
            }
        }
        byte[] flags = clientMessage.getPart(5).getSerializedForm();
        if (servConn.getClientVersion().ordinal() > Version.GFE_81.ordinal()) {
            isBucketsAsFilter = (flags[0] & ExecuteFunctionHelper.BUCKETS_AS_FILTER_MASK) != 0;
            isReExecute = (flags[0] & ExecuteFunctionHelper.IS_REXECUTE_MASK) != 0 ? (byte) 1 : 0;
        } else {
            isReExecute = flags[0];
            isBucketsAsFilter = false;
        }
        filterSize = clientMessage.getPart(6).getInt();
        if (filterSize != 0) {
            filter = new HashSet<Object>();
            partNumber = 7;
            for (int i = 0; i < filterSize; i++) {
                filter.add(clientMessage.getPart(partNumber + i).getStringOrObject());
            }
        }
        partNumber = 7 + filterSize;
        removedNodesSize = clientMessage.getPart(partNumber).getInt();
        if (removedNodesSize != 0) {
            removedNodesSet = new HashSet<Object>();
            partNumber = partNumber + 1;
            for (int i = 0; i < removedNodesSize; i++) {
                removedNodesSet.add(clientMessage.getPart(partNumber + i).getStringOrObject());
            }
        }
    } catch (ClassNotFoundException exception) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), exception);
        if (hasResult == 1) {
            writeChunkedException(clientMessage, exception, servConn);
        } else {
            writeException(clientMessage, exception, false, servConn);
        }
        servConn.setAsTrue(RESPONDED);
        return;
    }
    if (function == null || regionName == null) {
        String message = null;
        if (function == null) {
            message = LocalizedStrings.ExecuteRegionFunction_THE_INPUT_0_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString("function");
        }
        if (regionName == null) {
            message = LocalizedStrings.ExecuteRegionFunction_THE_INPUT_0_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString("region");
        }
        logger.warn("{}: {}", servConn.getName(), message);
        sendError(hasResult, clientMessage, message, servConn);
        return;
    }
    Region region = crHelper.getRegion(regionName);
    if (region == null) {
        String message = LocalizedStrings.ExecuteRegionFunction_THE_REGION_NAMED_0_WAS_NOT_FOUND_DURING_EXECUTE_FUNCTION_REQUEST.toLocalizedString(regionName);
        logger.warn("{}: {}", servConn.getName(), message);
        sendError(hasResult, clientMessage, message, servConn);
        return;
    }
    HandShake handShake = (HandShake) servConn.getHandshake();
    int earlierClientReadTimeout = handShake.getClientReadTimeout();
    handShake.setClientReadTimeout(functionTimeout);
    ServerToClientFunctionResultSender resultSender = null;
    Function functionObject = null;
    try {
        if (function instanceof String) {
            functionObject = FunctionService.getFunction((String) function);
            if (functionObject == null) {
                String message = LocalizedStrings.ExecuteRegionFunction_THE_FUNCTION_0_HAS_NOT_BEEN_REGISTERED.toLocalizedString(function);
                logger.warn("{}: {}", servConn.getName(), message);
                sendError(hasResult, clientMessage, message, servConn);
                return;
            } else {
                byte functionStateOnServerSide = AbstractExecution.getFunctionState(functionObject.isHA(), functionObject.hasResult(), functionObject.optimizeForWrite());
                if (logger.isDebugEnabled()) {
                    logger.debug("Function State on server side: {} on client: {}", functionStateOnServerSide, functionState);
                }
                if (functionStateOnServerSide != functionState) {
                    String message = LocalizedStrings.FunctionService_FUNCTION_ATTRIBUTE_MISMATCH_CLIENT_SERVER.toLocalizedString(function);
                    logger.warn("{}: {}", servConn.getName(), message);
                    sendError(hasResult, clientMessage, message, servConn);
                    return;
                }
            }
        } else {
            functionObject = (Function) function;
        }
        this.securityService.authorizeDataWrite();
        // check if the caller is authorized to do this operation on server
        AuthorizeRequest authzRequest = servConn.getAuthzRequest();
        final String functionName = functionObject.getId();
        final String regionPath = region.getFullPath();
        ExecuteFunctionOperationContext executeContext = null;
        if (authzRequest != null) {
            executeContext = authzRequest.executeFunctionAuthorize(functionName, regionPath, filter, args, functionObject.optimizeForWrite());
        }
        // Construct execution
        AbstractExecution execution = (AbstractExecution) FunctionService.onRegion(region);
        ChunkedMessage m = servConn.getFunctionResponseMessage();
        m.setTransactionId(clientMessage.getTransactionId());
        resultSender = new ServerToClientFunctionResultSender65(m, MessageType.EXECUTE_REGION_FUNCTION_RESULT, servConn, functionObject, executeContext);
        if (execution instanceof PartitionedRegionFunctionExecutor) {
            if ((hasResult == 1) && filter != null && filter.size() == 1) {
                ServerConnection.executeFunctionOnLocalNodeOnly((byte) 1);
            }
            execution = new PartitionedRegionFunctionExecutor((PartitionedRegion) region, filter, args, memberMappedArg, resultSender, removedNodesSet, isBucketsAsFilter);
        } else {
            execution = new DistributedRegionFunctionExecutor((DistributedRegion) region, filter, args, memberMappedArg, resultSender);
        }
        if (isReExecute == 1) {
            execution = execution.setIsReExecute();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Executing Function: {} on Server: {} with Execution: {} functionState={} reExecute={} hasResult={}", functionObject.getId(), servConn, execution, functionState, isReExecute, hasResult);
        }
        if (hasResult == 1) {
            if (function instanceof String) {
                switch(functionState) {
                    case AbstractExecution.NO_HA_HASRESULT_NO_OPTIMIZEFORWRITE:
                        execution.execute((String) function, true, false, false).getResult();
                        break;
                    case AbstractExecution.HA_HASRESULT_NO_OPTIMIZEFORWRITE:
                        execution.execute((String) function, true, true, false).getResult();
                        break;
                    case AbstractExecution.HA_HASRESULT_OPTIMIZEFORWRITE:
                        execution.execute((String) function, true, true, true).getResult();
                        break;
                    case AbstractExecution.NO_HA_HASRESULT_OPTIMIZEFORWRITE:
                        execution.execute((String) function, true, false, true).getResult();
                        break;
                }
            } else {
                execution.execute(functionObject).getResult();
            }
        } else {
            if (function instanceof String) {
                switch(functionState) {
                    case AbstractExecution.NO_HA_NO_HASRESULT_NO_OPTIMIZEFORWRITE:
                        execution.execute((String) function, false, false, false);
                        break;
                    case AbstractExecution.NO_HA_NO_HASRESULT_OPTIMIZEFORWRITE:
                        execution.execute((String) function, false, false, true);
                        break;
                }
            } else {
                execution.execute(functionObject);
            }
            writeReply(clientMessage, servConn);
        }
    } catch (IOException ioe) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), ioe);
        final String message = LocalizedStrings.ExecuteRegionFunction_SERVER_COULD_NOT_SEND_THE_REPLY.toLocalizedString();
        sendException(hasResult, clientMessage, message, servConn, ioe);
    } catch (FunctionException fe) {
        String message = fe.getMessage();
        Object cause = fe.getCause();
        if (cause instanceof FunctionInvocationTargetException || cause instanceof QueryInvocationTargetException) {
            if (cause instanceof InternalFunctionInvocationTargetException) {
                // 4> in case of HA member departed
                if (logger.isDebugEnabled()) {
                    logger.debug(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, new Object[] { function }), fe);
                }
            } else if (functionObject.isHA()) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function + " :" + message));
            } else {
                logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), fe);
            }
            resultSender.setException(fe);
        } else {
            logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), fe);
            sendException(hasResult, clientMessage, message, servConn, fe);
        }
    } catch (Exception e) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), e);
        String message = e.getMessage();
        sendException(hasResult, clientMessage, message, servConn, e);
    } finally {
        handShake.setClientReadTimeout(earlierClientReadTimeout);
        ServerConnection.executeFunctionOnLocalNodeOnly((byte) 0);
    }
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) Function(org.apache.geode.cache.execute.Function) HandShake(org.apache.geode.internal.cache.tier.sockets.HandShake) MemberMappedArgument(org.apache.geode.internal.cache.execute.MemberMappedArgument) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) PartitionedRegionFunctionExecutor(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionExecutor) ExecuteFunctionOperationContext(org.apache.geode.cache.operations.ExecuteFunctionOperationContext) ServerToClientFunctionResultSender65(org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender65) FunctionException(org.apache.geode.cache.execute.FunctionException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) IOException(java.io.IOException) DistributedRegionFunctionExecutor(org.apache.geode.internal.cache.execute.DistributedRegionFunctionExecutor) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Part(org.apache.geode.internal.cache.tier.sockets.Part) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ServerToClientFunctionResultSender(org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Example 27 with DistributedRegion

use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.

the class ConcurrentLeaveDuringGIIDUnitTest method testBug48962.

/**
   * In #48962 a member X has replicated region and is updating it. Members A and B are started up
   * in parallel. At the same time X decides to close the region. Member A manages to tell X that
   * it's creating the region and receives an update that B does not see. B finishes GII with no
   * content and then A gets its initial image from B, leaving an inconsistency between them.
   * <p>
   * The test installs a GII hook in A that causes it to pause after announcing creation of the
   * region.
   * <p>
   * X then creates its region and does an operation and closes its cache.
   * <p>
   * B then starts and creates its region, not doing a GII from A since A is still initializing.
   * <p>
   * A is then allowed to start its GII and pulls an image from B.
   * 
   */
@Ignore
@Test
public void testBug48962() throws Exception {
    VM X = Host.getHost(0).getVM(1);
    VM A = Host.getHost(0).getVM(2);
    VM B = Host.getHost(0).getVM(3);
    final String regionName = getUniqueName() + "_Region";
    SerializableCallable createRegionXB = new SerializableCallable("create region in X and B") {

        public Object call() {
            Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            Object result = null;
            if (VM.getCurrentVMNum() == 1) {
                // VM X
                r.put("keyFromX", "valueFromX");
                result = getCache().getDistributedSystem().getDistributedMember();
                r.getCache().getDistributedSystem().disconnect();
            } else {
                // VM B
                // B will not do a GII and X never knows about B
                assertFalse(r.containsKey("keyFromX"));
                result = getCache().getDistributedSystem().getDistributedMember();
            }
            return result;
        }
    };
    SerializableCallable createRegionA = new SerializableCallable("create region in A") {

        public Object call() {
            final GiiCallback cb = new GiiCallback(InitialImageOperation.GIITestHookType.BeforeGetInitialImage, regionName);
            InitialImageOperation.setGIITestHook(cb);
            Thread t = new Thread("create region in a thread that will block before GII") {

                public void run() {
                    Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
                }
            };
            t.start();
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return cb.isRunning;
                }

                public String description() {
                    return "waiting for GII test hook to be invoked";
                }
            };
            Wait.waitForCriterion(wc, 20000, 500, true);
            return getCache().getDistributedSystem().getDistributedMember();
        }
    };
    A.invoke(createRegionA);
    final InternalDistributedMember Xid = (InternalDistributedMember) X.invoke(createRegionXB);
    A.invoke(new SerializableRunnable("make sure A got keyFromX from X") {

        public void run() {
            // use internal methods to get the region since it's still initializing
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            final RegionMap r = cache.getRegionByPathForProcessing(regionName).getRegionMap();
            // X's update should have been propagated to A and put into the cache.
            // If this throws an assertion error then there's no point in
            // continuing the test because we didn't set up the initial
            // condition needed for the next step.
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return r.containsKey("keyFromX");
                }

                public String description() {
                    return "waiting for region " + regionName + " to contain keyFromX";
                }
            };
            Wait.waitForCriterion(wc, 20000, 1000, true);
        }
    });
    // create in B and make sure the key isn't there
    B.invoke(createRegionXB);
    A.invoke(new SerializableRunnable("allow A to continue GII from B") {

        public void run() {
            GiiCallback cb = (GiiCallback) InitialImageOperation.getGIITestHookForCheckingPurpose(InitialImageOperation.GIITestHookType.BeforeGetInitialImage);
            synchronized (cb.lockObject) {
                cb.lockObject.notify();
            }
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return getCache().getRegion(regionName) != null;
                }

                public String description() {
                    return "waiting for region " + regionName + " to initialize";
                }
            };
            Wait.waitForCriterion(wc, 20000, 1000, true);
            // ensure that the RVV has recorded the event
            DistributedRegion r = (DistributedRegion) getCache().getRegion(regionName);
            if (!r.getVersionVector().contains(Xid, 1)) {
                LogWriterUtils.getLogWriter().info("r's version vector is " + r.getVersionVector().fullToString());
                ((LocalRegion) r).dumpBackingMap();
            }
            assertTrue(r.containsKey("keyFromX"));
            // if the test fails here then the op received from X was not correctly
            // picked up and recorded in the RVV
            assertTrue(r.getVersionVector().contains(Xid, 1));
        }
    });
    // Now ensure the B has done the sync and received the entry
    B.invoke(new SerializableRunnable("ensure B is now consistent") {

        public void run() {
            final Region r = getCache().getRegion(regionName);
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    return r.containsKey("keyFromX");
                }

                public String description() {
                    return "waiting for region " + regionName + " to contain keyFromX";
                }
            };
            // if the test fails here then a sync from B to A was not performed
            Wait.waitForCriterion(wc, 20000, 500, true);
            // if the test fails here something is odd because the sync was done
            // but the RVV doesn't know about it
            assertTrue(((LocalRegion) r).getVersionVector().contains(Xid, 1));
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) RegionMap(org.apache.geode.internal.cache.RegionMap) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 28 with DistributedRegion

use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.

the class ParallelAsyncEventQueueImpl method setModifiedEventId.

@Override
protected void setModifiedEventId(EntryEventImpl clonedEvent) {
    int bucketId = -1;
    // merged from 42004
    if (clonedEvent.getRegion() instanceof DistributedRegion) {
        bucketId = PartitionedRegionHelper.getHashKey(clonedEvent.getKey(), getMaxParallelismForReplicatedRegion());
    } else {
        bucketId = PartitionedRegionHelper.getHashKey((EntryOperation) clonedEvent);
    }
    EventID originalEventId = clonedEvent.getEventId();
    long originatingThreadId = ThreadIdentifier.getRealThreadID(originalEventId.getThreadID());
    long newThreadId = ThreadIdentifier.createFakeThreadIDForParallelGSPrimaryBucket(bucketId, originatingThreadId, getEventIdIndex());
    // In case of parallel as all events go through primary buckets
    // we don't need to generate different threadId for secondary buckets
    // as they will be rejected if seen at PR level itself
    EventID newEventId = new EventID(originalEventId.getMembershipID(), newThreadId, originalEventId.getSequenceID(), bucketId);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Generated event id for event with key={}, bucketId={}, original event id={}, threadId={}, new event id={}, newThreadId={}", this, clonedEvent.getKey(), bucketId, originalEventId, originatingThreadId, newEventId, newThreadId);
    }
    clonedEvent.setEventId(newEventId);
}
Also used : EventID(org.apache.geode.internal.cache.EventID) EntryOperation(org.apache.geode.cache.EntryOperation) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion)

Example 29 with DistributedRegion

use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.

the class DistributionAdvisor method syncForCrashedMember.

/** perform a delta-GII for the given lost member */
public void syncForCrashedMember(final InternalDistributedMember id, final Profile profile) {
    final DistributedRegion dr = getRegionForDeltaGII();
    if (dr == null) {
        return;
    }
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("da.syncForCrashedMember will sync region in waiting thread pool: {}", dr);
    }
    dr.getDistributionManager().getWaitingThreadPool().execute(new Runnable() {

        // bug #49601 - don't synchronize until GII has been performed
        public void run() {
            while (!dr.isInitialized()) {
                if (dr.isDestroyed()) {
                    return;
                } else {
                    try {
                        if (isDebugEnabled) {
                            logger.debug("da.syncForCrashedMember waiting for region to finish initializing: {}", dr);
                        }
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        return;
                    }
                }
            }
            CacheProfile cp = (CacheProfile) profile;
            PersistentMemberID persistentId = cp.persistentID;
            if (dr.getDataPolicy().withPersistence() && persistentId == null) {
                // a persistent member.
                if (isDebugEnabled) {
                    logger.debug("da.syncForCrashedMember skipping sync because crashed member is not persistent: {}", id);
                }
                return;
            }
            VersionSource lostVersionID;
            if (persistentId != null) {
                lostVersionID = persistentId.getVersionMember();
            } else {
                lostVersionID = id;
            }
            dr.synchronizeForLostMember(id, lostVersionID);
        }
    });
}
Also used : CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID)

Example 30 with DistributedRegion

use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.

the class PersistentStateQueryMessage method process.

@Override
protected void process(DistributionManager dm) {
    // Set thread local flag to allow entrance through initialization Latch
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
    PersistentMemberState state = null;
    PersistentMemberID myId = null;
    PersistentMemberID myInitializingId = null;
    DiskStoreID diskStoreId = null;
    HashSet<PersistentMemberID> onlineMembers = null;
    ReplyException exception = null;
    boolean successfulReply = false;
    try {
        // get the region from the path, but do NOT wait on initialization,
        // otherwise we could have a distributed deadlock
        Cache cache = CacheFactory.getInstance(dm.getSystem());
        Region region = cache.getRegion(this.regionPath);
        PersistenceAdvisor persistenceAdvisor = null;
        if (region instanceof DistributedRegion) {
            persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
        } else if (region == null) {
            Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
            if (proxy != null) {
                persistenceAdvisor = proxy.getPersistenceAdvisor();
            }
        }
        if (persistenceAdvisor != null) {
            if (id != null) {
                state = persistenceAdvisor.getPersistedStateOfMember(id);
            }
            if (initializingId != null && state == null) {
                state = persistenceAdvisor.getPersistedStateOfMember(initializingId);
            }
            myId = persistenceAdvisor.getPersistentID();
            myInitializingId = persistenceAdvisor.getInitializingID();
            onlineMembers = persistenceAdvisor.getPersistedOnlineOrEqualMembers();
            diskStoreId = persistenceAdvisor.getDiskStoreID();
            successfulReply = true;
        }
    } catch (RegionDestroyedException e) {
        logger.debug("<RegionDestroyed> {}", this);
    } catch (CancelException e) {
        logger.debug("<CancelException> {}", this);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable t) {
        SystemFailure.checkFailure();
        exception = new ReplyException(t);
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
        ReplyMessage replyMsg;
        if (successfulReply) {
            PersistentStateQueryReplyMessage persistentReplyMessage = new PersistentStateQueryReplyMessage();
            persistentReplyMessage.myId = myId;
            persistentReplyMessage.persistedStateOfPeer = state;
            persistentReplyMessage.myInitializingId = myInitializingId;
            persistentReplyMessage.diskStoreId = diskStoreId;
            persistentReplyMessage.onlineMembers = onlineMembers;
            replyMsg = persistentReplyMessage;
        } else {
            replyMsg = new ReplyMessage();
        }
        replyMsg.setProcessorId(processorId);
        replyMsg.setRecipient(getSender());
        if (exception != null) {
            replyMsg.setException(exception);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Received {},replying with {}", this, replyMsg);
        }
        dm.putOutgoing(replyMsg);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Cache(org.apache.geode.cache.Cache)

Aggregations

DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)36 Region (org.apache.geode.cache.Region)25 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)16 LocalRegion (org.apache.geode.internal.cache.LocalRegion)14 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 VM (org.apache.geode.test.dunit.VM)9 Test (org.junit.Test)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 Cache (org.apache.geode.cache.Cache)7 Host (org.apache.geode.test.dunit.Host)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 FunctionException (org.apache.geode.cache.execute.FunctionException)6 IOException (java.io.IOException)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 CacheException (org.apache.geode.cache.CacheException)5 IgnoredException (org.apache.geode.test.dunit.IgnoredException)5 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)5 Set (java.util.Set)4 CancelException (org.apache.geode.CancelException)4 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)4