Implementation:Apache Shardingsphere MetaDataContexts Container
| Knowledge Sources | |
|---|---|
| Domains | Mode_Management, Metadata |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Thread-safe container holding the runtime metadata and statistics contexts for a ShardingSphere instance.
Description
MetaDataContexts wraps ShardingSphereMetaData and ShardingSphereStatistics in AtomicReference objects for thread-safe access. It provides atomic update methods for both metadata and statistics, used throughout the ShardingSphere runtime when configurations change or metadata is refreshed.
Usage
This is the central runtime state object accessed by all components. It is created during context initialization and updated atomically when rule configurations, schemas, or statistics change.
Code Reference
Source Location
- Repository: Apache_Shardingsphere
- File: MetaDataContexts.java
- Lines: 1-81
Signature
public final class MetaDataContexts {
private final AtomicReference<ShardingSphereMetaData> metaData;
private final AtomicReference<ShardingSphereStatistics> statistics;
public MetaDataContexts(ShardingSphereMetaData metaData, ShardingSphereStatistics statistics);
public ShardingSphereMetaData getMetaData();
public ShardingSphereStatistics getStatistics();
public void update(ShardingSphereMetaData metaData);
public void update(ShardingSphereStatistics statistics);
}
Import
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| metaData | ShardingSphereMetaData | Yes | Runtime metadata (databases, rules, props) |
| statistics | ShardingSphereStatistics | Yes | Runtime statistics data |
Outputs
| Name | Type | Description |
|---|---|---|
| getMetaData() | ShardingSphereMetaData | Current metadata reference |
| getStatistics() | ShardingSphereStatistics | Current statistics reference |
Usage Examples
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
// Created during initialization
MetaDataContexts contexts = new MetaDataContexts(metaData, statistics);
// Thread-safe read
ShardingSphereMetaData currentMeta = contexts.getMetaData();
// Atomic update after rule change
contexts.update(newMetaData);