Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proof of concepts: Introduce reader and write groutine #1491

Closed
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
e4761dd
introduce writer goroutine
shogo82148 Oct 5, 2023
5ec520f
skip failing tests
shogo82148 Oct 5, 2023
22dd1e4
introduce reader loop
shogo82148 Oct 5, 2023
df63ad7
Merge branch 'master' into introduce-reader-and-write-groutine-3
shogo82148 Oct 5, 2023
a2f43e6
skip failing test: TestConnectionAttributes
shogo82148 Oct 5, 2023
8888cbe
fix compile error
shogo82148 Oct 5, 2023
62a33a1
skip failing test
shogo82148 Oct 5, 2023
9d248ae
suppress warnings
shogo82148 Oct 5, 2023
6629b93
introduce mysqlConn.data
shogo82148 Oct 6, 2023
f35e499
stop using buffer.takeSmallBuffer
shogo82148 Oct 6, 2023
56fe716
stop using buffer.takeCompleteBuffer
shogo82148 Oct 6, 2023
95e59e1
Revert "introduce mysqlConn.data"
shogo82148 Oct 6, 2023
1b07946
revert changes of buffer.takeSmallBuffer
shogo82148 Oct 6, 2023
4ffc645
introduce mysqlConn.data
shogo82148 Oct 6, 2023
dd65116
re-implement mysqlConn.writeCommandPacket
shogo82148 Oct 6, 2023
5c4569a
re-implement mysqlConn.writeCommandPacketUint32
shogo82148 Oct 6, 2023
8c475de
remove buffer.takeSmallBuffer
shogo82148 Oct 6, 2023
b584ce9
remove buffer.store
shogo82148 Oct 6, 2023
366679e
remove buffer.takeBuffer
shogo82148 Oct 6, 2023
525a5a2
re-implement mysqlConn.readPacket
shogo82148 Oct 6, 2023
832eeab
fix race condition of read
shogo82148 Oct 7, 2023
6826f06
mysqlConn.readFull supports context
shogo82148 Oct 7, 2023
5ed7b40
mysqlConn.writePacket now supports context
shogo82148 Oct 7, 2023
d1c6fa0
mysqlConn.readPacket now supports context
shogo82148 Oct 7, 2023
6b20c77
mysqlCon.handleAuthResult support context
shogo82148 Oct 7, 2023
e62a325
mysqlConn.handleInFileRequest supports context
shogo82148 Oct 7, 2023
525ee4d
mysqlConn.readHandshakePacket supports context
shogo82148 Oct 7, 2023
20ce0ad
mysqlConn.writeHandshakeResponsePacket supports context
shogo82148 Oct 7, 2023
4274a48
mysqlConn.writeAuthSwitchPacket supports context
shogo82148 Oct 7, 2023
21c54fa
Revert "mysqlConn.readHandshakePacket supports context"
shogo82148 Oct 7, 2023
50e2037
mysqlConn.readHandshakePacket support context
shogo82148 Oct 7, 2023
956412b
mysqlConn.writeCommandPacket supports context
shogo82148 Oct 7, 2023
9b8f2eb
Revert "mysqlConn.readHandshakePacket support context"
shogo82148 Oct 7, 2023
c62067a
mysqlConn.writeCommandPacketStr supports context
shogo82148 Oct 7, 2023
c9de1fc
mysqlConn.writeCommandPacketUint32 supports context
shogo82148 Oct 7, 2023
8717263
mysqlConn.readAuthResult supports context
shogo82148 Oct 7, 2023
8f381e1
okHandler.readResultOK supports context
shogo82148 Oct 7, 2023
13d825d
okHandler.readResultSetHeaderPacket supports context
shogo82148 Oct 7, 2023
e943ca7
mysqlConn.readColumns supports context
shogo82148 Oct 7, 2023
4328b11
mysqlConn.exec supports context
shogo82148 Oct 7, 2023
48d12aa
re-implement mysqlConn.ExecContext
shogo82148 Oct 7, 2023
f41405c
mysqlConn.query and mysqlStmt.query accept context
shogo82148 Oct 7, 2023
5868824
mysqlStmt.ExecContext propagates context
shogo82148 Oct 7, 2023
c4b0b07
mysqlStmt.writeExecutePacket supports context
shogo82148 Oct 7, 2023
cf055bb
fix: TestConnectorTimeoutsDuringOpen
shogo82148 Oct 7, 2023
9309e5d
mysqlConn.Ping no longer need to call watchCancel
shogo82148 Oct 7, 2023
57aa3e2
mysqlConn.begin supports context
shogo82148 Oct 7, 2023
952400c
mysqlConn.PrepareContext propagates context
shogo82148 Oct 7, 2023
62c508a
fix compile error
shogo82148 Oct 7, 2023
17f7abe
fix TestCleanCancel
shogo82148 Oct 7, 2023
2f77b54
NextResultSet treats context
shogo82148 Oct 7, 2023
bcee9e5
textRows.readRow and binaryRows.readRow see context
shogo82148 Oct 7, 2023
3719818
remove the watcher goroutine
shogo82148 Oct 7, 2023
6b8b377
remove mysqlConn.watching
shogo82148 Oct 7, 2023
cd998ef
remove mysqlConn.canceled
shogo82148 Oct 7, 2023
31707d5
mysqlConn.handleParams supports context
shogo82148 Oct 7, 2023
f61cb1f
mysqlConn.getSystemVar supports context
shogo82148 Oct 7, 2023
7e45f92
mysqlConn.readUntilEOF supports context
shogo82148 Oct 7, 2023
c90f82e
mysqlStmt.readPrepareResultPacket supports context
shogo82148 Oct 7, 2023
7656242
okHandler.discardResults supports context
shogo82148 Oct 7, 2023
28a813e
mysqlRows.Close handles context
shogo82148 Oct 7, 2023
14cedd3
mysqlStmt.writeCommandLongData supports context
shogo82148 Oct 7, 2023
01726b6
mysqlConn.sendEncryptedPassword support context
shogo82148 Oct 7, 2023
e8d1c24
mysqlConn.readHandshakePacket supports context
shogo82148 Oct 7, 2023
f7f734a
close the connection if canceled
shogo82148 Oct 7, 2023
923c82b
enable -race option
shogo82148 Oct 7, 2023
cf9b120
-covermode must be "atomic", not "count", when -race is enabled
shogo82148 Oct 7, 2023
f6ba15b
fix race condition of TestConcurrent
shogo82148 Oct 7, 2023
68d06b9
revert changes of noCopy
shogo82148 Oct 7, 2023
06c89a5
re-implement BenchmarkInterpolation
shogo82148 Oct 7, 2023
c6ef997
re-implement TestInterpolateParams
shogo82148 Oct 7, 2023
b867777
re-implement TestInterpolateParamsJSONRawMessage
shogo82148 Oct 7, 2023
8a6efeb
re-implement TestInterpolateParamsTooManyPlaceholders
shogo82148 Oct 7, 2023
67efea6
re-implement TestInterpolateParamsPlaceholderInString
shogo82148 Oct 7, 2023
aad3fd6
re-implement TestInterpolateParamsUint64
shogo82148 Oct 7, 2023
a4af165
re-implement TestCheckNamedValue
shogo82148 Oct 7, 2023
166fc5c
re-implement TestPingMarkBadConnection and TestPingErrInvalidConn
shogo82148 Oct 7, 2023
0226235
re-implement TestReadPacketSingleByte
shogo82148 Oct 7, 2023
1eaf0c0
re-implement TestReadPacketWrongSequenceID
shogo82148 Oct 7, 2023
1c6e980
re-implement TestReadPacketSplit
shogo82148 Oct 7, 2023
e849989
re-implement TestReadPacketFail
shogo82148 Oct 7, 2023
3ae4b2f
re-implement TestRegression801
shogo82148 Oct 7, 2023
198f0bf
Revert "re-implement TestRegression801"
shogo82148 Oct 7, 2023
15cbe27
introduce packet type
shogo82148 Oct 7, 2023
4a07d42
check error
shogo82148 Oct 7, 2023
8c82535
Revert "Revert "re-implement TestRegression801""
shogo82148 Oct 7, 2023
803dd56
Revert "re-implement TestReadPacketFail"
shogo82148 Oct 7, 2023
222487f
Revert "Revert "re-implement TestReadPacketFail""
shogo82148 Oct 7, 2023
7095f22
fix broken tests
shogo82148 Oct 7, 2023
5507c4f
re-implement mysqlConn.readPacket
shogo82148 Oct 7, 2023
b969ca3
introduce packet pool
shogo82148 Oct 7, 2023
e86f580
fix panic
shogo82148 Oct 7, 2023
46ed973
fix TestReadPacketFail
shogo82148 Oct 7, 2023
9431d87
re-implement TestStaleConnectionChecks
shogo82148 Oct 7, 2023
14644a0
put packets to pool
shogo82148 Oct 8, 2023
744cd7a
re-use package as buffer
shogo82148 Oct 8, 2023
07a417f
use packet pool for Interpolation
shogo82148 Oct 8, 2023
978f9f3
introduce writeBuffer
shogo82148 Oct 9, 2023
b0945da
introduce readBuffer
shogo82148 Oct 9, 2023
6d17fea
fix TestPingMarkBadConnection and TestPingErrInvalidConn
shogo82148 Oct 9, 2023
c4f94e2
fix TestReadPacketSingleByte
shogo82148 Oct 9, 2023
b6c7b5d
fix race conditions
shogo82148 Oct 9, 2023
6eda7f8
re-introduce packet pool
shogo82148 Oct 9, 2023
2e8bb88
fix TestReadPacketSplit
shogo82148 Oct 9, 2023
7019692
reduce allocation for interpolateParams
shogo82148 Oct 9, 2023
aecdebb
cache allocated buffer
shogo82148 Oct 9, 2023
5bfa422
check mc.reset
shogo82148 Oct 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:

