Table Sharding
The sharding of stored data is essential to any distributed database. This document will describe how table's data in GreptimeDB is being sharded, and distributed.
Partition
For the syntax of creating a partitioned table, please refer to the Table Sharding section in the User Guide.
Region
The data within a table is logically split after creating partitions. You may ask the question "
how are the data, after being logically partitioned, stored in the GreptimeDB? The answer is in "Region
"s.
Each region is corresponding to a partition, and stores the data in the partition. The regions are distributed among
Datanode
s. Our
metasrv
will move regions among Datanodes automatically, according to the states of Datanodes.
Also, metasrv
can split or merge regions according to their data volume or access pattern.
The relationship between partition and region can be viewed as the following diagram:
┌───────┐
│ │
│ Table │
│ │
└─── ┬───┘
│
Range [Start, end) │ Horizontally Split Data
┌──────────────────┼──────────────────┐
│ │ │
│ │ │
┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼─────┐
│ │ │ │ │ │
│ Partition │ │ Partition │ │ Partition │
│ │ │ │ │ │
│ P0 │ │ P1 │ │ Px │
└─────┬─────┘ └─────┬─────┘ └─────┬─────┘
│ │ │
│ │ │ One-to-one mapping of
┌───────┼──────────────────┼───────┐ │ Partition and Region
│ │ │ │ │
│ ┌─────▼─────┐ ┌─────▼─────┐ │ ┌─────▼─────┐
│ │ │ │ │ │ │ │
│ │ Region │ │ Region │ │ │ Region │
│ │ │ │ │ │ │ │
│ │ R0 │ │ R1 │ │ │ Ry │
│ └───────────┘ └───────────┘ │ └───────────┘
│ │
└──────────────────────────────────┘
Could be placed in one Datanode