Skip to content

Commit

Permalink
Merge branch 'vitessio:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
timvaillancourt authored Nov 7, 2023
2 parents 626907b + 6eebcb7 commit 7690988
Show file tree
Hide file tree
Showing 110 changed files with 4,718 additions and 3,410 deletions.
811 changes: 438 additions & 373 deletions changelog/18.0/18.0.0/changelog.md

Large diffs are not rendered by default.

198 changes: 111 additions & 87 deletions changelog/18.0/18.0.0/release_notes.md

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions changelog/18.0/18.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ In v17, the `vtbackup` stat `DurationByPhase` stat was added to measure the time

`Phase` reports a 1 (active) or a 0 (inactive) for each of the following phases:

* `CatchupReplication`
* `InitialBackup`
* `RestoreLastBackup`
* `TakeNewBackup`
* `CatchupReplication`
* `InitialBackup`
* `RestoreLastBackup`
* `TakeNewBackup`

To calculate how long `vtbackup` has spent in a given phase, sum the 1-valued data points over time and multiply by the data collection or reporting interval. For example, in Prometheus:

Expand All @@ -255,9 +255,9 @@ sum_over_time(vtbackup_phase{phase="TakeNewBackup"}) * <interval>

`PhaseStatus` reports a 1 (active) or a 0 (inactive) for each of the following phases and statuses:

* `CatchupReplication` phase has statuses `Stalled` and `Stopped`.
* `Stalled` is set to `1` when replication stops advancing.
* `Stopped` is set to `1` when replication stops before `vtbackup` catches up with the primary.
* `CatchupReplication` phase has statuses `Stalled` and `Stopped`.
* `Stalled` is set to `1` when replication stops advancing.
* `Stopped` is set to `1` when replication stops before `vtbackup` catches up with the primary.

#### <a id="backup-restore-metrics-aws-s3"/>Backup and restore metrics for AWS S3

Expand Down
1 change: 0 additions & 1 deletion changelog/19.0/19.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
### <a id="deprecations-and-deletions"/>Deprecations and Deletions

- The `MYSQL_FLAVOR` environment variable is now removed from all Docker Images.
- VTTablet metrics for TxThrottler's topology watchers have been deprecated. They will be deleted in the next release.

### <a id="docker"/>Docker

