@@ -123,49 +123,45 @@ func portInUse(hostPort string) bool {
123
123
return false
124
124
}
125
125
126
- func getPortOrDefault (cfg mysql.ListenerConfig ) int64 {
127
- // TODO read this value from systemVars (different in postgres)
128
- defaultPort := int64 (3606 )
126
+ func getPort (cfg mysql.ListenerConfig ) (int64 , error ) {
129
127
_ , port , err := net .SplitHostPort (cfg .Listener .Addr ().String ())
130
128
if err != nil {
131
- return defaultPort
129
+ return 0 , err
132
130
}
133
131
portInt , err := strconv .ParseInt (port , 10 , 64 )
134
132
if err != nil {
135
- return defaultPort
133
+ return 0 , err
136
134
}
137
- return portInt
135
+ return portInt , nil
138
136
}
139
137
140
138
func updateSystemVariables (cfg mysql.ListenerConfig ) error {
141
- port := getPortOrDefault (cfg )
139
+ sysVars := make (map [string ]interface {})
140
+
141
+ if port , err := getPort (cfg ); err == nil {
142
+ sysVars ["port" ] = port
143
+ }
144
+
145
+ oneSecond := time .Duration (1 ) * time .Second
146
+ if cfg .ConnReadTimeout >= oneSecond {
147
+ sysVars ["net_read_timeout" ] = cfg .ConnReadTimeout .Seconds ()
148
+ }
149
+ if cfg .ConnWriteTimeout >= oneSecond {
150
+ sysVars ["net_write_timeout" ] = cfg .ConnWriteTimeout .Seconds ()
151
+ }
152
+ if cfg .MaxConns > 0 {
153
+ sysVars ["max_connections" ] = cfg .MaxConns
154
+ }
142
155
143
156
// TODO: add the rest of the config variables
144
- err := sql .SystemVariables .AssignValues (map [string ]interface {}{
145
- "port" : port ,
146
- "max_connections" : cfg .MaxConns ,
147
- "net_read_timeout" : cfg .ConnReadTimeout .Seconds (),
148
- "net_write_timeout" : cfg .ConnWriteTimeout .Seconds (),
149
- })
157
+ err := sql .SystemVariables .AssignValues (sysVars )
150
158
if err != nil {
151
159
return err
152
160
}
153
161
return nil
154
162
}
155
163
156
164
func newServerFromHandler (cfg Config , e * sqle.Engine , sm * SessionManager , handler mysql.Handler , sel ServerEventListener ) (* Server , error ) {
157
- oneSecond := time .Duration (1 ) * time .Second
158
- // TODO read default values from systemVars. some default values are different in postgres vs mysql
159
- if cfg .ConnReadTimeout < oneSecond {
160
- cfg .ConnReadTimeout = oneSecond * 30
161
- }
162
- if cfg .ConnWriteTimeout < oneSecond {
163
- cfg .ConnWriteTimeout = oneSecond * 60
164
- }
165
- if cfg .MaxConnections < 1 {
166
- cfg .MaxConnections = 151
167
- }
168
-
169
165
for _ , opt := range cfg .Options {
170
166
e , sm , handler = opt (e , sm , handler )
171
167
}
0 commit comments