Search in sources :

Example 1 with DependencyGraph

use of org.apache.geode.distributed.internal.deadlock.DependencyGraph in project geode by apache.

the class MiscellaneousCommands method showDeadlock.

@CliCommand(value = CliStrings.SHOW_DEADLOCK, help = CliStrings.SHOW_DEADLOCK__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result showDeadlock(@CliOption(key = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE, help = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE__HELP, mandatory = true) String filename) {
    Result result = null;
    try {
        if (!filename.endsWith(".txt")) {
            return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, ".txt"));
        }
        InternalCache cache = getCache();
        Set<DistributedMember> allMembers = CliUtil.getAllMembers(cache);
        GemFireDeadlockDetector gfeDeadLockDetector = new GemFireDeadlockDetector(allMembers);
        DependencyGraph dependencyGraph = gfeDeadLockDetector.find();
        Collection<Dependency> deadlock = dependencyGraph.findCycle();
        DependencyGraph deepest = null;
        if (deadlock == null) {
            deepest = dependencyGraph.findLongestCallChain();
            if (deepest != null) {
                deadlock = deepest.getEdges();
            }
        }
        Set<Dependency> dependencies = (Set<Dependency>) dependencyGraph.getEdges();
        InfoResultData resultData = ResultBuilder.createInfoResultData();
        if (deadlock != null) {
            if (deepest != null) {
                resultData.addLine(CliStrings.SHOW_DEADLOCK__DEEPEST_FOUND);
            } else {
                resultData.addLine(CliStrings.SHOW_DEADLOCK__DEADLOCK__DETECTED);
            }
            resultData.addLine(DeadlockDetector.prettyFormat(deadlock));
        } else {
            resultData.addLine(CliStrings.SHOW_DEADLOCK__NO__DEADLOCK);
        }
        resultData.addAsFile(filename, DeadlockDetector.prettyFormat(dependencies), MessageFormat.format(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__REVIEW, filename), false);
        result = ResultBuilder.buildResult(resultData);
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.SHOW_DEADLOCK__ERROR + " : " + e.getMessage());
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) GemFireDeadlockDetector(org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) DependencyGraph(org.apache.geode.distributed.internal.deadlock.DependencyGraph) Dependency(org.apache.geode.distributed.internal.deadlock.Dependency) TimeoutException(java.util.concurrent.TimeoutException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) FunctionException(org.apache.geode.cache.execute.FunctionException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) NetstatFunctionResult(org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 DataFormatException (java.util.zip.DataFormatException)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 Dependency (org.apache.geode.distributed.internal.deadlock.Dependency)1 DependencyGraph (org.apache.geode.distributed.internal.deadlock.DependencyGraph)1 GemFireDeadlockDetector (org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 Result (org.apache.geode.management.cli.Result)1 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)1 NetstatFunctionResult (org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult)1 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)1 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)1 ResultDataException (org.apache.geode.management.internal.cli.result.ResultDataException)1 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)1