- name: test
run: |
go test -v '-covermode=count' '-coverprofile=coverage.out'
go test -v -race '-covermode=atomic' '-coverprofile=coverage.out'

- name: Send coverage
uses: shogo82148/actions-goveralls@v1
Expand Down
16 changes: 16 additions & 0 deletions atomic_bool_go118.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ import "sync/atomic"
* Sync utils *
******************************************************************************/

// noCopy may be embedded into structs which must not be copied
// after the first use.
//
// See https://github.com/golang/go/issues/8005#issuecomment-190753527
// for details.
type noCopy struct{}

// Lock is a no-op used by -copylocks checker from `go vet`.
func (*noCopy) Lock() {}

// Unlock is a no-op used by -copylocks checker from `go vet`.
// noCopy should implement sync.Locker from Go 1.11
// https://github.com/golang/go/commit/c2eba53e7f80df21d51285879d51ab81bcfbf6bc
// https://github.com/golang/go/issues/26165
func (*noCopy) Unlock() {}

// atomicBool is an implementation of atomic.Bool for older version of Go.
// it is a wrapper around uint32 for usage as a boolean value with
// atomic access.
Expand Down
38 changes: 18 additions & 20 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package mysql

import (
"context"
"crypto/rand"
"crypto/rsa"
"crypto/sha1"
Expand Down Expand Up @@ -225,12 +226,12 @@ func encryptPassword(password string, seed []byte, pub *rsa.PublicKey) ([]byte,
return rsa.EncryptOAEP(sha1, rand.Reader, pub, plain, nil)
}

func (mc *mysqlConn) sendEncryptedPassword(seed []byte, pub *rsa.PublicKey) error {
func (mc *mysqlConn) sendEncryptedPassword(ctx context.Context, seed []byte, pub *rsa.PublicKey) error {
enc, err := encryptPassword(mc.cfg.Passwd, seed, pub)
if err != nil {
return err
}
return mc.writeAuthSwitchPacket(enc)
return mc.writeAuthSwitchPacket(ctx, enc)
}

func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error) {
Expand Down Expand Up @@ -296,9 +297,9 @@ func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error) {
}
}

