Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Shardingsphere KillProcessHandler Handle

From Leeroopedia


Knowledge Sources
Domains Cluster, Process_Management
Last Updated 2026-02-10 00:00 GMT

Overview

KillProcessHandler handles distributed kill process events by extracting instance and process IDs from node paths and delegating to ProcessRegistry for execution.

Description

KillProcessHandler implements GlobalDataChangedEventHandler and subscribes to KillProcessTriggerNodePath for ADDED and DELETED event types. On an ADDED event, it extracts the instance ID and process ID from the event path using NodePathSearcher. If the instance ID matches the local instance, it calls ProcessRegistry.kill(processId) to terminate the SQL process and then cleans up the trigger path via ClusterProcessPersistCoordinator. On a DELETED event, it notifies the ProcessOperationLockRegistry to release any waiting locks for the process ID. SQL exceptions during kill are wrapped in SQLWrapperException.

Usage

This handler is loaded via SPI as a GlobalDataChangedEventHandler in cluster mode. It is triggered when a KILL PROCESS command is issued on any cluster node, which persists a trigger path that all nodes watch. Only the node whose instance ID matches will execute the actual kill.

Code Reference

Source Location

Signature

public final class KillProcessHandler implements GlobalDataChangedEventHandler {

    public NodePath getSubscribedNodePath()

    public Collection<Type> getSubscribedTypes()

    public void handle(final ContextManager contextManager, final DataChangedEvent event)
}

Import

import org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.node.process.KillProcessHandler;

I/O Contract

Inputs

Name Type Required Description
contextManager ContextManager Yes Provides access to instance context and persist services
event DataChangedEvent Yes Contains the event key (path), value, and type (ADDED/DELETED)

Outputs

Name Type Description
void void Side effects: kills SQL process on matching instance, cleans trigger path, or notifies lock

Usage Examples

// This handler is auto-loaded via SPI. Trigger a kill by persisting to the trigger path:
String triggerPath = NodePathGenerator.toPath(
    new KillProcessTriggerNodePath(new InstanceProcessNodeValue(instanceId, processId)));
repository.persist(triggerPath, "");
// The KillProcessHandler on the target instance will pick up the ADDED event and kill the process.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment