Search in sources :

Example 1 with JetDelegatingClassLoader

use of com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader in project hazelcast by hazelcast.

the class JobExecutionService method completeExecution.

/**
 * Completes and cleans up execution of the given job
 */
public void completeExecution(@Nonnull ExecutionContext executionContext, Throwable error) {
    ExecutionContext removed = executionContexts.remove(executionContext.executionId());
    if (removed != null) {
        if (error != null) {
            failedJobs.put(executionContext.executionId(), System.nanoTime() + FAILED_EXECUTION_EXPIRY_NS);
        }
        JetDelegatingClassLoader jobClassLoader = jobClassloaderService.getClassLoader(executionContext.jobId());
        try {
            doWithClassLoader(jobClassLoader, () -> executionContext.completeExecution(error));
        } finally {
            if (!executionContext.isLightJob()) {
                jobClassloaderService.tryRemoveClassloadersForJob(executionContext.jobId(), EXECUTION);
            }
            executionCompleted.inc();
            executionContextJobIds.remove(executionContext.jobId());
            logger.fine("Completed execution of " + executionContext.jobNameAndExecutionId());
        }
    }
}
Also used : JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) ExecutionContext(com.hazelcast.jet.impl.execution.ExecutionContext)

Example 2 with JetDelegatingClassLoader

use of com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader in project hazelcast by hazelcast.

the class MasterJobContext method completeVertices.

private void completeVertices(@Nullable Throwable failure) {
    if (vertices != null) {
        JobClassLoaderService classLoaderService = mc.getJetServiceBackend().getJobClassLoaderService();
        JetDelegatingClassLoader jobCl = classLoaderService.getClassLoader(mc.jobId());
        doWithClassLoader(jobCl, () -> {
            for (Vertex v : vertices) {
                try {
                    ClassLoader processorCl = classLoaderService.getProcessorClassLoader(mc.jobId(), v.getName());
                    doWithClassLoader(processorCl, () -> v.getMetaSupplier().close(failure));
                } catch (Throwable e) {
                    logger.severe(mc.jobIdString() + " encountered an exception in ProcessorMetaSupplier.close(), ignoring it", e);
                }
            }
        });
    }
}
Also used : JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) Vertex(com.hazelcast.jet.core.Vertex) JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) Util.doWithClassLoader(com.hazelcast.jet.impl.util.Util.doWithClassLoader) CustomClassLoadedObject.deserializeWithCustomClassLoader(com.hazelcast.jet.impl.execution.init.CustomClassLoadedObject.deserializeWithCustomClassLoader)

Example 3 with JetDelegatingClassLoader

use of com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader in project hazelcast by hazelcast.

the class JobClassLoaderService method tryRemoveClassloadersForJob.

/**
 * Try to remove and close/shutdown job classloader and any processor
 * classloaders for given job
 * <p>
 * We keep track of phases where the classloader is used and remove
 * the classloader only if there are no more phases left.
 */
public void tryRemoveClassloadersForJob(long jobId, JobPhase phase) {
    logFinest(logger, "Try remove classloaders for jobId=%s, phase=%s", idToString(jobId), phase);
    classLoaders.compute(jobId, (k, jobClassLoaders) -> {
        if (jobClassLoaders == null) {
            logger.warning("JobClassLoaders for jobId=" + idToString(jobId) + " already removed");
            return null;
        }
        int phaseCount = jobClassLoaders.removePhase(phase);
        if (phaseCount == 0) {
            logFinest(logger, "JobClassLoaders phaseCount = 0, removing classloaders for jobId=%s", idToString(jobId));
            Map<String, ClassLoader> processorCls = jobClassLoaders.processorCls();
            if (processorCls != null) {
                for (ClassLoader cl : processorCls.values()) {
                    try {
                        ((ChildFirstClassLoader) cl).close();
                    } catch (IOException e) {
                        logger.warning("Exception when closing processor classloader", e);
                    }
                }
            }
            // the class loader might not have been initialized if the job failed before that
            JetDelegatingClassLoader jobClassLoader = jobClassLoaders.jobClassLoader();
            jobClassLoader.shutdown();
            logFine(logger, "Finish JobClassLoaders phaseCount = 0," + " removing classloaders for jobId=%s", idToString(jobId));
            // Removes the item from the map
            return null;
        } else {
            logFinest(logger, "JobClassLoaders refCount > 0, NOT removing classloaders for jobId=%s", idToString(jobId));
            return jobClassLoaders;
        }
    });
}
Also used : JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) ChildFirstClassLoader(com.hazelcast.jet.impl.deployment.ChildFirstClassLoader) JetDelegatingClassLoader(com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader) ChildFirstClassLoader(com.hazelcast.jet.impl.deployment.ChildFirstClassLoader) JetClassLoader(com.hazelcast.jet.impl.deployment.JetClassLoader) Util.idToString(com.hazelcast.jet.Util.idToString) IOException(java.io.IOException)

Aggregations

JetDelegatingClassLoader (com.hazelcast.jet.impl.deployment.JetDelegatingClassLoader)3 Util.idToString (com.hazelcast.jet.Util.idToString)1 Vertex (com.hazelcast.jet.core.Vertex)1 ChildFirstClassLoader (com.hazelcast.jet.impl.deployment.ChildFirstClassLoader)1 JetClassLoader (com.hazelcast.jet.impl.deployment.JetClassLoader)1 ExecutionContext (com.hazelcast.jet.impl.execution.ExecutionContext)1 CustomClassLoadedObject.deserializeWithCustomClassLoader (com.hazelcast.jet.impl.execution.init.CustomClassLoadedObject.deserializeWithCustomClassLoader)1 Util.doWithClassLoader (com.hazelcast.jet.impl.util.Util.doWithClassLoader)1 IOException (java.io.IOException)1