Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix-vschemaddl-flake
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Sep 27, 2023
2 parents 274366d + b793adf commit b4c0f9d
Show file tree
Hide file tree
Showing 50 changed files with 2,629 additions and 1,373 deletions.
6 changes: 3 additions & 3 deletions go/cmd/vtctldclient/command/onlineddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
}
OnlineDDLCancel = &cobra.Command{
Use: "cancel <keyspace> <uuid|all>",
Short: "cancel one or all migrations, terminating any running ones as needed.",
Short: "Cancel one or all migrations, terminating any running ones as needed.",
Example: "OnlineDDL cancel test_keyspace 82fa54ac_e83e_11ea_96b7_f875a4d24e90",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
Expand All @@ -64,15 +64,15 @@ var (
}
OnlineDDLComplete = &cobra.Command{
Use: "complete <keyspace> <uuid|all>",
Short: "complete one or all migrations executed with --postpone-completion",
Short: "Complete one or all migrations executed with --postpone-completion",
Example: "OnlineDDL complete test_keyspace 82fa54ac_e83e_11ea_96b7_f875a4d24e90",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandOnlineDDLComplete,
}
OnlineDDLLaunch = &cobra.Command{
Use: "launch <keyspace> <uuid|all>",
Short: "launch one or all migrations executed with --postpone-launch",
Short: "Launch one or all migrations executed with --postpone-launch",
Example: "OnlineDDL launch test_keyspace 82fa54ac_e83e_11ea_96b7_f875a4d24e90",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
Expand Down
36 changes: 36 additions & 0 deletions go/cmd/zk/command/add_auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023 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 agreedto 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 (
"github.com/spf13/cobra"
)

var AddAuth = &cobra.Command{
Use: "addAuth <digest> <user:pass>",
Args: cobra.ExactArgs(2),
RunE: commandAddAuth,
}

func commandAddAuth(cmd *cobra.Command, args []string) error {
scheme, auth := cmd.Flags().Arg(0), cmd.Flags().Arg(1)
return fs.Conn.AddAuth(cmd.Context(), scheme, []byte(auth))
}

func init() {
Root.AddCommand(AddAuth)
}
103 changes: 103 additions & 0 deletions go/cmd/zk/command/cat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
Copyright 2023 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 agreedto 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 (
"fmt"
"os"

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

"vitess.io/vitess/go/cmd/zk/internal/zkfilepath"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/zk2topo"
)

var (
catArgs = struct {
LongListing bool
Force bool
DecodeProto bool
}{}

Cat = &cobra.Command{
Use: "cat <path1> [<path2> ...]",
Example: `zk cat /zk/path
# List filename before file data
zk cat -l /zk/path1 /zk/path2`,
Args: cobra.MinimumNArgs(1),
RunE: commandCat,
}
)

func commandCat(cmd *cobra.Command, args []string) error {
resolved, err := zk2topo.ResolveWildcards(cmd.Context(), fs.Conn, cmd.Flags().Args())
if err != nil {
return fmt.Errorf("cat: invalid wildcards: %w", err)
}
if len(resolved) == 0 {
// the wildcards didn't result in anything, we're done
return nil
}

hasError := false
for _, arg := range resolved {
zkPath := zkfilepath.Clean(arg)
data, _, err := fs.Conn.Get(cmd.Context(), zkPath)
if err != nil {
hasError = true
if !catArgs.Force || err != zk.ErrNoNode {
log.Warningf("cat: cannot access %v: %v", zkPath, err)
}
continue
}

if catArgs.LongListing {
fmt.Printf("%v:\n", zkPath)
}
decoded := ""
if catArgs.DecodeProto {
decoded, err = topo.DecodeContent(zkPath, data, false)
if err != nil {
log.Warningf("cat: cannot proto decode %v: %v", zkPath, err)
decoded = string(data)
}
} else {
decoded = string(data)
}
fmt.Print(decoded)
if len(decoded) > 0 && decoded[len(decoded)-1] != '\n' && (term.IsTerminal(int(os.Stdout.Fd())) || catArgs.LongListing) {
fmt.Print("\n")
}
}
if hasError {
return fmt.Errorf("cat: some paths had errors")
}
return nil
}

func init() {
Cat.Flags().BoolVarP(&catArgs.LongListing, "longListing", "l", false, "long listing")
Cat.Flags().BoolVarP(&catArgs.Force, "force", "f", false, "no warning on nonexistent node")
Cat.Flags().BoolVarP(&catArgs.DecodeProto, "decodeProto", "p", false, "decode proto files and display them as text")

Root.AddCommand(Cat)
}
91 changes: 91 additions & 0 deletions go/cmd/zk/command/chmod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Copyright 2023 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 agreedto 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 (
"fmt"

"github.com/spf13/cobra"

"vitess.io/vitess/go/cmd/zk/internal/zkfilepath"
"vitess.io/vitess/go/cmd/zk/internal/zkfs"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/topo/zk2topo"
)

var Chmod = &cobra.Command{
Use: "chmod <mode> <path>",
Example: `zk chmod n-mode /zk/path
zk chmod n+mode /zk/path`,
Args: cobra.MinimumNArgs(2),
RunE: commandChmod,
}

func commandChmod(cmd *cobra.Command, args []string) error {
mode := cmd.Flags().Arg(0)
if mode[0] != 'n' {
return fmt.Errorf("chmod: invalid mode")
}

addPerms := false
if mode[1] == '+' {
addPerms = true
} else if mode[1] != '-' {
return fmt.Errorf("chmod: invalid mode")
}

permMask := zkfs.ParsePermMode(mode[2:])

resolved, err := zk2topo.ResolveWildcards(cmd.Context(), fs.Conn, cmd.Flags().Args()[1:])
if err != nil {
return fmt.Errorf("chmod: invalid wildcards: %w", err)
}
if len(resolved) == 0 {
// the wildcards didn't result in anything, we're done
return nil
}

hasError := false
for _, arg := range resolved {
zkPath := zkfilepath.Clean(arg)
aclv, _, err := fs.Conn.GetACL(cmd.Context(), zkPath)
if err != nil {
hasError = true
log.Warningf("chmod: cannot set access %v: %v", zkPath, err)
continue
}
if addPerms {
aclv[0].Perms |= permMask
} else {
aclv[0].Perms &= ^permMask
}
err = fs.Conn.SetACL(cmd.Context(), zkPath, aclv, -1)
if err != nil {
hasError = true
log.Warningf("chmod: cannot set access %v: %v", zkPath, err)
continue
}
}
if hasError {
return fmt.Errorf("chmod: some paths had errors")
}
return nil
}

func init() {
Root.AddCommand(Chmod)
}
43 changes: 43 additions & 0 deletions go/cmd/zk/command/cp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2023 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 agreedto 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 "github.com/spf13/cobra"

var Cp = &cobra.Command{
Use: "cp <src> <dst>",
Example: `zk cp /zk/path .
zk cp ./config /zk/path/config
# Trailing slash indicates directory
zk cp ./config /zk/path/`,
Args: cobra.MinimumNArgs(2),
RunE: commandCp,
}

func commandCp(cmd *cobra.Command, args []string) error {
switch cmd.Flags().NArg() {
case 2:
return fs.CopyContext(cmd.Context(), cmd.Flags().Arg(0), cmd.Flags().Arg(1))
default:
return fs.MultiCopyContext(cmd.Context(), cmd.Flags().Args())
}
}

func init() {
Root.AddCommand(Cp)
}
Loading

0 comments on commit b4c0f9d

Please sign in to comment.