System Views, also known as virtual tables, is a powerful tool that is meant to expose the system's state and provide real-time insights into its various components.
This module provides an abstraction and core interfaces for the Ignite system views.
SystemViews
provides static factory methods for system view builders.SystemView
is a base class for system view definitions.ClusterSystemView
represents cluster-wide view definition. This type of view is used to expose the data from a common source, like distributed meta storage, table, or anything, so every node will provide the same copy of dataset. Use SystemViews.clusterViewBuilder()
to create this type of view.NodeSystemView
represents node view definition. This type of view is used to expose data that is unique to a particular node, and can be acquired only on the node itself. Note that a special column containing local node name always implicitly added to the local view. The name of this column must be set explicitly using the nodeNameColumnAlias
builder method. Use SystemViews.nodeViewBuilder()
to create this type of view.SystemViewProvider
denotes a component that provides system views.SystemViewManager
is responsible for views registration in the cluster.SystemViewProvider
interface.IgniteImpl
constructor is currently used as a starting point to do this.SYSTEM
schema.SYSTEM_VIEWS
may be used to obtain a list of all system views registered in the cluster.To register a system view, you need to complete three steps.
SystemViewProvider
Any component that wants to register system views must implement SystemViewProvider
interface with single systemViews()
method, which simply returns a list of system views. The next step provides an example of the implementation of this method.
For example we want to add a view representing actual cluster topology. Since this information can be obtained on any node in the cluster this should be a ClusterSystemView
, but to understand the difference between cluster-wide and local view, let's also add exactly the same local view (NodeSystemView
). The only difference is that we have to set nodeNameColumnAlias
for the local view.
Please note that we explicitly specify the generic type of the column. It is a good practice to detect the column type mismatch at compile time.
@Override public List<SystemView<?>> systemViews() { SystemView<ClusterNode> clusterWideView = SystemViews.<ClusterNode>clusterViewBuilder() .name("TOPOLOGY_SNAPSHOT") .<String>addColumn("NAME", NativeTypes.STRING, ClusterNode::name) .<String>addColumn("HOST", NativeTypes.STRING, node -> node.address().host()) .<Integer>addColumn("PORT", NativeTypes.INT32, node -> node.address().port()) .dataProvider(SubscriptionUtils.fromIterable(() -> ignite.clusterNodes().iterator())) .build(); SystemView<ClusterNode> localView = SystemViews.<ClusterNode>nodeViewBuilder() .name("TOPOLOGY_SNAPSHOT_LOCAL_VIEW") .nodeNameColumnAlias("VIEW_DATA_SOURCE") .<String>addColumn("NAME", NativeTypes.STRING, ClusterNode::name) .<String>addColumn("HOST", NativeTypes.STRING, node -> node.address().host()) .<Integer>addColumn("PORT", NativeTypes.INT32, node -> node.address().port()) .dataProvider(SubscriptionUtils.fromIterable(() -> ignite.iterator())) .build(); return List.of(clusterWideView, localView); }
Component SystemViewManager
is responsible for views registration in the system. Currently there is no automatic registration of system components views, so we need to do it manually.
MyComponent component = new MyComponent(); systemViewManager.register(component);
Please note that this must be done before systemViewManager
starts.
After these steps, we can start the cluster and start working with the system views we just created.
Note that the list of registered views can be obtained using the SYSTEM_VIEWS
view.
select * from system.system_views order by id
ID | SCHEMA | NAME | TYPE |
---|---|---|---|
3 | SYSTEM | SYSTEM_VIEWS | CLUSTER |
4 | SYSTEM | SYSTEM_VIEW_COLUMNS | CLUSTER |
5 | SYSTEM | TOPOLOGY_SNAPSHOT | CLUSTER |
6 | SYSTEM | TOPOLOGY_SNAPSHOT_LOCAL_VIEW | NODE |
select * from system.topology_snapshot
host | address | port |
---|---|---|
isvt_n_0 | 192.168.0.103 | 3344 |
isvt_n_1 | 192.168.0.103 | 3345 |
isvt_n_2 | 192.168.0.103 | 3346 |
For a cluster-wide system view, the data is retrieved on one of the nodes on which the view was registered.
select * from system.topology_snapshot_local_view
view_data_source | host | address | port |
---|---|---|---|
isvt_n_0 | isvt_n_0 | 192.168.0.103 | 3344 |
isvt_n_0 | isvt_n_1 | 192.168.0.103 | 3345 |
isvt_n_0 | isvt_n_2 | 192.168.0.103 | 3346 |
isvt_n_2 | isvt_n_0 | 192.168.0.103 | 3344 |
isvt_n_2 | isvt_n_1 | 192.168.0.103 | 3345 |
isvt_n_2 | isvt_n_2 | 192.168.0.103 | 3346 |
isvt_n_1 | isvt_n_0 | 192.168.0.103 | 3344 |
isvt_n_1 | isvt_n_1 | 192.168.0.103 | 3345 |
isvt_n_1 | isvt_n_2 | 192.168.0.103 | 3346 |
Since the local cluster includes 3 nodes, the data is duplicated three times. Because for a local view, data is retrieved on each node where the view is registered.