Skip to content

Commit

Permalink
Merge pull request #515 from planetscale/create-pull-request/patch
Browse files Browse the repository at this point in the history
Upgrade Vitess Dependency to Latest
  • Loading branch information
GuptaManan100 authored Dec 28, 2023
2 parents 63128e4 + cd5c5d1 commit c0fb25c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 15 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
sigs.k8s.io/controller-runtime v0.14.3
sigs.k8s.io/controller-tools v0.11.3
sigs.k8s.io/kustomize v2.0.3+incompatible
vitess.io/vitess v0.10.3-0.20231215192727-7c9fec7205cb
vitess.io/vitess v0.10.3-0.20231222054134-d807985131ed
)

require (
Expand Down Expand Up @@ -148,7 +148,7 @@ require (
go.uber.org/zap v1.24.0 // indirect
go4.org/intern v0.0.0-20230205224052-192e9f60865c // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230426161633-7e06285ff160 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1186,5 +1186,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ih
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
vitess.io/vitess v0.10.3-0.20231215192727-7c9fec7205cb h1:dNI30GuQx70LgnhhJaPAOyzF1DkNuTgpypAJ2OrGM30=
vitess.io/vitess v0.10.3-0.20231215192727-7c9fec7205cb/go.mod h1:klf5QIzty1+nq+FXHFmimgRA5lh4DhP9edrrKPGDNgY=
vitess.io/vitess v0.10.3-0.20231222054134-d807985131ed h1:XHwJFwKTCWu2Mo3B8+41TOVGzGTHIzqU69yG+TmUSlM=
vitess.io/vitess v0.10.3-0.20231222054134-d807985131ed/go.mod h1:fIPsR9+FuCA/QwknylRPp0buFk41Tl9KNhOQPQTm+5Y=
7 changes: 6 additions & 1 deletion pkg/controller/vitesskeyspace/reconcile_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"vitess.io/vitess/go/vt/wrangler"

v2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2"
"planetscale.dev/vitess-operator/pkg/operator/environment"
"planetscale.dev/vitess-operator/pkg/operator/reconciler"
"planetscale.dev/vitess-operator/pkg/operator/toposerver"
)
Expand Down Expand Up @@ -74,9 +75,13 @@ func (r *reconcileHandler) tsInit(ctx context.Context) error {
r.tmc = tmclient.NewTabletManagerClient()
}

collationEnv, parser, err := environment.CollationEnvAndParser()
if err != nil {
return err
}
// Wrangler wraps the necessary clients and implements
// multi-step Vitess cluster management workflows.
wr := wrangler.New(logutil.NewConsoleLogger(), r.ts.Server, r.tmc)
wr := wrangler.New(logutil.NewConsoleLogger(), r.ts.Server, r.tmc, collationEnv, parser)
r.wr = wr

return nil
Expand Down
11 changes: 8 additions & 3 deletions pkg/controller/vitessshard/reconcile_topo.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"vitess.io/vitess/go/vt/wrangler"

planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2"
"planetscale.dev/vitess-operator/pkg/operator/environment"
"planetscale.dev/vitess-operator/pkg/operator/k8s"
"planetscale.dev/vitess-operator/pkg/operator/results"
"planetscale.dev/vitess-operator/pkg/operator/toposerver"
Expand Down Expand Up @@ -63,7 +64,11 @@ func (r *ReconcileVitessShard) reconcileTopology(ctx context.Context, vts *plane
return resultBuilder.RequeueAfter(topoRequeueDelay)
}
defer ts.Close()
wr := wrangler.New(logutil.NewConsoleLogger(), ts.Server, nil)
collationEnv, parser, err := environment.CollationEnvAndParser()
if err != nil {
return resultBuilder.Error(err)
}
wr := wrangler.New(logutil.NewConsoleLogger(), ts.Server, nil, collationEnv, parser)

// Get the shard record.
if shard, err := ts.GetShard(ctx, keyspaceName, vts.Spec.Name); err == nil {
Expand Down Expand Up @@ -168,8 +173,8 @@ func (r *ReconcileVitessShard) pruneShardCells(ctx context.Context, vts *planets
Keyspace: keyspaceName,
ShardName: vts.Spec.Name,
Cell: cellName,
Force: false /* force */,
Recursive: false /* recursive */,
Force: false, /* force */
Recursive: false, /* recursive */
}); err != nil {
r.recorder.Eventf(vts, corev1.EventTypeWarning, "TopoCleanupFailed", "unable to remove cell %s from shard: %v", cellName, err)
resultBuilder.RequeueAfter(topoRequeueDelay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"time"

"github.com/sirupsen/logrus"

"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/vttablet/tmclient"
"vitess.io/vitess/go/vt/wrangler"
Expand Down Expand Up @@ -195,9 +194,13 @@ func (r *ReconcileVitessShard) Reconcile(cctx context.Context, request reconcile
tmc := tmclient.NewTabletManagerClient()
defer tmc.Close()

collationEnv, parser, err := environment.CollationEnvAndParser()
if err != nil {
return resultBuilder.Error(err)
}
// Wrangler wraps the necessary clients and implements
// multi-step Vitess cluster management workflows.
wr := wrangler.New(logutil.NewConsoleLogger(), ts.Server, tmc)
wr := wrangler.New(logutil.NewConsoleLogger(), ts.Server, tmc, collationEnv, parser)

// Initialize replication if it has not already been started.
initReplicationResult, err := r.initReplication(ctx, vts, wr)
Expand Down
20 changes: 19 additions & 1 deletion pkg/operator/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ import (
"time"

"github.com/spf13/pflag"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/vt/sqlparser"

planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2"
)

var (
reconcileTimeout time.Duration
reconcileTimeout time.Duration
mySQLServerVersion = "8.0.30-Vitess"
// truncateUILen truncate queries in debug UIs to the given length. 0 means unlimited.
truncateUILen = 512
// truncateErrLen truncate queries in error logs to the given length. 0 means unlimited.
truncateErrLen = 0
)

// FlagSet returns the FlagSet for the operator.
Expand Down Expand Up @@ -58,3 +65,14 @@ func FlagSet() *pflag.FlagSet {
func ReconcileTimeout() time.Duration {
return reconcileTimeout
}

// CollationEnvAndParser gets the collation environment and parser to be used in the operator.
func CollationEnvAndParser() (*collations.Environment, *sqlparser.Parser, error) {
collationEnv := collations.NewEnvironment(mySQLServerVersion)
parser, err := sqlparser.New(sqlparser.Options{
MySQLServerVersion: mySQLServerVersion,
TruncateUILen: truncateUILen,
TruncateErrLen: truncateErrLen,
})
return collationEnv, parser, err
}
7 changes: 6 additions & 1 deletion pkg/operator/vitesstopo/prune_keyspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"vitess.io/vitess/go/vt/wrangler"

planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2"
"planetscale.dev/vitess-operator/pkg/operator/environment"
"planetscale.dev/vitess-operator/pkg/operator/results"

vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
Expand Down Expand Up @@ -91,9 +92,13 @@ func KeyspacesToPrune(keyspaceNames []string, desiredKeyspaces sets.String, orph
func DeleteKeyspaces(ctx context.Context, ts *topo.Server, recorder record.EventRecorder, eventObj runtime.Object, keyspaceNames []string) (reconcile.Result, error) {
resultBuilder := &results.Builder{}

collationEnv, parser, err := environment.CollationEnvAndParser()
if err != nil {
return resultBuilder.Error(err)
}
// We use the Vitess wrangler (multi-step command executor) to recursively delete the keyspace.
// This is equivalent to `vtctl DeleteKeyspace -recursive`.
wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil)
wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil, collationEnv, parser)

for _, name := range keyspaceNames {
// Before we delete a keyspace, we must delete vschema for this operation to be idempotent.
Expand Down
8 changes: 7 additions & 1 deletion pkg/operator/vitesstopo/prune_shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"vitess.io/vitess/go/vt/wrangler"

planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2"
"planetscale.dev/vitess-operator/pkg/operator/environment"
"planetscale.dev/vitess-operator/pkg/operator/results"
)

Expand Down Expand Up @@ -83,9 +84,14 @@ func ShardsToPrune(currentShards []string, desiredShards sets.String, orphanedSh
func DeleteShards(ctx context.Context, ts *topo.Server, recorder record.EventRecorder, eventObj runtime.Object, keyspaceName string, shardNames []string) (reconcile.Result, error) {
resultBuilder := &results.Builder{}

collationEnv, parser, err := environment.CollationEnvAndParser()
if err != nil {
return resultBuilder.Error(err)
}

// We use the Vitess wrangler (multi-step command executor) to recursively delete the shard.
// This is equivalent to `vtctl DeleteShard -recursive`.
wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil)
wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil, collationEnv, parser)

for _, name := range shardNames {
// topo.NoNode is the error type returned if we can't find the shard when deleting. This ensures that this operation is idempotent.
Expand Down

0 comments on commit c0fb25c

Please sign in to comment.