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 StatisticsManager Manage

From Leeroopedia


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

Overview

Synchronized manager for in-memory statistics data at database, schema, table, and row levels.

Description

StatisticsManager manages the lifecycle of statistics data held in ShardingSphereStatistics. It provides synchronized methods to add and drop database, schema, and table statistics, as well as alter and delete individual row statistics using YamlRowStatistics. All operations atomically update the statistics within MetaDataContexts.

Usage

Accessed via MetaDataContextManager.getStatisticsManager() to apply statistics changes triggered by cluster events or local operations.

Code Reference

Source Location

Signature

@RequiredArgsConstructor
public final class StatisticsManager {

    private final MetaDataContexts metaDataContexts;

    public synchronized void addDatabase(String databaseName);
    public synchronized void dropDatabase(String databaseName);
    public synchronized void addSchema(String databaseName, String schemaName);
    public synchronized void dropSchema(String databaseName, String schemaName);
    public synchronized void addTable(String databaseName, String schemaName, String tableName);
    public synchronized void dropTable(String databaseName, String schemaName, String tableName);
    public synchronized void alterRowData(String databaseName, String schemaName, String tableName,
        String uniqueKey, YamlRowStatistics yamlRowStatistics);
    public synchronized void deleteRowData(String databaseName, String schemaName, String tableName,
        String uniqueKey);
}

Import

import org.apache.shardingsphere.mode.metadata.manager.statistics.StatisticsManager;

I/O Contract

Inputs

Name Type Required Description
databaseName String Yes Target database
schemaName String Varies Target schema
tableName String Varies Target table
uniqueKey String Varies Row unique identifier
yamlRowStatistics YamlRowStatistics Varies Row data to alter

Outputs

Name Type Description
void Side effect: updates in-memory statistics

Usage Examples

StatisticsManager manager = metaDataContextManager.getStatisticsManager();

// Track a new database in statistics
manager.addDatabase("my_database");
manager.addSchema("my_database", "public");
manager.addTable("my_database", "public", "t_order");

// Alter row data
manager.alterRowData("my_database", "public", "t_order", "row_1", yamlRow);

Related Pages

Page Connections

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