Search in sources :

Example 16 with InternalFunctionInvocationTargetException

use of org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException 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 17 with InternalFunctionInvocationTargetException

use of org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException in project geode by apache.

the class ExecuteRegionFunction65 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;
    byte isReExecute = 0;
    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;
    try {
        functionState = clientMessage.getPart(0).getSerializedForm()[0];
        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;
            }
        }
        isReExecute = clientMessage.getPart(5).getSerializedForm()[0];
        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);
            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(0);
    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) {
            execution = new PartitionedRegionFunctionExecutor((PartitionedRegion) region, filter, args, memberMappedArg, resultSender, removedNodesSet, false);
        } 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);
            }
        }
    } 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();
        if (fe.getCause() instanceof FunctionInvocationTargetException) {
            if (fe.getCause() 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);
    }
}
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) 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) 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 18 with InternalFunctionInvocationTargetException

use of org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException 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 19 with InternalFunctionInvocationTargetException

use of org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException in project geode by apache.

the class PartitionedRegion method executeOnSingleNode.

/**
   * Single key execution on single node
   * 
   * @since GemFire 6.0
   */
private ResultCollector executeOnSingleNode(final Function function, final PartitionedRegionFunctionExecutor execution, ResultCollector rc, boolean isPRSingleHop, boolean isBucketSetAsFilter) {
    final Set routingKeys = execution.getFilter();
    final Object key = routingKeys.iterator().next();
    final Integer bucketId;
    if (isBucketSetAsFilter) {
        bucketId = (Integer) key;
    } else {
        bucketId = PartitionedRegionHelper.getHashKey(this, Operation.FUNCTION_EXECUTION, key, null, null);
    }
    InternalDistributedMember targetNode = null;
    if (function.optimizeForWrite()) {
        targetNode = createBucket(bucketId, 0, null);
        HeapMemoryMonitor hmm = ((InternalResourceManager) cache.getResourceManager()).getHeapMonitor();
        if (hmm.isMemberHeapCritical(targetNode) && !MemoryThresholds.isLowMemoryExceptionDisabled()) {
            Set<DistributedMember> sm = Collections.singleton((DistributedMember) targetNode);
            throw new LowMemoryException(LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_0_FUNCEXEC_MEMBERS_1.toLocalizedString(function.getId(), sm), sm);
        }
    } else {
        targetNode = getOrCreateNodeForBucketRead(bucketId);
    }
    final DistributedMember localVm = getMyId();
    if (targetNode != null && isPRSingleHop && !localVm.equals(targetNode)) {
        Set<ServerBucketProfile> profiles = this.getRegionAdvisor().getClientBucketProfiles(bucketId);
        if (profiles != null) {
            for (ServerBucketProfile profile : profiles) {
                if (profile.getDistributedMember().equals(targetNode)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("FunctionServiceSingleHop: Found remote node.{}", localVm);
                    }
                    throw new InternalFunctionInvocationTargetException(LocalizedStrings.PartitionedRegion_MULTIPLE_TARGET_NODE_FOUND_FOR.toLocalizedString());
                }
            }
        }
    }
    if (targetNode == null) {
        throw new FunctionException(LocalizedStrings.PartitionedRegion_NO_TARGET_NODE_FOUND_FOR_KEY_0.toLocalizedString(key));
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Executing Function: {} setArguments={} on {}", function.getId(), execution.getArguments(), targetNode);
    }
    while (!execution.getFailedNodes().isEmpty()) {
        RetryTimeKeeper retryTime = new RetryTimeKeeper(this.retryTimeout);
        if (execution.getFailedNodes().contains(targetNode.getId())) {
            /*
         * if (retryTime.overMaximum()) { PRHARedundancyProvider.timedOut(this, null, null,
         * "doing function execution", this.retryTimeout); // NOTREACHED }
         */
            // Fix for Bug # 40083
            targetNode = null;
            while (targetNode == null) {
                if (retryTime.overMaximum()) {
                    PRHARedundancyProvider.timedOut(this, null, null, "doing function execution", this.retryTimeout);
                // NOTREACHED
                }
                retryTime.waitToRetryNode();
                if (function.optimizeForWrite()) {
                    targetNode = getOrCreateNodeForBucketWrite(bucketId, retryTime);
                } else {
                    targetNode = getOrCreateNodeForBucketRead(bucketId);
                }
            }
            if (targetNode == null) {
                throw new FunctionException(LocalizedStrings.PartitionedRegion_NO_TARGET_NODE_FOUND_FOR_KEY_0.toLocalizedString(key));
            }
        } else {
            execution.clearFailedNodes();
        }
    }
    final HashSet<Integer> buckets = new HashSet<Integer>();
    buckets.add(bucketId);
    final Set<InternalDistributedMember> singleMember = Collections.singleton(targetNode);
    execution.validateExecution(function, singleMember);
    execution.setExecutionNodes(singleMember);
    LocalResultCollector<?, ?> localRC = execution.getLocalResultCollector(function, rc);
    if (targetNode.equals(localVm)) {
        final DM dm = getDistributionManager();
        PartitionedRegionFunctionResultSender resultSender = new PartitionedRegionFunctionResultSender(dm, PartitionedRegion.this, 0, localRC, execution.getServerResultSender(), true, false, execution.isForwardExceptions(), function, buckets);
        final FunctionContext context = new RegionFunctionContextImpl(function.getId(), PartitionedRegion.this, execution.getArgumentsForMember(localVm.getId()), routingKeys, ColocationHelper.constructAndGetAllColocatedLocalDataSet(PartitionedRegion.this, buckets), buckets, resultSender, execution.isReExecute());
        execution.executeFunctionOnLocalPRNode(function, context, resultSender, dm, isTX());
        return localRC;
    } else {
        return executeFunctionOnRemoteNode(targetNode, function, execution.getArgumentsForMember(targetNode.getId()), routingKeys, function.isHA() ? rc : localRC, buckets, execution.getServerResultSender(), execution);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) FunctionException(org.apache.geode.cache.execute.FunctionException) EmptyRegionFunctionException(org.apache.geode.cache.execute.EmptyRegionFunctionException) DM(org.apache.geode.distributed.internal.DM) HeapMemoryMonitor(org.apache.geode.internal.cache.control.HeapMemoryMonitor) FunctionContext(org.apache.geode.cache.execute.FunctionContext) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerBucketProfile(org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RegionFunctionContextImpl(org.apache.geode.internal.cache.execute.RegionFunctionContextImpl) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) PartitionedRegionFunctionResultSender(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultSender) LowMemoryException(org.apache.geode.cache.LowMemoryException) HashSet(java.util.HashSet)

