Skip to content

Commit

Permalink
Slack vitess r14.0.5 dsdefense (#214)
Browse files Browse the repository at this point in the history
This PR adds the vitess backpressure / Transaction Throttler work to our v14 release. In short, it adds the following:

* vtgates parse a comment directive specifying the query priority. If missing, a default, configurable priority is assigned to the query.
* The throttler uses the priority to determine whether a given query can or cannot be throttled.
* The throttler will throttle if the query rate is above its estimate of max query rate and there is lag.
* The throttler can now throttle write statements outside of explicit BEGIN/COMMIT blocks.
* The throttler is still guarded by a CLI flag so if not passed, throttling is not enabled.
* Throttled queries return a different/separate MySQL error code.

In addition, some changes were backported from newer versions to v14 for easier handling of parsing of some config options.
  • Loading branch information
ejortegau authored Mar 1, 2024
1 parent b878269 commit 0286fd7
Show file tree
Hide file tree
Showing 55 changed files with 2,651 additions and 2,510 deletions.
1 change: 1 addition & 0 deletions config/tablet/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ cacheResultFields: true # enable-query-plan-field-caching
# enable-tx-throttler
# tx-throttler-config
# tx-throttler-healthcheck-cells
# tx-throttler-tablet-types
# enable_transaction_limit
# enable_transaction_limit_dry_run
# transaction_limit_per_user
Expand Down
9 changes: 7 additions & 2 deletions doc/ReplicationLagBasedThrottlingOfTransactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ If this is not specified a [default](https://github.com/vitessio/vitess/tree/mai
* *tx-throttler-healthcheck-cells*

A comma separated list of datacenter cells. The throttler will only monitor
the non-RDONLY replicas found in these cells for replication lag.
the replicas found in these cells for replication lag.

* *tx-throttler-tablet-types*

A comma separated list of tablet types. The throttler will only monitor tablets
with these types. Only `replica` and/or `rdonly` types are supported. The default
is `replica`.

# Caveats and Known Issues
* The throttler keeps trying to explore the maximum rate possible while keeping
Expand All @@ -39,4 +45,3 @@ lag limit may occasionally be slightly violated.

* Transactions are considered homogeneous. There is currently no support
for specifying how `expensive` a transaction is.

4 changes: 3 additions & 1 deletion go/cmd/mysqlctl/mysqlctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"os"
"time"

"github.com/spf13/pflag"

"vitess.io/vitess/go/cmd"
"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/flagutil"
Expand Down Expand Up @@ -248,7 +250,7 @@ func main() {
exit.Return(1)
}
dbconfigs.RegisterFlags(dbconfigs.Dba)
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("mysqlctl", pflag.ExitOnError))

tabletAddr = netutil.JoinHostPort("localhost", int32(*port))

Expand Down
4 changes: 3 additions & 1 deletion go/cmd/query_analyzer/query_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"os"
"sort"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/sqlparser"
Expand Down Expand Up @@ -59,7 +61,7 @@ func (a stats) Less(i, j int) bool { return a[i].Count > a[j].Count }

func main() {
defer exit.Recover()
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("query_analyzer", pflag.ExitOnError))
for _, filename := range _flag.Args() {
fmt.Printf("processing: %s\n", filename)
if err := processFile(filename); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/topo2topo/topo2topo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"fmt"
"os"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand Down Expand Up @@ -53,7 +55,7 @@ func main() {
defer exit.RecoverAll()
defer logutil.Flush()

_flag.Parse()
_flag.Parse(pflag.NewFlagSet("topo2topo", pflag.ExitOnError))
args := _flag.Args()
if len(args) != 0 {
flag.Usage()
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/vtbench/vtbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strings"
"time"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/log"
Expand Down Expand Up @@ -104,7 +106,7 @@ func main() {
defer exit.Recover()

flag.Lookup("logtostderr").Value.Set("true")
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vtbench", pflag.ExitOnError))

clientProto := vtbench.MySQL
switch *protocol {
Expand Down
3 changes: 2 additions & 1 deletion go/cmd/vtclient/vtclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"time"

"github.com/olekukonko/tablewriter"
"github.com/spf13/pflag"

"vitess.io/vitess/go/vt/concurrency"
"vitess.io/vitess/go/vt/log"
Expand Down Expand Up @@ -147,7 +148,7 @@ func main() {
}

func run() (*results, error) {
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vtclient", pflag.ExitOnError))
args := _flag.Args()

if len(args) == 0 {
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/vtctlclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"strings"
"time"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/log"
Expand Down Expand Up @@ -70,7 +72,7 @@ func checkDeprecations(args []string) {
func main() {
defer exit.Recover()

_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vtctlclient", pflag.ExitOnError))

closer := trace.StartTracing("vtctlclient")
defer trace.LogErrorsWhenClosing(closer)
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func main() {
log.Exitf("tablet_types_to_wait should contain at least one serving tablet type")
}

err := CheckCellFlags(context.Background(), resilientServer, *cell, *vtgate.CellsToWatch)
err := CheckCellFlags(context.Background(), resilientServer, *cell, vtgate.CellsToWatch)
if err != nil {
log.Exitf("cells_to_watch validation failed: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/vtgr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"flag"
"strings"

"github.com/spf13/pflag"

"vitess.io/vitess/go/vt/vtgr"

// Include deprecation warnings for soon-to-be-unsupported flag invocations.
Expand All @@ -26,7 +28,7 @@ import (

func main() {
clustersToWatch := flag.String("clusters_to_watch", "", "Comma-separated list of keyspaces or keyspace/shards that this instance will monitor and repair. Defaults to all clusters in the topology. Example: \"ks1,ks2/-80\"")
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vtgr", pflag.ExitOnError))

// openTabletDiscovery will open up a connection to topo server
// and populate the tablets in memory
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/vttlstest/vttlstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"io"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand Down Expand Up @@ -137,7 +139,7 @@ func main() {
_flag.SetUsage(flag.CommandLine, _flag.UsageOptions{
Preface: func(w io.Writer) { fmt.Fprint(w, doc) },
})
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vttlstest", pflag.ExitOnError))
args := _flag.Args()
if len(args) == 0 {
flag.Usage()
Expand Down
6 changes: 4 additions & 2 deletions go/cmd/zk/zkcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"syscall"
"time"

"github.com/spf13/pflag"
"github.com/z-division/go-zookeeper/zk"
"golang.org/x/term"

Expand Down Expand Up @@ -140,10 +141,11 @@ func main() {
defer exit.Recover()
defer logutil.Flush()

_flag.SetUsage(flag.CommandLine, _flag.UsageOptions{
fs := pflag.NewFlagSet("zkcmd", pflag.ExitOnError)
_flag.SetUsage(flag.CommandLine, _flag.UsageOptions{ // TODO: hmmm
Epilogue: func(w io.Writer) { fmt.Fprint(w, doc) },
})
_flag.Parse()
_flag.Parse(fs)
args := _flag.Args()
if len(args) == 0 {
flag.Usage()
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/zkctl/zkctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"io"
"os"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand Down Expand Up @@ -60,7 +62,7 @@ func main() {
defer exit.Recover()
defer logutil.Flush()

_flag.Parse()
_flag.Parse(pflag.NewFlagSet("zkctl", pflag.ExitOnError))
args := _flag.Args()

if len(args) == 0 {
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/zkctld/zkctld.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"os/signal"
"syscall"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand All @@ -45,7 +47,7 @@ func main() {
defer exit.Recover()
defer logutil.Flush()

_flag.Parse()
_flag.Parse(pflag.NewFlagSet("zkctld", pflag.ExitOnError))

zkConfig := zkctl.MakeZkConfigFromString(*zkCfg, uint32(*myID))
zkd := zkctl.NewZkd(zkConfig)
Expand Down
Loading

0 comments on commit 0286fd7

Please sign in to comment.