Skip to content

Commit a13fdc2

Browse files
committed
rename func String() to ConfigString()
rename func String() to ConfigString()
1 parent 18831d4 commit a13fdc2

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

client/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (db *DB) Addr() string {
3636
return db.addr
3737
}
3838

39-
func (db *DB) String() string {
39+
func (db *DB) ConfigString() string {
4040
return fmt.Sprintf("%s:%s@%s/%s?idleConns=%v&conns=%v",
4141
db.user, db.password, db.addr, db.db, db.idleConns, db.conns.Len())
4242
}

proxy/conn_show.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,16 @@ func (c *Conn) handleShowProxyConfig() (*Resultset, error) {
109109
var names []string = []string{"Section", "Key", "Value"}
110110
var rows [][]string
111111
const (
112-
Section = 0
113-
Key = 1
114-
Value = 2
115-
Column = 3
112+
Column = 3
116113
)
117114

118115
rows = append(rows, []string{"Global_Config", "Addr", c.server.cfg.Addr})
119116
rows = append(rows, []string{"Global_Config", "User", c.server.cfg.User})
120117
rows = append(rows, []string{"Global_Config", "Password", c.server.cfg.Password})
121118
rows = append(rows, []string{"Global_Config", "LogLevel", c.server.cfg.LogLevel})
122-
123119
rows = append(rows, []string{"Global_Config", "Schemas_Count", fmt.Sprintf("%d", len(c.server.schemas))})
124120
rows = append(rows, []string{"Global_Config", "Nodes_Count", fmt.Sprintf("%d", len(c.server.nodes))})
125121

126-
// var row []string = make([]string, Column)
127-
128122
for db, schema := range c.server.schemas {
129123
rows = append(rows, []string{"Schemas", "DB", db})
130124

@@ -135,14 +129,14 @@ func (c *Conn) handleShowProxyConfig() (*Resultset, error) {
135129
var nodeSection = fmt.Sprintf("Schemas[%s]-Node[ %v ]", db, name)
136130

137131
if node.master != nil {
138-
nodeRows = append(nodeRows, []string{nodeSection, "Master", node.master.String()})
132+
nodeRows = append(nodeRows, []string{nodeSection, "Master", node.master.ConfigString()})
139133
}
140134
if node.masterBackup != nil {
141-
nodeRows = append(nodeRows, []string{nodeSection, "Master_Backup", node.masterBackup.String()})
135+
nodeRows = append(nodeRows, []string{nodeSection, "Master_Backup", node.masterBackup.ConfigString()})
142136
}
143137

144138
if node.slave != nil {
145-
nodeRows = append(nodeRows, []string{nodeSection, "Slave", node.slave.String()})
139+
nodeRows = append(nodeRows, []string{nodeSection, "Slave", node.slave.ConfigString()})
146140
}
147141
nodeRows = append(nodeRows, []string{nodeSection, "Last_Master_Ping", fmt.Sprintf("%v", time.Unix(node.lastMasterPing, 0))})
148142

@@ -152,7 +146,20 @@ func (c *Conn) handleShowProxyConfig() (*Resultset, error) {
152146

153147
}
154148
rows = append(rows, []string{fmt.Sprintf("Schemas[%s]", db), "Nodes_List", strings.Join(nodeNames, ",")})
155-
rows = append(rows, []string{fmt.Sprintf("Schemas[%s]", db), "Rule", schema.rule.String()})
149+
150+
var defaultRule = schema.rule.DefaultRule
151+
if defaultRule.DB == db {
152+
if defaultRule.DB == db {
153+
rows = append(rows, []string{fmt.Sprintf("Schemas[%s]_Rule_Default", db),
154+
"Default_Table", defaultRule.ConfigString()})
155+
}
156+
}
157+
for tb, r := range schema.rule.Rules {
158+
if r.DB == db {
159+
rows = append(rows, []string{fmt.Sprintf("Schemas[%s]_Rule_Table", db),
160+
fmt.Sprintf("Table[ %s ]", tb), r.ConfigString()})
161+
}
162+
}
156163

157164
for i := range nodeRows {
158165
rows = append(rows, nodeRows[i])

router/router.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ func (r *Rule) FindNodeIndex(key interface{}) int {
2727
}
2828

2929
func (r *Rule) String() string {
30-
return fmt.Sprintf("%s.%s(%s)?shard=%s", r.DB, r.Table, r.Key, r.Type)
30+
return fmt.Sprintf("%s.%s?key=%v&shard=%s", r.DB, r.Table, r.Key, r.Type)
31+
}
32+
33+
func (r *Rule) ConfigString() string {
34+
return fmt.Sprintf("%s.%s?key=%v&shard=%s&nodes=%s",
35+
r.DB, r.Table, r.Key, r.Type, strings.Join(r.Nodes, ", "))
3136
}
3237

3338
type DBRules struct {
3439
DB string
35-
Rules map[string]*Rule
40+
Rules map[string]*Rule //key is <table name>
3641
DefaultRule *Rule
3742
}
3843

@@ -57,12 +62,7 @@ func (r *DBRules) GetRule(table string) *Rule {
5762
}
5863

5964
func (r *DBRules) String() string {
60-
var rules []string
61-
62-
for _, rule := range r.Rules {
63-
rules = append(rules, rule.String())
64-
}
65-
return strings.Join(rules, "; ")
65+
return r.DB
6666
}
6767

6868
type Router struct {

0 commit comments

Comments
 (0)