Skip to content

Commit f3fb9af

Browse files
wbtlbwangbo
andauthored
fix(sharding): fix parse sharding toml config failed (#381)
Signed-off-by: wangbo <wangbo@sphere-ex.com> Signed-off-by: wangbo <wangbo@sphere-ex.com> Co-authored-by: wangbo <wangbo@sphere-ex.com>
1 parent 1de659f commit f3fb9af

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pisa-proxy/proxy/strategy/src/config.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,18 @@ pub struct Sharding {
155155
pub database_table_strategy: Option<StrategyType>,
156156
}
157157

158+
// There is no explicit tag identifying which variant the data contains.
159+
// Serde will try to match the data against each variant in order and the first one that deserializes successfully is the one returned.
160+
// Refrence Link: https://serde.rs/enum-representations.html
161+
// DatabaseTableStrategyConfig struct must be guaranteed to be matched firstly
158162
#[derive(Debug, Serialize, Deserialize, Clone)]
159163
#[serde(untagged)]
160164
pub enum StrategyType {
165+
DatabaseTableStrategyConfig(DatabaseTableStrategyConfig),
161166
DatabaseStrategyConfig(DatabaseStrategyConfig),
162-
DatabaseStrategyInline(StrategyInline),
163167
TableStrategyConfig(TableStrategyConfig),
168+
DatabaseStrategyInline(StrategyInline),
164169
TableStrategyInline(StrategyInline),
165-
DatabaseTableStrategyConfig(DatabaseTableStrategyConfig),
166170
}
167171

168172
#[derive(Debug, Serialize, Deserialize, Clone)]
@@ -194,10 +198,10 @@ pub struct TableStrategyConfig {
194198
#[derive(Debug, Serialize, Deserialize, Clone)]
195199
pub struct DatabaseTableStrategyConfig {
196200
pub database_sharding_algorithm_name: ShardingAlgorithmName,
197-
pub table_sharding_algorithm_name: ShardingAlgorithmName,
198201
pub database_sharding_column: String,
202+
pub table_sharding_algorithm_name: ShardingAlgorithmName,
199203
pub table_sharding_column: String,
200-
pub shading_count: u32,
204+
pub sharding_count: u32,
201205
}
202206

203207
fn default_monitor_period() -> u64 {

0 commit comments

Comments
 (0)