Implementation:Apache Shardingsphere StatisticsStorageEngine Store
| Knowledge Sources | |
|---|---|
| Domains | Cluster, Statistics |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
StatisticsStorageEngine computes row-level statistics differences between current and changed data and persists the adds, updates, and deletes.
Description
StatisticsStorageEngine is a final class constructed with a ContextManager, database name, schema name, table name, and a collection of new row/column values. The storage method retrieves the current table schema, creates RowStatistics from the new values using RowStatisticsCollectorUtils, and compares them against the current statistics obtained from the ShardingSphereStatistics hierarchy. It produces an AlteredDatabaseStatistics containing three lists: added rows (keys present in changed but not current), updated rows (keys present in both but with different values), and deleted rows (keys present in current but not changed). The diff is serialized via YamlRowStatisticsSwapper and persisted through StatisticsPersistService.update.
Usage
Use this engine when new statistics data has been collected for a specific table and needs to be diff-merged into the persistent store. It is called by StatisticsRefreshEngine after collecting row/column values from a DialectDatabaseStatisticsCollector.
Code Reference
Source Location
- Repository: Apache_Shardingsphere
- File: StatisticsStorageEngine.java
- Lines: 1-103
Signature
@RequiredArgsConstructor
public final class StatisticsStorageEngine {
public StatisticsStorageEngine(final ContextManager contextManager,
final String databaseName, final String schemaName,
final String tableName,
final Collection<Map<String, Object>> rowColumnValues)
public void storage()
}
Import
import org.apache.shardingsphere.mode.manager.cluster.statistics.StatisticsStorageEngine;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| contextManager | ContextManager | Yes | Provides access to database metadata, statistics, and persist facade |
| databaseName | String | Yes | Target database name |
| schemaName | String | Yes | Target schema name |
| tableName | String | Yes | Target table name |
| rowColumnValues | Collection<Map<String, Object>> | Yes | Newly collected row data as column name-value maps |
Outputs
| Name | Type | Description |
|---|---|---|
| void | void | Side effects: persists added, updated, and deleted row statistics to the repository |
Usage Examples
// After collecting row/column values from a statistics collector:
Collection<Map<String, Object>> rowColumnValues = collector.collectRowColumnValues(
databaseName, schemaName, tableName, metaData).orElse(Collections.emptyList());
// Create the storage engine and persist the diff
new StatisticsStorageEngine(contextManager, databaseName, schemaName, tableName, rowColumnValues)
.storage();