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 shadow config #303

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ data:
password: "123456"
database: employees_0000_r
weight: r0w0
parameters:
- name: employees_0001
nodes:
- name: node1
Expand All @@ -70,7 +69,6 @@ data:
password: "123456"
database: employees_0001
weight: r10w10
parameters:
- name: employees_0002
nodes:
- name: node2
Expand All @@ -80,7 +78,6 @@ data:
password: "123456"
database: employees_0002
weight: r10w10
parameters:
- name: employees_0003
nodes:
- name: node3
Expand All @@ -90,7 +87,15 @@ data:
password: "123456"
database: employees_0003
weight: r10w10
parameters:
- name: employees_shadow
nodes:
- name: node_shadow
host: arana-mysql
port: 3306
username: root
password: "123456"
database: employees_show
weight: r10w10
sharding_rule:
tables:
- name: employees.student
Expand All @@ -109,3 +114,24 @@ data:
tbl_pattern: student_${0000..0031}
attributes:
sqlMaxLimit: -1

shadow_rule:
tables:
- name: student
enable: false
group_node: employees_shadow
match_rules:
- operation: [insert,update]
match_type: value
attributes:
- column: uid
value: 10000
- operation: [delete]
match_type: regex
attributes:
- column: name
regex: "^hanmeimei$"
- operation: [select]
match_type: hint
attributes:
- shadow: true
31 changes: 31 additions & 0 deletions pkg/config/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type (
Tenants []*Tenant `validate:"required,dive" yaml:"tenants" json:"tenants"`
DataSourceClusters []*DataSourceCluster `validate:"required,dive" yaml:"clusters" json:"clusters"`
ShardingRule *ShardingRule `validate:"required,dive" yaml:"sharding_rule,omitempty" json:"sharding_rule,omitempty"`
ShadowRule *ShadowRule `yaml:"shadow_rule,omitempty" json:"shadow_rule,omitempty"`
}

Filter struct {
Expand Down Expand Up @@ -110,6 +111,36 @@ type (
Tables []*Table `yaml:"tables" json:"tables"`
}

ShadowRule struct {
ShadowTables []*ShadowTable `yaml:"tables" json:"tables"`
}

ShadowTable struct {
Name string `yaml:"name" json:"name"`
Enable bool `yaml:"enable" json:"enable"`
GroupNode string `yaml:"group_node" json:"group_node"`
MatchRules []*MatchRule `yaml:"match_rules" json:"match_rules"`
}

MatchRule struct {
Operation []string `yaml:"operation" json:"operation"`
MatchType string `yaml:"match_type" json:"match_type"`
Attributes []*RuleAttribute `yaml:"attributes" json:"attributes"`
}

RuleAttribute struct {
Column string `yaml:"column" json:"column"`
Value string `yaml:"value,omitempty" json:"value,omitempty"`
Regex string `yaml:"regex,omitempty" json:"regex,omitempty"`
}

Prop struct {
Operation string `yaml:"operation" json:"operation"`
Column string `yaml:"column" json:"column"`
Value string `yaml:"value" json:"value"`
Regex string `yaml:"regex" json:"regex"`
}

Listener struct {
ProtocolType string `yaml:"protocol_type" json:"protocol_type"`
SocketAddress *SocketAddress `yaml:"socket_address" json:"socket_address"`
Expand Down