Example 20 with InternalFunctionInvocationTargetException

use of org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException in project geode by apache.

the class PRFunctionStreamingResultCollector method memberDeparted.

@Override
public void memberDeparted(final InternalDistributedMember id, final boolean crashed) {
    FunctionInvocationTargetException fite;
    if (id != null) {
        synchronized (this.members) {
            if (removeMember(id, true)) {
                if (!this.fn.isHA()) {
                    fite = new FunctionInvocationTargetException(LocalizedStrings.PartitionMessage_PARTITIONRESPONSE_GOT_MEMBERDEPARTED_EVENT_FOR_0_CRASHED_1.toLocalizedString(new Object[] { id, Boolean.valueOf(crashed) }), id);
                } else {
                    fite = new InternalFunctionInvocationTargetException(LocalizedStrings.PartitionMessage_PARTITIONRESPONSE_GOT_MEMBERDEPARTED_EVENT_FOR_0_CRASHED_1.toLocalizedString(new Object[] { id, Boolean.valueOf(crashed) }), id);
                    this.execution.addFailedNode(id.getId());
                }
                this.fites.add(fite);
            }
            checkIfDone();
        }
    } else {
        Exception e = new Exception(LocalizedStrings.PartitionMessage_MEMBERDEPARTED_GOT_NULL_MEMBERID.toLocalizedString());
        logger.info(LocalizedMessage.create(LocalizedStrings.PartitionMessage_MEMBERDEPARTED_GOT_NULL_MEMBERID_CRASHED_0, Boolean.valueOf(crashed)), e);
    }
}
Also used : InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) InternalFunctionException(org.apache.geode.internal.cache.execute.InternalFunctionException)

Aggregations

InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)24 FunctionException (org.apache.geode.cache.execute.FunctionException)17 ChunkedMessage (org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)10 IOException (java.io.IOException)9 CacheClosedException (org.apache.geode.cache.CacheClosedException)7 Function (org.apache.geode.cache.execute.Function)7 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)7 ExecuteFunctionOperationContext (org.apache.geode.cache.operations.ExecuteFunctionOperationContext)7 MemberMappedArgument (org.apache.geode.internal.cache.execute.MemberMappedArgument)7 HandShake (org.apache.geode.internal.cache.tier.sockets.HandShake)7 Part (org.apache.geode.internal.cache.tier.sockets.Part)7 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)7 LowMemoryException (org.apache.geode.cache.LowMemoryException)6 Region (org.apache.geode.cache.Region)6 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 DistributedMember (org.apache.geode.distributed.DistributedMember)5 ServerToClientFunctionResultSender (org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender)5 DM (org.apache.geode.distributed.internal.DM)4