Skip to content

Commit 9d66799

Browse files
committed
Remove obsolete "keepalive" feature
1 parent cec3390 commit 9d66799

File tree

3 files changed

+13
-130
lines changed

3 files changed

+13
-130
lines changed

Diff for: README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Note: `go get` doesn't install the `master` branch, but the tag `go1`, which bui
3535
* Automatic Connection-Pooling *(by database/sql package)*
3636

3737
## Requirements
38-
* Go 1 or higher (Go 1.0.3 or higher recommended)
38+
* Go 1.0.3 or higher
3939
* MySQL (Version 4.1 or higher), MariaDB or Percona Server
4040

4141
---------------------------------------
@@ -104,9 +104,8 @@ For Unix-sockets the address is the absolute path to the MySQL-Server-socket, e.
104104

105105
Possible Parameters are:
106106
* `charset`: *"SET NAMES `value`"*. If multiple charsets are set (seperated by a comma), the following charset is used if setting the charset failes. This enables support for `utf8mb4` ([introduced in MySQL 5.5.3](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html)) with fallback to `utf8` for older servers.
107-
* _(deprecated)_ <s>`keepalive`: If `value` equals 1, the keepalive-time is set to [wait_timeout](https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_wait_timeout)-60, which pings the Server 60 seconds before the MySQL server would close the connection to avoid timeout. If the value is greater than 1, the server gets pinged every `value` seconds without a command. System variables are executed **before**, so it may be possible to change the *wait_timeout* value.</s> **With Go 1.0.3 this is not necessary anymore. Now closed connections can be automatically detected and handled.**
108-
* _(pending)_ <s>`tls`</s>: will enable SSL/TLS-Encryption
109-
* _(pending)_ <s>`compress`</s>: will enable Compression
107+
* _(pending)_ <s>`tls`</s>: will enable SSL/TLS-Encryption
108+
* _(pending)_ <s>`compress`</s>: will enable Compression
110109

111110
All other parameters are interpreted as system variables:
112111
* `time_zone`: *"SET time_zone='`value`'"*
@@ -152,6 +151,6 @@ That means:
152151
* You **needn't publish** the source code of your library as long the files licensed under the MPL 2.0 are **unchanged**
153152
* You **must publish** the source code of any **changed files** licensed under the MPL 2.0 under a) the MPL 2.0 itself or b) a compatible license (e.g. GPL 3.0 or Apache License 2.0)
154153

155-
Please read the [MPL 2.0 FAQ](http://www.mozilla.org/MPL/2.0/FAQ.html) if you have further questions regarding the license.
154+
Please read the [MPL 2.0 FAQ](http://www.mozilla.org/MPL/2.0/FAQ.html) if you have further questions regarding the license.
156155

157156
You can read the full terms here: [LICENSE](https://raw.github.com/Go-SQL-Driver/MySQL/master/LICENSE)

Diff for: connection.go

+8-119
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,19 @@ package mysql
1212
import (
1313
"bufio"
1414
"database/sql/driver"
15-
"errors"
1615
"net"
17-
"strconv"
1816
"strings"
19-
"time"
2017
)
2118

2219
type mysqlConn struct {
23-
cfg *config
24-
server *serverSettings
25-
netConn net.Conn
26-
bufReader *bufio.Reader
27-
protocol uint8
28-
sequence uint8
29-
affectedRows uint64
30-
insertId uint64
31-
lastCmdTime time.Time
32-
keepaliveTimer *time.Timer
20+
cfg *config
21+
server *serverSettings
22+
netConn net.Conn
23+
bufReader *bufio.Reader
24+
protocol uint8
25+
sequence uint8
26+
affectedRows uint64
27+
insertId uint64
3328
}
3429

3530
type config struct {
@@ -48,7 +43,6 @@ type serverSettings struct {
4843
charset uint8
4944
scrambleBuff []byte
5045
threadID uint32
51-
keepalive int64
5246
}
5347

5448
// Handles parameters set in DSN
@@ -76,10 +70,6 @@ func (mc *mysqlConn) handleParams() (e error) {
7670
case "compress":
7771
dbgLog.Print("Compression not implemented yet")
7872

79-
// We don't want to set keepalive as system var
80-
case "keepalive":
81-
continue
82-
8373
// System Vars
8474
default:
8575
e = mc.exec("SET " + param + "=" + val + "")
@@ -89,52 +79,6 @@ func (mc *mysqlConn) handleParams() (e error) {
8979
}
9080
}
9181

92-
// KeepAlive
93-
if val, param := mc.cfg.params["keepalive"]; param {
94-
mc.server.keepalive, e = strconv.ParseInt(val, 10, 64)
95-
if e != nil {
96-
return errors.New("Invalid keepalive time")
97-
}
98-
99-
// Get keepalive time by MySQL system var wait_timeout
100-
if mc.server.keepalive == 1 {
101-
val, e = mc.getSystemVar("wait_timeout")
102-
mc.server.keepalive, e = strconv.ParseInt(val, 10, 64)
103-
if e != nil {
104-
return errors.New("Error getting wait_timeout")
105-
}
106-
107-
// Trigger 1min BEFORE wait_timeout
108-
if mc.server.keepalive > 60 {
109-
mc.server.keepalive -= 60
110-
}
111-
}
112-
113-
if mc.server.keepalive > 0 {
114-
mc.lastCmdTime = time.Now()
115-
116-
// Ping-Timer to avoid timeout
117-
mc.keepaliveTimer = time.AfterFunc(
118-
time.Duration(mc.server.keepalive)*time.Second, func() {
119-
var diff time.Duration
120-
for {
121-
// Fires only if diff > keepalive. Makes it collision safe
122-
for mc.netConn != nil &&
123-
mc.lastCmdTime.Unix()+mc.server.keepalive > time.Now().Unix() {
124-
diff = mc.lastCmdTime.Sub(time.Unix(time.Now().Unix()-mc.server.keepalive, 0))
125-
time.Sleep(diff)
126-
}
127-
if mc.netConn != nil {
128-
if e := mc.Ping(); e != nil {
129-
break
130-
}
131-
} else {
132-
return
133-
}
134-
}
135-
})
136-
}
137-
}
13882
return
13983
}
14084

@@ -148,9 +92,6 @@ func (mc *mysqlConn) Begin() (driver.Tx, error) {
14892
}
14993

15094
func (mc *mysqlConn) Close() (e error) {
151-
if mc.server.keepalive > 0 {
152-
mc.keepaliveTimer.Stop()
153-
}
15495
mc.writeCommandPacket(COM_QUIT)
15596
mc.bufReader = nil
15697
mc.netConn.Close()
@@ -271,55 +212,3 @@ func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, erro
271212

272213
return rows, e
273214
}
274-
275-
// Gets the value of the given MySQL System Variable
276-
func (mc *mysqlConn) getSystemVar(name string) (val string, e error) {
277-
// Send command
278-
e = mc.writeCommandPacket(COM_QUERY, "SELECT @@"+name)
279-
if e != nil {
280-
return
281-
}
282-
283-
// Read Result
284-
resLen, e := mc.readResultSetHeaderPacket()
285-
if e != nil {
286-
return
287-
}
288-
289-
if resLen > 0 {
290-
var n uint64
291-
n, e = mc.readUntilEOF()
292-
if e != nil {
293-
return
294-
}
295-
296-
var row *[]*[]byte
297-
row, e = mc.readRow(int(n))
298-
if e != nil {
299-
return
300-
}
301-
302-
_, e = mc.readUntilEOF()
303-
if e != nil {
304-
return
305-
}
306-
307-
val = string(*(*row)[0])
308-
}
309-
310-
return
311-
}
312-
313-
// *** DEPRECATED ***
314-
// Executes a simple Ping-CMD to test or keepalive the connection
315-
func (mc *mysqlConn) Ping() (e error) {
316-
// Send command
317-
e = mc.writeCommandPacket(COM_PING)
318-
if e != nil {
319-
return
320-
}
321-
322-
// Read Result
323-
e = mc.readResultOK()
324-
return
325-
}

Diff for: packets.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,13 @@ func (mc *mysqlConn) readNumber(nr uint8) (uint64, error) {
9494
}
9595

9696
func (mc *mysqlConn) writePacket(data *[]byte) error {
97-
// Set time BEFORE to avoid possible collisions
98-
if mc.server.keepalive > 0 {
99-
mc.lastCmdTime = time.Now()
100-
}
101-
10297
// Write packet
10398
n, e := mc.netConn.Write(*data)
10499
if e != nil || n != len(*data) {
105100
if e == nil {
106101
e = errors.New("Length of send data does not match packet length")
107102
}
108-
errLog.Print(`packets:104 `, e)
103+
errLog.Print(`packets:103 `, e)
109104
return driver.ErrBadConn
110105
}
111106

0 commit comments

Comments
 (0)