Skip to content

Commit

Permalink
Merge branch 'vitessio:main' into vtadmin-vexplain
Browse files Browse the repository at this point in the history
  • Loading branch information
c-r-dev authored Jan 24, 2025
2 parents f8a3d76 + a6c2896 commit 918d02e
Show file tree
Hide file tree
Showing 187 changed files with 20,174 additions and 10,485 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check_make_vtadmin_web_proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
# node-version should match package.json
node-version: '20.12.2'
node-version: '22.13.1'

- name: Install npm dependencies
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.proto_changes == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static_checks_etc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ jobs:
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
# make proto requires newer node than the pre-installed one
node-version: '20.12.2'
node-version: '22.13.1'

- name: check_make_proto
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.proto_changes == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vtadmin_web_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false'
with:
# node-version should match package.json
node-version: '20.12.2'
node-version: '22.13.1'

- name: Install dependencies
if: steps.skip-workflow.outputs.skip-workflow == 'false'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vtadmin_web_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false'
with:
# node-version should match package.json
node-version: '20.12.2'
node-version: '22.13.1'

- name: Install dependencies
if: steps.skip-workflow.outputs.skip-workflow == 'false'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vtadmin_web_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false'
with:
# node-version should match package.json
node-version: '20.12.2'
node-version: '22.13.1'

