Skip to content

Commit

Permalink
update import
Browse files Browse the repository at this point in the history
Signed-off-by: Jchicode <[email protected]>
  • Loading branch information
Jchicode committed Feb 3, 2023
1 parent e320a3e commit 67bffd0
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package client

import (
"github.com/ztalab/ZASentinel-MYSQL/utils"
"github.com/ztalab/mysqlproxy/utils"
)

func (c *Conn) writeCommand(command byte) error {
Expand Down
2 changes: 1 addition & 1 deletion client/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"encoding/binary"
"encoding/pem"

"github.com/ztalab/ZASentinel-MYSQL/utils"
"github.com/ztalab/mysqlproxy/utils"

"github.com/pingcap/errors"
"github.com/siddontang/go/hack"
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ require (
github.com/satori/go.uuid v1.2.0
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
github.com/siddontang/go-log v0.0.0-20190221022429-1e957dd83bed
github.com/ztalab/ZASentinel-MYSQL v0.0.0-20230117024847-bbb9de156777
github.com/sirupsen/logrus v1.8.1
)

require (
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.7.1 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
11 changes: 0 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -14,10 +12,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 h1:xT+JlYxNGqyT+XcU8iUrN18JYed2TvG9yN5ULG2jATM=
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
github.com/siddontang/go-log v0.0.0-20190221022429-1e957dd83bed h1:KMgQoLJGCq1IoZpLZE3AIffh9veYWoVlsvA4ib55TMM=
Expand All @@ -28,19 +24,12 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/ztalab/ZASentinel-MYSQL v0.0.0-20230117024847-bbb9de156777 h1:SJNZGQWequ2qIoe6TwMhUJxHw47GTe2f9wbUrxAlkZY=
github.com/ztalab/ZASentinel-MYSQL v0.0.0-20230117024847-bbb9de156777/go.mod h1:0oFVRQbibgyVKmONQHg83MaNDY+1WbcWsrzk9a8PnoU=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion mysql/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package mysql
import (
"encoding/binary"

"github.com/ztalab/ZASentinel-MYSQL/utils"
"github.com/ztalab/mysqlproxy/utils"
)

type FieldData []byte
Expand Down
2 changes: 1 addition & 1 deletion mysql/rowdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package mysql
import (
"strconv"

"github.com/ztalab/ZASentinel-MYSQL/utils"
"github.com/ztalab/mysqlproxy/utils"

"github.com/pingcap/errors"
)
Expand Down
4 changes: 2 additions & 2 deletions packet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"net"
"sync"

"github.com/ztalab/ZASentinel-MYSQL/utils"
"github.com/ztalab/mysqlproxy/utils"

"github.com/pingcap/errors"
)
Expand Down Expand Up @@ -56,7 +56,7 @@ func (b *BufPool) Return(buf *bytes.Buffer) {
}

/*
Conn is the base class to handle MySQL protocol.
Conn is the base class to handle MySQL protocol.
*/
type Conn struct {
net.Conn
Expand Down
47 changes: 47 additions & 0 deletions utils/byte_slice_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2022-present The ZTDBP Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package utils

import "sync"

var (
byteSlicePool = sync.Pool{
New: func() interface{} {
return []byte{}
},
}
byteSliceChan = make(chan []byte, 10)
)

func ByteSliceGet(length int) (data []byte) {
select {
case data = <-byteSliceChan:
default:
data = byteSlicePool.Get().([]byte)[:0]
}

if cap(data) < length {
data = make([]byte, length)
} else {
data = data[:length]
}

return data
}

func ByteSlicePut(data []byte) {
select {
case byteSliceChan <- data:
default:
byteSlicePool.Put(data) //nolint:staticcheck
}
}
46 changes: 46 additions & 0 deletions utils/bytes_buffer_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2022-present The ZTDBP Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package utils

import (
"bytes"
"sync"
)

var (
bytesBufferPool = sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
bytesBufferChan = make(chan *bytes.Buffer, 10)
)

func BytesBufferGet() (data *bytes.Buffer) {
select {
case data = <-bytesBufferChan:
default:
data = bytesBufferPool.Get().(*bytes.Buffer)
}

data.Reset()

return data
}

func BytesBufferPut(data *bytes.Buffer) {
select {
case bytesBufferChan <- data:
default:
bytesBufferPool.Put(data)
}
}
49 changes: 49 additions & 0 deletions utils/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2022-present The ZTDBP Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package utils

import (
"runtime/debug"
"time"

"github.com/sirupsen/logrus"
)

func InArray(in string, array []string) bool {
for k := range array {
if in == array[k] {
return true
}
}
return false
}

func GoWithRecover(handler func(), recoverHandler func(r interface{})) {
go func() {
defer func() {
if r := recover(); r != nil {
logrus.Errorf("%s goroutine panic: %v\n%s\n", time.Now().Format("2006-01-02 15:04:05"), r, string(debug.Stack()))
if recoverHandler != nil {
go func() {
defer func() {
if p := recover(); p != nil {
logrus.Errorf("recover goroutine panic:%v\n%s\n", p, string(debug.Stack()))
}
}()
recoverHandler(r)
}()
}
}
}()
handler()
}()
}
38 changes: 38 additions & 0 deletions utils/zeroalloc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022-present The ZTDBP Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package utils

import "unsafe"

func StringToByteSlice(s string) []byte {
return *(*[]byte)(unsafe.Pointer(&s))
}

func ByteSliceToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

func Uint64ToInt64(val uint64) int64 {
return *(*int64)(unsafe.Pointer(&val))
}

func Uint64ToFloat64(val uint64) float64 {
return *(*float64)(unsafe.Pointer(&val))
}

func Int64ToUint64(val int64) uint64 {
return *(*uint64)(unsafe.Pointer(&val))
}

func Float64ToUint64(val float64) uint64 {
return *(*uint64)(unsafe.Pointer(&val))
}

0 comments on commit 67bffd0

Please sign in to comment.