Expand Down
2 changes: 0 additions & 2 deletions go/cmd/mysqlctld/cli/mysqlctld.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var (
Long: "`mysqlctld` is a gRPC server that can be used instead of the `mysqlctl` client tool.\n" +
"If the target directories are empty when it is invoked, it automatically performs initialization operations to bootstrap the `mysqld` instance before starting it.\n" +
"The `mysqlctld` process can subsequently receive gRPC commands from a `vttablet` to perform housekeeping operations like shutting down and restarting the `mysqld` instance as needed.\n\n" +

"{{< warning >}}\n" +
"`mysqld_safe` is not used so the `mysqld` process will not be automatically restarted in case of a failure.\n" +
"{{</ warning>}}\n\n" +
Expand Down Expand Up @@ -151,7 +150,6 @@ func run(cmd *cobra.Command, args []string) error {
cancel()

servenv.Init()
defer servenv.Close()

// Take mysqld down with us on SIGTERM before entering lame duck.
servenv.OnTermSync(func() {
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtaclcheck/cli/vtactlcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var (

func run(cmd *cobra.Command, args []string) error {
servenv.Init()
defer servenv.Close()

opts := &vtaclcheck.Options{
ACLFile: aclFile,
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtbackup/cli/vtbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ func init() {

func run(_ *cobra.Command, args []string) error {
servenv.Init()
defer servenv.Close()

ctx, cancel := context.WithCancel(context.Background())
servenv.OnClose(func() {
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtbench/cli/vtbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func run(cmd *cobra.Command, args []string) error {
_ = cmd.Flags().Set("logtostderr", "true")

servenv.Init()
defer servenv.Close()

var clientProto vtbench.ClientProtocol
switch protocol {
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtctld/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ This is demonstrated in the example usage below.`,

func run(cmd *cobra.Command, args []string) error {
servenv.Init()
defer servenv.Close()

ts = topo.Open()
defer ts.Close()
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vtgate/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func run(cmd *cobra.Command, args []string) error {
defer exit.Recover()

servenv.Init()
defer servenv.Close()

ts := topo.Open()
defer ts.Close()
Expand Down
1 change: 0 additions & 1 deletion go/cmd/vttablet/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ vttablet \

func run(cmd *cobra.Command, args []string) error {
servenv.Init()
defer servenv.Close()

tabletAlias, err := topoproto.ParseTabletAlias(tabletPath)
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions go/hack/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ func RuntimeAllocSize(size int64) int64 {
return int64(roundupsize(uintptr(size)))
}

//go:linkname ParseFloatPrefix strconv.parseFloatPrefix
func ParseFloatPrefix(s string, bitSize int) (float64, int, error)
//go:linkname Atof64 strconv.atof64
func Atof64(s string) (float64, int, error)

//go:linkname Atof32 strconv.atof32
func Atof32(s string) (float32, int, error)

//go:linkname FastRand runtime.fastrand
func FastRand() uint32
18 changes: 18 additions & 0 deletions go/mysql/collations/colldata/8bit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package colldata

import (
"encoding/binary"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/collations/charset"
"vitess.io/vitess/go/vt/vthash"
Expand Down Expand Up @@ -168,6 +170,16 @@ func (c *Collation_8bit_simple_ci) Collate(left, right []byte, rightIsPrefix boo
return len(left) - len(right)
}

func (c *Collation_8bit_simple_ci) TinyWeightString(src []byte) uint32 {
var w32 [4]byte
sortOrder := c.sort
sortLen := min(4, len(src))
for i := 0; i < sortLen; i++ {
w32[i] = sortOrder[src[i]]
}
return binary.BigEndian.Uint32(w32[:4])
}

func (c *Collation_8bit_simple_ci) WeightString(dst, src []byte, numCodepoints int) []byte {
padToMax := false
sortOrder := c.sort
Expand Down Expand Up @@ -272,6 +284,12 @@ func (c *Collation_binary) Collate(left, right []byte, isPrefix bool) int {
return collationBinary(left, right, isPrefix)
}

func (c *Collation_binary) TinyWeightString(src []byte) uint32 {
var w32 [4]byte
copy(w32[:4], src)
return binary.BigEndian.Uint32(w32[:4])
}

func (c *Collation_binary) WeightString(dst, src []byte, numCodepoints int) []byte {
padToMax := false
copyCodepoints := len(src)
Expand Down
8 changes: 8 additions & 0 deletions go/mysql/collations/colldata/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ type CaseAwareCollation interface {
ToLower(dst []byte, src []byte) []byte
}

// TinyWeightCollation implements the TinyWeightString API for collations.
type TinyWeightCollation interface {
Collation
// TinyWeightString returns a 32-bit weight string for a source string based on this collation.
// This is usually the 4-byte prefix of the full weight string, calculated more efficiently.
TinyWeightString(src []byte) uint32
}

func Lookup(id collations.ID) Collation {
if int(id) >= len(collationsById) {
return nil
Expand Down
23 changes: 23 additions & 0 deletions go/mysql/collations/colldata/uca.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package colldata

import (
"bytes"
"encoding/binary"
"math/bits"

"vitess.io/vitess/go/mysql/collations"
Expand Down Expand Up @@ -119,6 +120,28 @@ nextLevel:
return int(l) - int(r)
}

func (c *Collation_utf8mb4_uca_0900) TinyWeightString(src []byte) uint32 {
it := c.uca.Iterator(src)
defer it.Done()

if fast, ok := it.(*uca.FastIterator900); ok {
var chunk [16]byte
fast.NextWeightBlock64(chunk[:16])
return binary.BigEndian.Uint32(chunk[:4])
}

var w32 uint32
w, ok := it.Next()
if ok {
w32 = uint32(w) << 16
w, ok = it.Next()
if ok {
w32 |= uint32(w)
}
}
return w32
}

func (c *Collation_utf8mb4_uca_0900) WeightString(dst, src []byte, numCodepoints int) []byte {
it := c.uca.Iterator(src)
defer it.Done()
Expand Down
56 changes: 56 additions & 0 deletions go/mysql/collations/colldata/uca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,62 @@ func TestCompareWithWeightString(t *testing.T) {
}
}

func TestTinyWeightStrings(t *testing.T) {
var Collations = []Collation{
testcollation(t, "utf8mb4_0900_as_cs"),
testcollation(t, "utf8mb4_0900_as_ci"),
testcollation(t, "utf8mb4_0900_ai_ci"),
}

var Strings = []string{
"a", "A", "aa", "AA", "aaa", "AAA", "aaaa", "AAAA",
"b", "B", "BB", "BB", "bbb", "BBB", "bbbb", "BBBB",
"Abc", "aBC",
"ǍḄÇ", "ÁḆĈ",
"\uA73A", "\uA738",
"\uAC00", "\u326E",
ExampleString,
ExampleStringLong,
JapaneseString,
WhitespaceString,
HungarianString,
JapaneseString2,
ChineseString,
ChineseString2,
SpanishString,
EnglishString,
}

for _, coll := range Collations {
tw := coll.(TinyWeightCollation)

for _, a := range Strings {
aw := tw.TinyWeightString([]byte(a))

for _, b := range Strings {
bw := tw.TinyWeightString([]byte(b))
cmp := tw.Collate([]byte(a), []byte(b), false)

switch {
case cmp == 0:
if aw != bw {
t.Errorf("[%s] %q vs %q: should be equal, got %08x / %08x", coll.Name(), a, b, aw, bw)
}
case cmp < 0:
if aw > bw {
t.Errorf("[%s] %q vs %q: should be <=, got %08x / %08x", coll.Name(), a, b, aw, bw)
}
case cmp > 0:
if aw < bw {
t.Errorf("[%s] %q vs %q: should be >= got %08x / %08x", coll.Name(), a, b, aw, bw)
}
}
}
}
}

}

func TestFastIterators(t *testing.T) {
allASCIICharacters := make([]byte, 128)
for n := range allASCIICharacters {
Expand Down
62 changes: 25 additions & 37 deletions go/mysql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (c *Conn) endWriterBuffering() error {
c.bufferedWriter = nil
}()

c.stopFlushTimer()
c.flushTimer.Stop()
return c.bufferedWriter.Flush()
}

Expand All @@ -345,43 +345,20 @@ func (c *Conn) returnReader() {
readersPool.Put(c.bufferedReader)
}

// getWriter returns the current writer. It may be either
// the original connection or a wrapper. The returned unget
// function must be invoked after the writing is finished.
// In buffered mode, the unget starts a timer to flush any
// buffered data.
func (c *Conn) getWriter() (w io.Writer, unget func()) {
c.bufMu.Lock()
if c.bufferedWriter != nil {
return c.bufferedWriter, func() {
c.startFlushTimer()
c.bufMu.Unlock()
}
}
c.bufMu.Unlock()
return c.conn, func() {}
}

// startFlushTimer must be called while holding lock on bufMu.
func (c *Conn) startFlushTimer() {
c.stopFlushTimer()
c.flushTimer = time.AfterFunc(mysqlServerFlushDelay, func() {
c.bufMu.Lock()
defer c.bufMu.Unlock()

if c.bufferedWriter == nil {
return
}
c.stopFlushTimer()
c.bufferedWriter.Flush()
})
}
if c.flushTimer == nil {
c.flushTimer = time.AfterFunc(mysqlServerFlushDelay, func() {
c.bufMu.Lock()
defer c.bufMu.Unlock()

// stopFlushTimer must be called while holding lock on bufMu.
func (c *Conn) stopFlushTimer() {
if c.flushTimer != nil {
c.flushTimer.Stop()
c.flushTimer = nil
if c.bufferedWriter == nil {
return
}
c.bufferedWriter.Flush()
})
} else {
c.flushTimer.Reset(mysqlServerFlushDelay)
}
}

Expand Down Expand Up @@ -615,8 +592,19 @@ func (c *Conn) writePacket(data []byte) error {
index := 0
dataLength := len(data) - packetHeaderSize

w, unget := c.getWriter()
defer unget()
var w io.Writer

c.bufMu.Lock()
if c.bufferedWriter != nil {
w = c.bufferedWriter
defer func() {
c.startFlushTimer()
c.bufMu.Unlock()
}()
} else {
c.bufMu.Unlock()
w = c.conn
}

var header [packetHeaderSize]byte
for {
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/fastparse/fastparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func ParseFloat64(s string) (float64, error) {
// We only care to parse as many of the initial float characters of the
// string as possible. This functionality is implemented in the `strconv` package
// of the standard library, but not exposed, so we hook into it.
val, l, err := hack.ParseFloatPrefix(s[ws:], 64)
val, l, err := hack.Atof64(s[ws:])
for l < len(s[ws:]) {
if !isSpace(s[ws+uint(l)]) {
break
Expand Down
4 changes: 2 additions & 2 deletions go/sqltypes/bind_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TupleToProto(v []Value) *querypb.Value {

// ValueToProto converts Value to a *querypb.Value.
func ValueToProto(v Value) *querypb.Value {
return &querypb.Value{Type: v.typ, Value: v.val}
return &querypb.Value{Type: v.Type(), Value: v.val}
}

// ProtoToValue converts a *querypb.Value to a Value.
Expand Down Expand Up @@ -143,7 +143,7 @@ func BytesBindVariable(v []byte) *querypb.BindVariable {

// ValueBindVariable converts a Value to a bind var.
func ValueBindVariable(v Value) *querypb.BindVariable {
return &querypb.BindVariable{Type: v.typ, Value: v.val}
return &querypb.BindVariable{Type: v.Type(), Value: v.val}
}

// BuildBindVariable builds a *querypb.BindVariable from a valid input type.
Expand Down
Loading

0 comments on commit 7690988

Please sign in to comment.