-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional Driver args for compression and connection read/write time…
…outs (#885) * allow setting the collation in auth handshake * Allow connect with context in order to provide configurable connect timeouts * add driver arguments * check for empty ssl value when setting conn options * allow setting the collation in auth handshake (#860) * Allow connect with context in order to provide configurable connect timeouts * support collations IDs greater than 255 on the auth handshake --------- Co-authored-by: dvilaverde <[email protected]> * refactored and added more driver args * revert change to Makefile * added tests for timeouts * adding more tests * fixing linting issues * avoiding panic on test complete * revert returning set readtimeout error in binlogsyncer * fixing nil violation when connection with timeout from binlogsyncer * Update README.md Co-authored-by: Daniël van Eeden <[email protected]> * addressing pull request feedback * revert rename driver arg ssl to tls * addressing PR feedback * write compressed packet using writeWithTimeout * updated README.md --------- Co-authored-by: dvilaverde <[email protected]> Co-authored-by: Daniël van Eeden <[email protected]>
- Loading branch information
1 parent
6c99b4b
commit b13191f
Showing
15 changed files
with
551 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,6 +360,95 @@ func main() { | |
} | ||
``` | ||
|
||
### Driver Options | ||
|
||
Configuration options can be provided by the standard DSN (Data Source Name). | ||
|
||
``` | ||
[user[:password]@]addr[/db[?param=X]] | ||
``` | ||
|
||
#### `compress` | ||
|
||
Enable compression between the client and the server. Valid values are 'zstd','zlib','uncompressed'. | ||
|
||
| Type | Default | Example | | ||
| --------- | ------------- | --------------------------------------- | | ||
| string | uncompressed | user:pass@localhost/mydb?compress=zlib | | ||
|
||
#### `readTimeout` | ||
|
||
I/O read timeout. The time unit is specified in the argument value using | ||
golang's [ParseDuration](https://pkg.go.dev/time#ParseDuration) format. | ||
|
||
0 means no timeout. | ||
|
||
| Type | Default | Example | | ||
| --------- | --------- | ------------------------------------------- | | ||
| duration | 0 | user:pass@localhost/mydb?readTimeout=10s | | ||
|
||
#### `ssl` | ||
|
||
Enable TLS between client and server. Valid values are `true` or `custom`. When using `custom`, | ||
the connection will use the TLS configuration set by SetCustomTLSConfig matching the host. | ||
|
||
| Type | Default | Example | | ||
| --------- | --------- | ------------------------------------------- | | ||
| string | | user:pass@localhost/mydb?ssl=true | | ||
|
||
#### `timeout` | ||
|
||
Timeout is the maximum amount of time a dial will wait for a connect to complete. | ||
The time unit is specified in the argument value using golang's [ParseDuration](https://pkg.go.dev/time#ParseDuration) format. | ||
|
||
0 means no timeout. | ||
|
||
| Type | Default | Example | | ||
| --------- | --------- | ------------------------------------------- | | ||
| duration | 0 | user:pass@localhost/mydb?timeout=1m | | ||
|
||
#### `writeTimeout` | ||
|
||
I/O write timeout. The time unit is specified in the argument value using | ||
golang's [ParseDuration](https://pkg.go.dev/time#ParseDuration) format. | ||
|
||
0 means no timeout. | ||
|
||
| Type | Default | Example | | ||
| --------- | --------- | ----------------------------------------------- | | ||
| duration | 0 | user:pass@localhost/mydb?writeTimeout=1m30s | | ||
|
||
### Custom Driver Options | ||
|
||
The driver package exposes the function `SetDSNOptions`, allowing for modification of the | ||
connection by adding custom driver options. | ||
It requires a full import of the driver (not by side-effects only). | ||
|
||
Example of defining a custom option: | ||
|
||
```golang | ||
import ( | ||
"database/sql" | ||
|
||
"github.com/go-mysql-org/go-mysql/driver" | ||
) | ||
|
||
func main() { | ||
driver.SetDSNOptions(map[string]DriverOption{ | ||
"no_metadata": func(c *client.Conn, value string) error { | ||
c.SetCapability(mysql.CLIENT_OPTIONAL_RESULTSET_METADATA) | ||
return nil | ||
}, | ||
}) | ||
|
||
// dsn format: "user:password@addr/dbname?" | ||
dsn := "[email protected]:3306/test?no_metadata=true" | ||
db, _ := sql.Open(dsn) | ||
db.Close() | ||
} | ||
``` | ||
|
||
|
||
We pass all tests in https://github.com/bradfitz/go-sql-test using go-mysql driver. :-) | ||
|
||
## Donate | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.