@@ -123,49 +123,45 @@ func portInUse(hostPort string) bool {
123123 return false
124124}
125125
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 ) {
129127 _ , port , err := net .SplitHostPort (cfg .Listener .Addr ().String ())
130128 if err != nil {
131- return defaultPort
129+ return 0 , err
132130 }
133131 portInt , err := strconv .ParseInt (port , 10 , 64 )
134132 if err != nil {
135- return defaultPort
133+ return 0 , err
136134 }
137- return portInt
135+ return portInt , nil
138136}
139137
140138func 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+ }
142155
143156 // 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 )
150158 if err != nil {
151159 return err
152160 }
153161 return nil
154162}
155163
156164func 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-
169165 for _ , opt := range cfg .Options {
170166 e , sm , handler = opt (e , sm , handler )
171167 }
0 commit comments