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 StatisticsRefreshEngine Refresh

From Leeroopedia
Revision as of 14:24, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Apache_Shardingsphere_StatisticsRefreshEngine_Refresh.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

Overview

StatisticsRefreshEngine orchestrates statistics collection across all databases, schemas, and tables with support for asynchronous execution in cluster mode.

Description

StatisticsRefreshEngine is a final class that uses a ContextManager to traverse the metadata hierarchy and collect statistics. The asyncRefresh method submits refresh work to a single-threaded executor if the instance type is PROXY. The refresh method checks if metadata collection is enabled via TemporaryConfigurationPropertyKey.PROXY_META_DATA_COLLECTOR_ENABLED, then uses the ExclusiveOperatorEngine with a 5-second timeout to ensure only one node collects at a time. It iterates through databases, schemas, and tables, using DialectDatabaseStatisticsCollector (or ShardingSphereStatisticsCollector for the "shardingsphere" schema) to collect row/column values. Collected data is passed to StatisticsStorageEngine for diff-based persistence. After collection, it cleans up statistics for databases that no longer exist in the metadata.

Usage

Use this engine in cluster mode to trigger statistics collection. It is invoked after database lifecycle events (creation/dropping) and can be called for periodic refresh. Only PROXY instances participate in statistics collection.

Code Reference

Source Location

Signature

@RequiredArgsConstructor
@Slf4j
public final class StatisticsRefreshEngine {

    public StatisticsRefreshEngine(final ContextManager contextManager)

    public void asyncRefresh()

    public void refresh()
}

Import

import org.apache.shardingsphere.mode.manager.cluster.statistics.StatisticsRefreshEngine;

I/O Contract

Inputs

Name Type Required Description
contextManager ContextManager Yes Provides access to metadata, statistics, persist facade, and exclusive operator

Outputs

Name Type Description
void void Side effects: collects statistics from databases and persists diff-based updates; cleans up stale data

Usage Examples

// Trigger asynchronous statistics refresh (only executes on PROXY instances)
StatisticsRefreshEngine engine = new StatisticsRefreshEngine(contextManager);
engine.asyncRefresh();

// Trigger synchronous refresh (used internally)
engine.refresh();

Related Pages

Page Connections

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