Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(strategy): dynamic read write splitting #194

Closed
9 tasks done
wbtlb opened this issue Jul 19, 2022 · 1 comment · Fixed by #204
Closed
9 tasks done

feat(strategy): dynamic read write splitting #194

wbtlb opened this issue Jul 19, 2022 · 1 comment · Fixed by #204
Assignees
Labels
app:pisa-proxy Pisa-Proxy related changes in:strategy Strategy related changes
Milestone

Comments

@wbtlb
Copy link
Contributor

wbtlb commented Jul 19, 2022

Development Task

Description

Now,Pisa-Proxy has supported static read write splitting strategy. Static strategy depends on config, once datasource status is changed, Pisa-Proxy can't route SQL correctly. In dynamic read write splitting strategy, Pisa-Proxy will probe datasource status and reconcile loadbalance strategy dynamicly.

Implement

In this version, Pisa-proxy will support MHA high availability strategy. Pisa-Proxy will spawn four kind of monitor to probe the status of datasource.The rules match module will fork a thread to recive loadbalance strategy from dynamic read write splitting module by channel.In this module, there are four kind of monitor to probe datasource status.

  • Connect Monitor: probe the connectivity of datasource.
  • Ping Monitor: probe health status of datasource.
  • Lag Monitor: probe the late time between master node and slave node.
  • ReadOnly Monitor: probe the role of datasource.

Future Design Chart

image

Glossary

  • Monitor Reconcile: Monitor Reconcile. Get status from monitors and compute final read write splitting strategy.
  • Discovery: The kind of discovery, like MHA,RDS,MGR etc.
  • Monitor: The kind of Monitor, includes Connect Monitor, Ping Monitor, ReadOnly Monitor, Lag Monitor.

Probe Flow

  1. Start Monitor to probe datasource.
  2. Probe the connectivity of Master node and Slave node.
  3. If connectivity is ok.
    3.1. probe the role of datasource.
    3.2. probe the late time between master node and slave node.
    3.2.1. If slave node is not late from master node, enter next time probe.
    3.2.2. If slave node is late from master node, update the list of loadbalance and enter next time probe.
  4. If connectivity is not ok.
    4.1. If probe slave change to master,start Lag probe.
    4.1.1. If slave node is not late from master node, enter next time probe.
    4.1.2. If slave node is late from master node, update the list of loadbalance and enter next time probe.
    4.2.If slave node is not change to master, enter next time probe.

image

Configuration

param type required default description
user string yes None Monitor user name
password string yes None Monitor password
monitor_period u64 yes 1000 The interval of Reconcile Monitor update strategy(millisecond)
connect_period u64 yes 1000 The interval of Connect Monitor probe (millisecond)
connect_timeout u64 yes 6000 The timeout of Connect Monitor(millisecond)
connect_failure_threshold u64 yes 3 The max failures times of Connect Monitor probe
ping_period u64 yes 1000 The interval of Ping Monitor probe(millisecond)
ping_timeout u64 yes 6000 The timeout of Ping Monitor probe(millisecond)
ping_failure_threshold u64 yes 3 The max failures times of Ping Monitor probe
replication_lag_period u64 yes 1000 The interval of Lag Monitor probe(millisecond)
replication_lag_timeout u64 yes 6000 The timeout of Lag Monitor probe(millisecond)
replication_lag_failure_threshold u64 yes 3 The max failures of Lag Monitor probe
max_replication_lag u64 yes 10000 The threshold of Lag Monitor probe(millisecond)
read_only_period u64 yes 1000 The interval of ReadOnly Monitor probe(millisecond)
read_only_timeout u64 yes 6000 The timeout of ReadOnly Monitor probe(millisecond)
read_only_failure_threshold u64 yes 3 The max failures times of ReadOnly Monitor probe

Configuration

Configuration Structure
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ReadWriteSplitting {
    #[serde(rename = "static")]
    pub statics: Option<ReadWriteSplittingStatic>,
    pub dynamic: Option<ReadWriteSplitting>
}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ReadWriteSplittingDynamic {
    pub default_target: TargetRole,
    #[serde(rename = "rule")]
    pub rules: Vec<ReadWriteSplittingRule>,
    pub discovery: Discovery,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase", tag="type")]
pub enum Discovery {
    Mha(MasterHighAvailability),
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct MasterHighAvailability {
    pub user: String,
    pub password: String,
    pub pool_size: Option<u8>,
    pub monitor_period: u64,
    pub connect_period: u64,
    pub connect_timeout: u64,
    pub connect_failure_threshold: u64,
    pub ping_period: u64,
    pub ping_timeout: u64,
    pub ping_failure_threshold: u64,
    pub replication_lag_period: u64,
    pub replication_lag_timeout: u64,
    pub replication_lag_failure_threshold: u64,
    pub max_replication_lag: u64,
    pub read_only_period: u64,
    pub read_only_timeout: u64,
    pub read_only_failure_threshold: u64,
}
Configuration Example
[proxy.config.read_write_splitting]

[proxy.config.read_write_splitting.dynamic]
default_target = "readwrite"

[proxy.config.read_write_splitting.dynamic.discovery]
type = "mha"
user = "monitor"
password = "monitor"
pool_size = 16
monitor_period = 1000
connect_period = 2000
connect_timeout = 200
connect_failure_threshold = 3
ping_period = 1000
ping_timeout = 100
ping_failure_threshold = 3
replication_lag_period = 1000
replication_lag_timeout = 3
replication_lag_failure_threshold = 3
max_replication_lag = 3
read_only_period = 1000
read_only_timeout = 3
read_only_failure_threshold = 3

[[proxy.config.read_write_splitting.dynamic.rule]]
name = "write-rule"
type = "regex"
regex = ["^insert"]
target = "readwrite"
algorithm_name = "roundrobin"

[[proxy.config.read_write_splitting.dynamic.rule]]
name = "read-rule"
type = "regex"
regex = ["^select"]
target = "read"
algorithm_name = "roundrobin"

Check List

  • Monitor Reconcile.
  • configuration.
  • Pisa-Controller. @mlycore
  • Rules Match dynamic update.
  • Connect Monitor.
  • Ping Monitor.
  • Lag Monitor.
  • ReadOnly Monitor.
  • com query raw parse. @xuanyuan300

Association Issue #88

@wbtlb wbtlb added the app:pisa-proxy Pisa-Proxy related changes label Jul 19, 2022
@wbtlb wbtlb added this to the v0.2.0 milestone Jul 19, 2022
@wbtlb wbtlb self-assigned this Jul 19, 2022
@wbtlb wbtlb added the in:strategy Strategy related changes label Jul 19, 2022
@mlycore
Copy link
Member

mlycore commented Jul 25, 2022

For better understanding, we should use period instead of interval, using failureThreshold instead of MaxFailures`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app:pisa-proxy Pisa-Proxy related changes in:strategy Strategy related changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants