Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cor committed May 20, 2024
2 parents 3027122 + ff7bd63 commit 7506c61
Show file tree
Hide file tree
Showing 40 changed files with 19,521 additions and 14,908 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/check_make_parser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ jobs:
runs-on: ubuntu-20.04
steps:

- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.19

- name: Check out code
uses: actions/checkout@v3
go-version-file: go.mod

- name: Get dependencies
run: |
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ jobs:
name: Build
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.19

- name: Check out code
uses: actions/checkout@v3
go-version-file: go.mod

- name: Get dependencies
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/unit_race.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ jobs:
runs-on: ubuntu-20.04
steps:

- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.19

- name: Check out code
uses: actions/checkout@v3
go-version-file: go.mod

- name: Get dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/dolthub/vitess

go 1.19
go 1.22

require (
github.com/stretchr/testify v1.4.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -43,6 +44,7 @@ golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
Expand All @@ -51,6 +53,7 @@ golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8=
golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
Expand Down
70 changes: 70 additions & 0 deletions go/mysql/auth_server_static_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2023 Dolthub, Inc.
//
// 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.

// +build linux

package mysql

import (
"fmt"
"io/ioutil"
"os"
"syscall"
"testing"
"time"
)

func TestStaticConfigHUP(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "mysql_auth_server_static_file.json")
if err != nil {
t.Fatalf("couldn't create temp file: %v", err)
}
defer os.Remove(tmpFile.Name())
oldStr := "str5"
jsonConfig := fmt.Sprintf("{\"%s\":[{\"Password\":\"%s\"}]}", oldStr, oldStr)
if err := ioutil.WriteFile(tmpFile.Name(), []byte(jsonConfig), 0600); err != nil {
t.Fatalf("couldn't write temp file: %v", err)
}

aStatic := NewAuthServerStatic(tmpFile.Name(), "", 0)
defer aStatic.close()

if aStatic.getEntries()[oldStr][0].Password != oldStr {
t.Fatalf("%s's Password should still be '%s'", oldStr, oldStr)
}

hupTest(t, aStatic, tmpFile, oldStr, "str2")
hupTest(t, aStatic, tmpFile, "str2", "str3") // still handling the signal
}

func hupTest(t *testing.T, aStatic *AuthServerStatic, tmpFile *os.File, oldStr, newStr string) {
jsonConfig := fmt.Sprintf("{\"%s\":[{\"Password\":\"%s\"}]}", newStr, newStr)
if err := ioutil.WriteFile(tmpFile.Name(), []byte(jsonConfig), 0600); err != nil {
t.Fatalf("couldn't overwrite temp file: %v", err)
}

if aStatic.getEntries()[oldStr][0].Password != oldStr {
t.Fatalf("%s's Password should still be '%s'", oldStr, oldStr)
}

syscall.Kill(syscall.Getpid(), syscall.SIGHUP)
time.Sleep(100 * time.Millisecond) // wait for signal handler

if aStatic.getEntries()[oldStr] != nil {
t.Fatalf("Should not have old %s after config reload", oldStr)
}
if aStatic.getEntries()[newStr][0].Password != newStr {
t.Fatalf("%s's Password should be '%s'", newStr, newStr)
}
}
45 changes: 0 additions & 45 deletions go/mysql/auth_server_static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"io/ioutil"
"net"
"os"
"syscall"
"testing"
"time"
)
Expand Down Expand Up @@ -126,29 +125,6 @@ func TestHostMatcher(t *testing.T) {
}
}

func TestStaticConfigHUP(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "mysql_auth_server_static_file.json")
if err != nil {
t.Fatalf("couldn't create temp file: %v", err)
}
defer os.Remove(tmpFile.Name())
oldStr := "str5"
jsonConfig := fmt.Sprintf("{\"%s\":[{\"Password\":\"%s\"}]}", oldStr, oldStr)
if err := ioutil.WriteFile(tmpFile.Name(), []byte(jsonConfig), 0600); err != nil {
t.Fatalf("couldn't write temp file: %v", err)
}

aStatic := NewAuthServerStatic(tmpFile.Name(), "", 0)
defer aStatic.close()

if aStatic.getEntries()[oldStr][0].Password != oldStr {
t.Fatalf("%s's Password should still be '%s'", oldStr, oldStr)
}

hupTest(t, aStatic, tmpFile, oldStr, "str2")
hupTest(t, aStatic, tmpFile, "str2", "str3") // still handling the signal
}

func TestStaticConfigHUPWithRotation(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "mysql_auth_server_static_file.json")
if err != nil {
Expand Down Expand Up @@ -180,27 +156,6 @@ func TestStaticConfigHUPWithRotation(t *testing.T) {
aStatic.close()
}

func hupTest(t *testing.T, aStatic *AuthServerStatic, tmpFile *os.File, oldStr, newStr string) {
jsonConfig := fmt.Sprintf("{\"%s\":[{\"Password\":\"%s\"}]}", newStr, newStr)
if err := ioutil.WriteFile(tmpFile.Name(), []byte(jsonConfig), 0600); err != nil {
t.Fatalf("couldn't overwrite temp file: %v", err)
}

if aStatic.getEntries()[oldStr][0].Password != oldStr {
t.Fatalf("%s's Password should still be '%s'", oldStr, oldStr)
}

syscall.Kill(syscall.Getpid(), syscall.SIGHUP)
time.Sleep(100 * time.Millisecond) // wait for signal handler

if aStatic.getEntries()[oldStr] != nil {
t.Fatalf("Should not have old %s after config reload", oldStr)
}
if aStatic.getEntries()[newStr][0].Password != newStr {
t.Fatalf("%s's Password should be '%s'", newStr, newStr)
}
}

func hupTestWithRotation(t *testing.T, aStatic *AuthServerStatic, tmpFile *os.File, oldStr, newStr string) {
jsonConfig := fmt.Sprintf("{\"%s\":[{\"Password\":\"%s\"}]}", newStr, newStr)
if err := ioutil.WriteFile(tmpFile.Name(), []byte(jsonConfig), 0600); err != nil {
Expand Down
98 changes: 98 additions & 0 deletions go/mysql/binlog_dump.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Copyright 2022 The Vitess 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 mysql

import (
"encoding/binary"
vtrpcpb "github.com/dolthub/vitess/go/vt/proto/vtrpc"
"github.com/dolthub/vitess/go/vt/vterrors"
"io"
)

var (
// BinglogMagicNumber is 4-byte number at the beginning of every binary log
BinglogMagicNumber = []byte{0xfe, 0x62, 0x69, 0x6e}
readPacketErr = vterrors.Errorf(vtrpcpb.Code_INTERNAL, "error reading BinlogDumpGTID packet")
)

const (
BinlogDumpNonBlock = 0x01
BinlogThroughPosition = 0x02
BinlogThroughGTID = 0x04
)

func (c *Conn) parseComBinlogDump(data []byte) (logFile string, binlogPos uint32, err error) {
pos := 1

binlogPos, pos, ok := readUint32(data, pos)
if !ok {
return logFile, binlogPos, readPacketErr
}

pos += 2 // flags
pos += 4 // server-id

logFile = string(data[pos:])
return logFile, binlogPos, nil
}

func (c *Conn) parseComBinlogDumpGTID(data []byte) (logFile string, logPos uint64, position Position, err error) {
// see https://dev.mysql.com/doc/internals/en/com-binlog-dump-gtid.html
pos := 1

flags := binary.LittleEndian.Uint16(data[pos : pos+2])
pos += 2 // flags
pos += 4 // server-id

fileNameLen, pos, ok := readUint32(data, pos)
if !ok {
return logFile, logPos, position, readPacketErr
}
logFile = string(data[pos : pos+int(fileNameLen)])
pos += int(fileNameLen)

logPos, pos, ok = readUint64(data, pos)
if !ok {
return logFile, logPos, position, readPacketErr
}

if flags&BinlogDumpNonBlock != 0 {
return logFile, logPos, position, io.EOF
}
if flags&BinlogThroughGTID != 0 {
dataSize, pos, ok := readUint32(data, pos)
if !ok {
return logFile, logPos, position, readPacketErr
}

gtidBytes := data[pos : pos+int(dataSize)]

// NOTE: A MySQL 8.0 replica sends the GTID set as binary data, not as a human-readable string.
// The main Vitess codebase was parsing a human-readable string and then using DecodePosition
// to parse it, but that doesn't seem to actually work with real MySQL replicas, so we
// diverge here from their implementation.
gtidSet, err := NewMysql56GTIDSetFromSIDBlock(gtidBytes)
if err != nil {
return logFile, logPos, position, err
}
position = Position{
GTIDSet: gtidSet,
}
}

return logFile, logPos, position, nil
}
Loading

0 comments on commit 7506c61

Please sign in to comment.