Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tmc-pool-dialer-3
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Mar 24, 2024
2 parents 937a20d + a06cf7d commit f359c9f
Show file tree
Hide file tree
Showing 226 changed files with 13,131 additions and 7,269 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify cu stom queries, you can do so here or in a config file.
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
make build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3

- name: Slack Workflow Notification
if: ${{ failure() }}
Expand Down
4 changes: 2 additions & 2 deletions examples/compose/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ package main

import (
"fmt"
"math/rand"
"math/rand/v2"
"os"
"time"

Expand Down Expand Up @@ -59,7 +59,7 @@ func main() {
fmt.Printf("begin failed: %v\n", err)
os.Exit(1)
}
page := rand.Intn(100) + 1
page := rand.IntN(100) + 1
timeCreated := time.Now().UnixNano()
if _, err := tx.Exec("INSERT INTO messages (page,time_created_ns,message) VALUES (?,?,?)",
page, timeCreated, "V is for speed"); err != nil {
Expand Down
12 changes: 6 additions & 6 deletions go/bucketpool/bucketpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package bucketpool

import (
"math/rand"
"math/rand/v2"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -118,13 +118,13 @@ func TestPoolWeirdMaxSize(t *testing.T) {
func TestFuzz(t *testing.T) {
maxTestSize := 16384
for range 20000 {
minSize := rand.Intn(maxTestSize)
minSize := rand.IntN(maxTestSize)
if minSize == 0 {
minSize = 1
}
maxSize := rand.Intn(maxTestSize-minSize) + minSize
maxSize := rand.IntN(maxTestSize-minSize) + minSize
p := New(minSize, maxSize)
bufSize := rand.Intn(maxTestSize)
bufSize := rand.IntN(maxTestSize)
buf := p.Get(bufSize)
require.Len(t, *buf, bufSize, "unexpected buf length")
sPool := p.findPool(bufSize)
Expand All @@ -143,7 +143,7 @@ func BenchmarkPool(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
randomSize := rand.Intn(pool.maxSize)
randomSize := rand.IntN(pool.maxSize)
data := pool.Get(randomSize)
pool.Put(data)
}
Expand All @@ -156,7 +156,7 @@ func BenchmarkPoolGet(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
randomSize := rand.Intn(pool.maxSize)
randomSize := rand.IntN(pool.maxSize)
data := pool.Get(randomSize)
_ = data
}
Expand Down
4 changes: 2 additions & 2 deletions go/cmd/vtclient/cli/vtclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/json"
"fmt"
"io"
"math/rand"
"math/rand/v2"
"os"
"sort"
"sync"
Expand Down Expand Up @@ -174,7 +174,7 @@ func _run(cmd *cobra.Command, args []string) (*results, error) {
go func() {
if useRandom {
for {
seqChan <- rand.Intn(maxSeqID-minSeqID) + minSeqID
seqChan <- rand.IntN(maxSeqID-minSeqID) + minSeqID
}
} else {
for i := minSeqID; i < maxSeqID; i++ {
Expand Down
66 changes: 66 additions & 0 deletions go/cmd/vtctldclient/command/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ var (
RunE: commandExecuteFetchAsDBA,
Aliases: []string{"ExecuteFetchAsDba"},
}
// ExecuteMultiFetchAsDBA makes an ExecuteMultiFetchAsDBA gRPC call to a vtctld.
ExecuteMultiFetchAsDBA = &cobra.Command{
Use: "ExecuteMultiFetchAsDBA [--max-rows <max-rows>] [--json|-j] [--disable-binlogs] [--reload-schema] <tablet alias> <sql>",
Short: "Executes given multiple queries as the DBA user on the remote tablet.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandExecuteMultiFetchAsDBA,
Aliases: []string{"ExecuteMultiFetchAsDba"},
}
)

var executeFetchAsAppOptions = struct {
Expand Down Expand Up @@ -138,6 +147,57 @@ func commandExecuteFetchAsDBA(cmd *cobra.Command, args []string) error {
return nil
}

var executeMultiFetchAsDBAOptions = struct {
MaxRows int64
DisableBinlogs bool
ReloadSchema bool
JSON bool
}{
MaxRows: 10_000,
}

func commandExecuteMultiFetchAsDBA(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
return err
}

cli.FinishedParsing(cmd)

sql := cmd.Flags().Arg(1)

resp, err := client.ExecuteMultiFetchAsDBA(commandCtx, &vtctldatapb.ExecuteMultiFetchAsDBARequest{
TabletAlias: alias,
Sql: sql,
MaxRows: executeMultiFetchAsDBAOptions.MaxRows,
DisableBinlogs: executeMultiFetchAsDBAOptions.DisableBinlogs,
ReloadSchema: executeMultiFetchAsDBAOptions.ReloadSchema,
})
if err != nil {
return err
}

var qrs []*sqltypes.Result
for _, result := range resp.Results {
qr := sqltypes.Proto3ToResult(result)
qrs = append(qrs, qr)
}

switch executeMultiFetchAsDBAOptions.JSON {
case true:
data, err := cli.MarshalJSON(qrs)
if err != nil {
return err
}
fmt.Printf("%s\n", data)
default:
for _, qr := range qrs {
cli.WriteQueryResultTable(cmd.OutOrStdout(), qr)
}
}
return nil
}

func init() {
ExecuteFetchAsApp.Flags().Int64Var(&executeFetchAsAppOptions.MaxRows, "max-rows", 10_000, "The maximum number of rows to fetch from the remote tablet.")
ExecuteFetchAsApp.Flags().BoolVar(&executeFetchAsAppOptions.UsePool, "use-pool", false, "Use the tablet connection pool instead of creating a fresh connection.")
Expand All @@ -149,4 +209,10 @@ func init() {
ExecuteFetchAsDBA.Flags().BoolVar(&executeFetchAsDBAOptions.ReloadSchema, "reload-schema", false, "Instructs the tablet to reload its schema after executing the query.")
ExecuteFetchAsDBA.Flags().BoolVarP(&executeFetchAsDBAOptions.JSON, "json", "j", false, "Output the results in JSON instead of a human-readable table.")
Root.AddCommand(ExecuteFetchAsDBA)

ExecuteMultiFetchAsDBA.Flags().Int64Var(&executeMultiFetchAsDBAOptions.MaxRows, "max-rows", 10_000, "The maximum number of rows to fetch from the remote tablet.")
ExecuteMultiFetchAsDBA.Flags().BoolVar(&executeMultiFetchAsDBAOptions.DisableBinlogs, "disable-binlogs", false, "Disables binary logging during the query.")
ExecuteMultiFetchAsDBA.Flags().BoolVar(&executeMultiFetchAsDBAOptions.ReloadSchema, "reload-schema", false, "Instructs the tablet to reload its schema after executing the query.")
ExecuteMultiFetchAsDBA.Flags().BoolVarP(&executeMultiFetchAsDBAOptions.JSON, "json", "j", false, "Output the results in JSON instead of a human-readable table.")
Root.AddCommand(ExecuteMultiFetchAsDBA)
}
12 changes: 6 additions & 6 deletions go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --targe
delete = &cobra.Command{
Use: "delete",
Short: "Delete VDiffs.",
Example: `vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace delete a037a9e2-5628-11ee-8c99-0242ac120002
Example: `vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace customer delete a037a9e2-5628-11ee-8c99-0242ac120002
vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace delete all`,
DisableFlagsInUseLine: true,
Aliases: []string{"Delete"},
Expand All @@ -179,7 +179,7 @@ vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --targe
resume = &cobra.Command{
Use: "resume",
Short: "Resume a VDiff.",
Example: `vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace resume a037a9e2-5628-11ee-8c99-0242ac120002`,
Example: `vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace customer resume a037a9e2-5628-11ee-8c99-0242ac120002`,
DisableFlagsInUseLine: true,
Aliases: []string{"Resume"},
Args: cobra.ExactArgs(1),
Expand All @@ -198,9 +198,9 @@ vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --targe
show = &cobra.Command{
Use: "show",
Short: "Show the status of a VDiff.",
Example: `vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace show last
vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace show a037a9e2-5628-11ee-8c99-0242ac120002
vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace show all`,
Example: `vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace customer show last
vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace customer show a037a9e2-5628-11ee-8c99-0242ac120002
vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace customer show all`,
DisableFlagsInUseLine: true,
Aliases: []string{"Show"},
Args: cobra.ExactArgs(1),
Expand All @@ -224,7 +224,7 @@ vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --targe
stop = &cobra.Command{
Use: "stop",
Short: "Stop a running VDiff.",
Example: `vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace stop a037a9e2-5628-11ee-8c99-0242ac120002`,
Example: `vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace customer stop a037a9e2-5628-11ee-8c99-0242ac120002`,
DisableFlagsInUseLine: true,
Aliases: []string{"Stop"},
Args: cobra.ExactArgs(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"fmt"
"io"
"math/rand"
"math/rand/v2"
"sync"
"testing"

Expand Down Expand Up @@ -88,7 +88,7 @@ func newTestVDiffEnv(t testing.TB, ctx context.Context, sourceShards, targetShar
env.tmc.testEnv = env

// Generate a unique dialer name.
dialerName := fmt.Sprintf("VDiffTest-%s-%d", t.Name(), rand.Intn(1000000000))
dialerName := fmt.Sprintf("VDiffTest-%s-%d", t.Name(), rand.IntN(1000000000))
tabletconn.RegisterDialer(dialerName, func(tablet *topodatapb.Tablet, failFast grpcclient.FailFast) (queryservice.QueryService, error) {
env.mu.Lock()
defer env.mu.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions go/cmd/vttestserver/cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"fmt"
"io"
"math/rand"
"math/rand/v2"
"os/exec"
"path"
"strings"
Expand Down Expand Up @@ -426,7 +426,7 @@ func resetConfig(conf vttest.Config) {
}

func randomPort() int {
v := rand.Int31n(20000)
v := rand.Int32N(20000)
return int(v + 10000)
}

Expand Down
1 change: 1 addition & 0 deletions go/flags/endtoend/vtctldclient.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Available Commands:
ExecuteFetchAsApp Executes the given query as the App user on the remote tablet.
ExecuteFetchAsDBA Executes the given query as the DBA user on the remote tablet.
ExecuteHook Runs the specified hook on the given tablet.
ExecuteMultiFetchAsDBA Executes given multiple queries as the DBA user on the remote tablet.
FindAllShardsInKeyspace Returns a map of shard names to shard references for a given keyspace.
GenerateShardRanges Print a set of shard ranges assuming a keyspace with N shards.
GetBackups Lists backups for the given shard.
Expand Down
9 changes: 4 additions & 5 deletions go/mysql/collations/colldata/uca_contraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package colldata
import (
"encoding/json"
"fmt"
"math/rand"
"math/rand/v2"
"os"
"sort"
"testing"
Expand Down Expand Up @@ -203,14 +203,13 @@ func (s *strgen) generate(length int, freq float64) (out []byte) {
return flat[i] < flat[j]
})

gen := rand.New(rand.NewSource(0xDEADBEEF))
out = make([]byte, 0, length)
for len(out) < length {
if gen.Float64() < freq {
cnt := s.contractions[rand.Intn(len(s.contractions))]
if rand.Float64() < freq {
cnt := s.contractions[rand.IntN(len(s.contractions))]
out = append(out, cnt...)
} else {
cp := flat[rand.Intn(len(flat))]
cp := flat[rand.IntN(len(flat))]
out = append(out, string(cp)...)
}
}
Expand Down
4 changes: 2 additions & 2 deletions go/mysql/collations/colldata/uca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package colldata
import (
"bytes"
"fmt"
"math/rand"
"math/rand/v2"
"slices"
"sort"
"strings"
Expand Down Expand Up @@ -1002,7 +1002,7 @@ func TestUCACollationOrder(t *testing.T) {

ary := slices.Clone(sorted)
for i := range ary {
j := rand.Intn(i + 1)
j := rand.IntN(i + 1)
ary[i], ary[j] = ary[j], ary[i]
}
slices.SortFunc(ary, func(a, b string) int {
Expand Down
6 changes: 3 additions & 3 deletions go/mysql/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"math/rand"
"math/rand/v2"
"net"
"strconv"
"strings"
Expand Down Expand Up @@ -744,7 +744,7 @@ func TestEOFOrLengthEncodedIntFuzz(t *testing.T) {
}()

for i := 0; i < 100; i++ {
bytes := make([]byte, rand.Intn(16)+1)
bytes := make([]byte, rand.IntN(16)+1)
_, err := crypto_rand.Read(bytes)
require.NoError(t, err, "error doing rand.Read")

Expand Down Expand Up @@ -990,7 +990,7 @@ var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func randSeq(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
b[i] = letters[rand.IntN(len(letters))]
}
return string(b)
}
Expand Down
Loading

0 comments on commit f359c9f

Please sign in to comment.