func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
func (mc *mysqlConn) handleAuthResult(ctx context.Context, oldAuthData []byte, plugin string) error {
// Read Result Packet
authData, newPlugin, err := mc.readAuthResult()
authData, newPlugin, err := mc.readAuthResult(ctx)
if err != nil {
return err
}
Expand All @@ -320,12 +321,12 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
if err != nil {
return err
}
if err = mc.writeAuthSwitchPacket(authResp); err != nil {
if err = mc.writeAuthSwitchPacket(ctx, authResp); err != nil {
return err
}

// Read Result Packet
authData, newPlugin, err = mc.readAuthResult()
authData, newPlugin, err = mc.readAuthResult(ctx)
if err != nil {
return err
}
Expand All @@ -346,35 +347,32 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
case 1:
switch authData[0] {
case cachingSha2PasswordFastAuthSuccess:
if err = mc.resultUnchanged().readResultOK(); err == nil {
if err = mc.resultUnchanged().readResultOK(ctx); err == nil {
return nil // auth successful
}

case cachingSha2PasswordPerformFullAuthentication:
if mc.cfg.TLS != nil || mc.cfg.Net == "unix" {
// write cleartext auth packet
err = mc.writeAuthSwitchPacket(append([]byte(mc.cfg.Passwd), 0))
err = mc.writeAuthSwitchPacket(ctx, append([]byte(mc.cfg.Passwd), 0))
if err != nil {
return err
}
} else {
pubKey := mc.cfg.pubKey
if pubKey == nil {
// request public key from server
data, err := mc.buf.takeSmallBuffer(4 + 1)
if err != nil {
return err
}
data[4] = cachingSha2PasswordRequestPublicKey
err = mc.writePacket(data)
mc.data[4] = cachingSha2PasswordRequestPublicKey
err = mc.writePacket(ctx, mc.data[:5])
if err != nil {
return err
}

if data, err = mc.readPacket(); err != nil {
packet, err := mc.readPacket(ctx)
if err != nil {
return err
}

data := packet.data
if data[0] != iAuthMoreData {
return fmt.Errorf("unexpected resp from server for caching_sha2_password, perform full authentication")
}
Expand All @@ -392,12 +390,12 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
}

// send encrypted password
err = mc.sendEncryptedPassword(oldAuthData, pubKey)
err = mc.sendEncryptedPassword(ctx, oldAuthData, pubKey)
if err != nil {
return err
}
}
return mc.resultUnchanged().readResultOK()
return mc.resultUnchanged().readResultOK(ctx)

default:
return ErrMalformPkt
Expand All @@ -422,11 +420,11 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
}

// send encrypted password
err = mc.sendEncryptedPassword(oldAuthData, pub.(*rsa.PublicKey))
err = mc.sendEncryptedPassword(ctx, oldAuthData, pub.(*rsa.PublicKey))
if err != nil {
return err
}
return mc.resultUnchanged().readResultOK()
return mc.resultUnchanged().readResultOK(ctx)
}

default:
Expand Down
Loading
Loading