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 StatisticsChangedHandler Handle

From Leeroopedia


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

Overview

StatisticsChangedHandler hierarchically processes statistics change events at database, schema, table, and row levels from cluster registry events.

Description

StatisticsChangedHandler implements GlobalDataChangedEventHandler and subscribes to StatisticsDatabaseNodePath for ADDED, UPDATED, and DELETED events. The handle method performs a cascading path resolution: it first attempts to match a database-level path, then schema-level, then table-level, and finally row-level. At each level, it delegates to the corresponding method on StatisticsManager -- adding or dropping database/schema/table statistics on ADDED/UPDATED vs DELETED events. For row-level changes, it deserializes YamlRowStatistics from the event value on ADDED/UPDATED events and calls alterRowStatistics, or calls deleteRowStatistics on DELETED events.

Usage

This handler is auto-loaded via SPI in cluster mode. It ensures that statistics changes persisted by any cluster node are propagated to all other nodes' in-memory StatisticsManager, keeping the statistics view consistent across the cluster.

Code Reference

Source Location

Signature

public final class StatisticsChangedHandler 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.statistics.StatisticsChangedHandler;

I/O Contract

Inputs

Name Type Required Description
contextManager ContextManager Yes Provides access to StatisticsManager via MetaDataContextManager
event DataChangedEvent Yes Contains the statistics path key, value (YAML for row data), and event type

Outputs

Name Type Description
void void Side effects: adds/drops/alters statistics at the appropriate hierarchy level

Usage Examples

// The handler automatically processes events at different levels:
// Database level: adds or drops DatabaseStatistics
// Schema level: adds or drops SchemaStatistics
// Table level: adds or drops TableStatistics
// Row level: alters or deletes individual RowStatistics from YamlRowStatistics

Related Pages

Page Connections

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