- name: Install dependencies
if: steps.skip-workflow.outputs.skip-workflow == 'false'
Expand Down
16 changes: 15 additions & 1 deletion changelog/22.0/22.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
- **[Stalled Disk Recovery in VTOrc](#stall-disk-recovery)**
- **[Update default MySQL version to 8.0.40](#mysql-8-0-40)**
- **[Update lite images to Debian Bookworm](#debian-bookworm)**
- **[Support for Filtering Query logs on Error](#query-logs)**
- **[Minor Changes](#minor-changes)**
- **[VTTablet Flags](#flags-vttablet)**
- **[Topology read concurrency behaviour changes](#topo-read-concurrency-changes)**
- **[VTAdmin](#vtadmin)**
- [Updated to node v22.13.1](#updated-node)

## <a id="major-changes"/>Major Changes</a>

### <a id="rpc-changes"/>RPC Changes</a>

These are the RPC changes made in this release -

1. `GetTransactionInfo` RPC has been added to both `VtctldServer`, and `TabletManagerClient` interface. These RPCs are used to fecilitate the users in reading the state of an unresolved distributed transaction. This can be useful in debugging what went wrong and how to fix the problem.
1. `GetTransactionInfo` RPC has been added to both `VtctldServer`, and `TabletManagerClient` interface. These RPCs are used to facilitate the users in reading the state of an unresolved distributed transaction. This can be useful in debugging what went wrong and how to fix the problem.

### <a id="deprecations-and-deletions"/>Deprecations and Deletions</a>

Expand Down Expand Up @@ -132,6 +135,10 @@ This is the last time this will be needed in the `8.0.x` series, as starting wit

The base system now uses Debian Bookworm instead of Debian Bullseye for the `vitess/lite` images. This change was brought by [Pull Request #17552].

### <a id="query-logs"/>Support for Filtering Query logs on Error</a>

The `querylog-mode` setting can be configured to `error` to log only queries that result in errors. This option is supported in both VTGate and VTTablet.

## <a id="minor-changes"/>Minor Changes</a>

#### <a id="flags-vttablet"/>VTTablet Flags</a>
Expand All @@ -145,3 +152,10 @@ While the flag will continue to accept float values (interpreted as seconds) for
The `--topo_read_concurrency` flag was added to all components that access the topology and the provided limit is now applied separately for each global or local cell _(default `32`)_.

All topology read calls _(`Get`, `GetVersion`, `List` and `ListDir`)_ now respect this per-cell limit. Previous to this version a single limit was applied to all cell calls and it was not respected by many topology calls.

### <a id="vtadmin"/>VTAdmin

#### <a id="updated-node"/>vtadmin-web updated to node v22.13.1 (LTS)

Building `vtadmin-web` now requires node >= v22.13.0 (LTS). Breaking changes from v20 to v22 can be found at https://nodejs.org/en/blog/release/v22.13.0 -- with no known issues that apply to VTAdmin.
Full details on the node v20.12.2 release can be found at https://nodejs.org/en/blog/release/v22.13.1.
2 changes: 1 addition & 1 deletion docker/binaries/vtadmin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ARG DEBIAN_VER=bookworm-slim

FROM vitess/lite:${VT_BASE_VER} AS lite

FROM node:20-${DEBIAN_VER} as node
FROM node:22-${DEBIAN_VER} as node

# Prepare directory structure.
RUN mkdir -p /vt/web
Expand Down
11 changes: 7 additions & 4 deletions go/cmd/vtcombo/cli/vschema_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ func loadKeyspacesFromDir(ctx context.Context, dir string, ts *topo.Server) {
log.Fatalf("Unable to read keyspace file %v: %v", ksFile, err)
}

keyspace := &vschemapb.Keyspace{}
err = json.Unmarshal(jsonData, keyspace)
ksvs := &topo.KeyspaceVSchemaInfo{
Name: ks.Name,
Keyspace: &vschemapb.Keyspace{},
}
err = json.Unmarshal(jsonData, ksvs.Keyspace)
if err != nil {
log.Fatalf("Unable to parse keyspace file %v: %v", ksFile, err)
}

_, err = vindexes.BuildKeyspace(keyspace, env.Parser())
_, err = vindexes.BuildKeyspace(ksvs.Keyspace, env.Parser())
if err != nil {
log.Fatalf("Invalid keyspace definition: %v", err)
}
ts.SaveVSchema(ctx, ks.Name, keyspace)
ts.SaveVSchema(ctx, ksvs)
log.Infof("Loaded keyspace %v from %v\n", ks.Name, ksFile)
}
}
Expand Down
267 changes: 267 additions & 0 deletions go/cmd/vtctldclient/command/framework_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/*
Copyright 2025 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 command

import (
"context"
"net"
"net/http"
"testing"
"time"

"github.com/stretchr/testify/require"
"google.golang.org/grpc"

"vitess.io/vitess/go/mysql/fakesqldb"
"vitess.io/vitess/go/vt/binlog/binlogplayer"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/mysqlctl"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/vtenv"
"vitess.io/vitess/go/vt/vttablet/grpctmserver"
"vitess.io/vitess/go/vt/vttablet/tabletconntest"
"vitess.io/vitess/go/vt/vttablet/tabletmanager"
"vitess.io/vitess/go/vt/vttablet/tabletmanager/vreplication"
"vitess.io/vitess/go/vt/vttablet/tabletservermock"
"vitess.io/vitess/go/vt/vttablet/tmclient"

querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"

// Import the gRPC client implementation for tablet manager.
_ "vitess.io/vitess/go/vt/vttablet/grpctmclient"

// Import the gRPC client implementation for query service.
_ "vitess.io/vitess/go/vt/vttablet/grpctabletconn"
)

func init() {
tabletconntest.SetProtocol("go.cmd.vtctldclient.command", "grpc")
}

// This file contains utility methods for unit tests.
// We allow the creation of fake tablets, and running their event loop based
// on a FakeMysqlDaemon.

// FakeTablet keeps track of a fake tablet in memory. It has:
// - a Tablet record (used for creating the tablet, kept for user's information)
// - a FakeMysqlDaemon (used by the fake event loop)
// - a 'done' channel (used to terminate the fake event loop)
type FakeTablet struct {
// Tablet and FakeMysqlDaemon are populated at NewFakeTablet time.
// We also create the RPCServer, so users can register more services
// before calling StartActionLoop().
Tablet *topodatapb.Tablet
FakeMysqlDaemon *mysqlctl.FakeMysqlDaemon
RPCServer *grpc.Server

// The following fields are created when we start the event loop for
// the tablet, and closed / cleared when we stop it.
// The Listener is used by the gRPC server.
TM *tabletmanager.TabletManager
Listener net.Listener

// These optional fields are used if the tablet also needs to
// listen on the 'vt' port.
StartHTTPServer bool
HTTPListener net.Listener
HTTPServer *http.Server
}

// TabletOption is an interface for changing tablet parameters.
// It's a way to pass multiple parameters to NewFakeTablet without
// making it too cumbersome.
type TabletOption func(tablet *topodatapb.Tablet)

// TabletKeyspaceShard is the option to set the tablet keyspace and shard
func TabletKeyspaceShard(t *testing.T, keyspace, shard string) TabletOption {
return func(tablet *topodatapb.Tablet) {
tablet.Keyspace = keyspace
shard, kr, err := topo.ValidateShardName(shard)
if err != nil {
require.FailNow(t, "cannot ValidateShardName value %v", shard)
}
tablet.Shard = shard
tablet.KeyRange = kr
}
}

// ForceInitTablet is the tablet option to set the 'force' flag during InitTablet
func ForceInitTablet() TabletOption {
return func(tablet *topodatapb.Tablet) {
// set the force_init field into the portmap as a hack
tablet.PortMap["force_init"] = 1
}
}

// StartHTTPServer is the tablet option to start the HTTP server when
// starting a tablet.
func StartHTTPServer() TabletOption {
return func(tablet *topodatapb.Tablet) {
// set the start_http_server field into the portmap as a hack
tablet.PortMap["start_http_server"] = 1
}
}

// NewFakeTablet creates the test tablet in the topology. 'uid'
// has to be between 0 and 99. All the tablet info will be derived
// from that. Look at the implementation if you need values.
// Use TabletOption implementations if you need to change values at creation.
// 'db' can be nil if the test doesn't use a database at all.
func NewFakeTablet(t *testing.T, ts *topo.Server, cell string, uid uint32, tabletType topodatapb.TabletType, db *fakesqldb.DB, options ...TabletOption) *FakeTablet {
t.Helper()

if uid > 99 {
require.FailNow(t, "uid has to be between 0 and 99: %v", uid)
}
mysqlPort := int32(3300 + uid)
tablet := &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{Cell: cell, Uid: uid},
Hostname: "127.0.0.1",
MysqlHostname: "127.0.0.1",
PortMap: map[string]int32{
"vt": int32(8100 + uid),
"grpc": int32(8200 + uid),
},
Keyspace: "test_keyspace",
Shard: "0",
Type: tabletType,
}
tablet.MysqlPort = mysqlPort
for _, option := range options {
option(tablet)
}
_, startHTTPServer := tablet.PortMap["start_http_server"]
delete(tablet.PortMap, "start_http_server")
_, force := tablet.PortMap["force_init"]
delete(tablet.PortMap, "force_init")
if err := ts.InitTablet(context.Background(), tablet, force, true /* createShardAndKeyspace */, false /* allowUpdate */); err != nil {
require.FailNow(t, "cannot create tablet %v: %v", uid, err)
}

// create a FakeMysqlDaemon with the right information by default.
fakeMysqlDaemon := mysqlctl.NewFakeMysqlDaemon(db)
fakeMysqlDaemon.MysqlPort.Store(mysqlPort)

return &FakeTablet{
Tablet: tablet,
FakeMysqlDaemon: fakeMysqlDaemon,
RPCServer: grpc.NewServer(),
StartHTTPServer: startHTTPServer,
}
}

// StartActionLoop will start the action loop for a fake tablet,
// using ft.FakeMysqlDaemon as the backing mysqld.
func (ft *FakeTablet) StartActionLoop(t *testing.T, ts *topo.Server) {
t.Helper()
if ft.TM != nil {
require.FailNow(t, "TM for %v is already running", ft.Tablet.Alias)
}

// Listen on a random port for gRPC.
var err error
ft.Listener, err = net.Listen("tcp", "127.0.0.1:0")
if err != nil {
require.FailNow(t, "Cannot listen: %v", err)
}
gRPCPort := int32(ft.Listener.Addr().(*net.TCPAddr).Port)

// If needed, listen on a random port for HTTP.
vtPort := ft.Tablet.PortMap["vt"]
if ft.StartHTTPServer {
ft.HTTPListener, err = net.Listen("tcp", "127.0.0.1:0")
if err != nil {
require.FailNow(t, "Cannot listen on http port: %v", err)
}
handler := http.NewServeMux()
ft.HTTPServer = &http.Server{
Handler: handler,
}
go func() {
_ = ft.HTTPServer.Serve(ft.HTTPListener)
}()
vtPort = int32(ft.HTTPListener.Addr().(*net.TCPAddr).Port)
}
ft.Tablet.PortMap["vt"] = vtPort
ft.Tablet.PortMap["grpc"] = gRPCPort
ft.Tablet.Hostname = "127.0.0.1"

// Create a test tm on that port, and re-read the record
// (it has new ports and IP).
ft.TM = &tabletmanager.TabletManager{
BatchCtx: context.Background(),
TopoServer: ts,
MysqlDaemon: ft.FakeMysqlDaemon,
DBConfigs: &dbconfigs.DBConfigs{},
QueryServiceControl: tabletservermock.NewController(),
VREngine: vreplication.NewTestEngine(ts, ft.Tablet.Alias.Cell, ft.FakeMysqlDaemon, binlogplayer.NewFakeDBClient, binlogplayer.NewFakeDBClient, topoproto.TabletDbName(ft.Tablet), nil),
Env: vtenv.NewTestEnv(),
}
if err := ft.TM.Start(ft.Tablet, nil); err != nil {
require.FailNow(t, "Error in tablet - %v, err - %v", topoproto.TabletAliasString(ft.Tablet.Alias), err.Error())
}
ft.Tablet = ft.TM.Tablet()

// Register the gRPC server, and starts listening.
grpctmserver.RegisterForTest(ft.RPCServer, ft.TM)
go ft.RPCServer.Serve(ft.Listener)

// And wait for it to serve, so we don't start using it before it's
// ready.
timeout := 5 * time.Second
step := 10 * time.Millisecond
c := tmclient.NewTabletManagerClient()
for timeout >= 0 {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
err := c.Ping(ctx, ft.TM.Tablet())
cancel()
if err == nil {
break
}
time.Sleep(step)
timeout -= step
}
if timeout < 0 {
panic("StartActionLoop failed.")
}
}

// StopActionLoop will stop the Action Loop for the given FakeTablet
func (ft *FakeTablet) StopActionLoop(t *testing.T) {
if ft.TM == nil {
return
}
if ft.StartHTTPServer {
ft.HTTPListener.Close()
}
ft.Listener.Close()
ft.TM.Stop()
ft.TM = nil
ft.Listener = nil
ft.HTTPListener = nil
}

// Target returns the keyspace/shard/type info of this tablet as Target.
func (ft *FakeTablet) Target() *querypb.Target {
return &querypb.Target{
Keyspace: ft.Tablet.Keyspace,
Shard: ft.Tablet.Shard,
TabletType: ft.Tablet.Type,
}
}
Loading

0 comments on commit 918d02e

Please sign in to comment.