<commit_before>+++
toc = true
title = "Configuration"
weight = 3
+++

## Sharding Rule

Main entrance of sharding configuration. Includes data sources configurations, tables configurations, binding tables configurations and master-slave configurations.

## Data Sources Configurations

Physical data sources list.

## Tables Configurations

Configure logic table, data nodes and sharding strategies.

## Data Node Configurations

Configure relationship mapping with logic table and actual data nodes, can use uniform distribution or user-defined distribution.

- Uniform Distribution

Tables are evenly distributed in each data source, for example: 

```
db0
  ├── t_order0 
  └── t_order1 
db1
  ├── t_order0 
  └── t_order1
```

Then, configuration of data nodes are: 

```
db0.t_order0, db0.t_order1, db1.t_order0, db1.t_order1
```

- User-defined Distribution

Tables are distributed by user defined in each data source, for example: 

```
db0
  ├── t_order0 
  └── t_order1 
db1
  ├── t_order2
  ├── t_order3
  └── t_order4
```

Then, configuration of data nodes are: 

```
db0.t_order0, db0.t_order1, db1.t_order2, db1.t_order3, db1.t_order4
```

## Sharding Strategies Configurations

Include database sharding strategy and table sharding strategy. API of them are same.

## Key Generator Strategy Configurations

Generate distribute unique primary keys by this.

## Config Map

ConfigMap allows user to configure metadata information for data source of Sharding. The information of shardingConfig in ConfigMap can be obtained by calling ConfigMapContext.getInstance (). e.g. Different weight for machines, different traffic on machines. The metadata for machines' weight can be configured through the ConfigMap.<commit_msg>update configuration.en<commit_after>+++
toc = true
title = "Configuration"
weight = 3
+++

## Sharding Rule

The main entrance for Sharding rules includes the configurations of data source, tables, binding tables and read-write split.

## Data Sources Configuration

Real data sources list.

## Tables Configuration

Configurations of logic table names, data node and table sharding rules.

## Data Node Configuration

It is used in the configurations of the mapping relationship between logic tables and actual tables, can be divided into two kinds: uniform distribution and user-defined distribution.

- Uniform Distribution

It means that data tables are evenly distributed in each data source, for example: 

```
db0
  ├── t_order0 
  └── t_order1 
db1
  ├── t_order0 
  └── t_order1
```

So the data node configurations will be as follow:

```
db0.t_order0, db0.t_order1, db1.t_order0, db1.t_order1
```

- User-defined Distribution

It means that data tables are distributed with certain rules, for example:

```
db0
  ├── t_order0 
  └── t_order1 
db1
  ├── t_order2
  ├── t_order3
  └── t_order4
```

So the data node configurations will be as follow:

```
db0.t_order0, db0.t_order1, db1.t_order2, db1.t_order3, db1.t_order4
```

## Sharding Strategy Configuration

There are two dimensions of sharding strategies, database sharding and table sharding.

- Database Sharding Strategy

`DatabaseShardingStrategy` is used to configure data in the targeted database.

- Table Sharding Strategy

`TableShardingStrategy` is used to configure data in the targeted table that exists in the database. 
So the table sharding strategy relies on the result of the database sharding strategy.

API of those two kinds of strategies are totally same.

## Generation Strategy of Auto-increment Key

Replacing the original database auto-increment key with that generated in the server can make distributed key not repeat.

## Config Map

When configuring the metadata from the source of sharding databases and tables, `ConfigMapContext.getInstance()` can be used to acquire shardingConfig data in ConfigMap. 
For instance, machines of different weight may have different data traffic and `ConfigMap` can be used to set the metadata.
{'fraction_non_alphanumeric': 0.06902654867256637, 'fraction_numerical': 0.01618204804045512, 'mean_word_length': 4.571830985915493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4741573', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1102, 'n_words': 498}