Skip to content

Commit

Permalink
fix(sharding): fix parse sharding toml config failed (#381)
Browse files Browse the repository at this point in the history
Signed-off-by: wangbo <wangbo@sphere-ex.com>

Signed-off-by: wangbo <wangbo@sphere-ex.com>
Co-authored-by: wangbo <wangbo@sphere-ex.com>
  • Loading branch information
wbtlb and wangbo committed Nov 22, 2022
1 parent 1de659f commit f3fb9af
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pisa-proxy/proxy/strategy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,18 @@ pub struct Sharding {
pub database_table_strategy: Option<StrategyType>,
}

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

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -194,10 +198,10 @@ pub struct TableStrategyConfig {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DatabaseTableStrategyConfig {
pub database_sharding_algorithm_name: ShardingAlgorithmName,
pub table_sharding_algorithm_name: ShardingAlgorithmName,
pub database_sharding_column: String,
pub table_sharding_algorithm_name: ShardingAlgorithmName,
pub table_sharding_column: String,
pub shading_count: u32,
pub sharding_count: u32,
}

fn default_monitor_period() -> u64 {
Expand Down

0 comments on commit f3fb9af

Please sign in to comment.