1. Data Source datasource
The datasource of cobarclient is divided into three layers.
Icobardatasourceservice: encapsulates multiple performancedescriptor and ihadatasourcecreator encapsulated by HA.
Datasourcedescriptor: encapsulates identity, primary targetdatasource, and standby standbydatasource.
Datasource: actual database datasource
2. Router
The routing rule of cobarclient depends on ibatis. It is mainly determined by the sqlmap ID and the route field, for example
<rules> <rule> <namespace>com.alibaba.cobar.client.entities.Offer</namespace> <shardingExpression>mod.apply(memberId)==1</shardingExpression> <shards>partition1</shards> </rule> <rule> <namespace>com.alibaba.cobar.client.entities.Offer</namespace> <shardingExpression>mod.apply(memberId)==2</shardingExpression> <shards>partition2</shards> </rule></rules>
For SQL statements whose namespace is offline in sqlmap, Shard is obtained based on the memberid field of the parameter. Shard is the identity of performancedescriptor.
3. Ha
The HA of cobarclient is divided into active and passive modes. The active mode is enabled by default, that is, to open a thread to regularly detect whether the master data source is available. If not, switch to the standby data source, that is, the master and slave data sources of performancedescriptor are switched.
The passive mode is disabled by default. The Passive mode is to check before each query. This will reduce the efficiency. If the check fails, the active/standby mode will be switched.
4. Data Aggregation
Data aggregation mainly depends on manual aggregation after the client query, such
select count(*), companyId from offer group by companyId
The SQL statement is executed on multiple data sources, and multiple result sets are returned. Finally, the companyid is manually aggregated by the user.
Cobar-client implementation policy summary