Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport-2.1: storage, roachtest, cli: assorted backports #29390

Merged
merged 5 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pkg/cli/cli_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

package cli

import (
"path/filepath"
"strings"
"testing"

"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
)

func Example_debug_decode_key_value() {
cliTest{}.RunWithArgs([]string{"debug", "decode-value", "016b12bd8980c0b6c2e211ba5182000172647363", "884d186d03089b09120bbd8980c0b6c2e211ba51821a0bbd8980c0b9e7c5c610e99622060801100118012206080410041802220608021002180428053004"})

Expand All @@ -25,3 +34,39 @@ func Example_debug_decode_key_value() {
// 0.987654321,0 /Local/Range/Table/53/1/-4560243296450227838/RangeDescriptor: [/Table/53/1/-4560243296450227838, /Table/53/1/-4559358311118345834)
// Raw:r1179:/Table/53/1/-45{60243296450227838-59358311118345834} [(n1,s1):1, (n4,s4):2, (n2,s2):4, next=5, gen=4]
}

func TestDebugKeysHex(t *testing.T) {
defer leaktest.AfterTest(t)()

baseDir, dirCleanupFn := testutils.TempDir(t)
defer dirCleanupFn()

storePath := filepath.Join(baseDir, "store")
createStore(t, storePath)

{
out, err := cliTest{}.RunWithCapture("debug keys " + storePath +
" --from hex:016b12bd898090d79e52e79b0144000174786e2d733fb094e9aa4d67974c71486b9823b900" +
" --to hex:016b12bd898090d79e52e79b0144000174786e2d733fb094e9aa4d67974c71486b9823b900")
if err != nil {
t.Fatal(err)
}
// Should just output the command invocation and no results.
if !strings.HasSuffix(strings.TrimSpace(out), "b900") {
t.Fatalf("%q", out)
}
}

// Test invalid key, verify we get a good suggestion back.
out, err := cliTest{}.RunWithCapture("debug keys " + storePath +
" --to hex:01")
if err != nil {
t.Fatal(err)
}
expOut := `invalid argument "hex:01" for "--to" flag: perhaps this is just a hex-encoded key; ` +
`you need an encoded MVCCKey (i.e. with a timestamp component); here's one with a zero timestamp: ` +
`0100: invalid encoded mvcc key: 01`
if !strings.Contains(out, expOut) {
t.Fatalf("%q", out)
}
}
8 changes: 4 additions & 4 deletions pkg/cli/cliflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,17 +673,17 @@ database, insecure, certs).`,
From = FlagInfo{
Name: "from",
Description: `
Start key and format as [<format>:]<key>. Supported formats: raw, human,
Start key and format as [<format>:]<key>. Supported formats: raw, hex, human,
rangeID. The raw format supports escaped text. For example, "raw:\x01k" is the
prefix for range local keys.`,
prefix for range local keys. The hex format takes an encoded MVCCKey.`,
}

To = FlagInfo{
Name: "to",
Description: `
Exclusive end key and format as [<format>:]<key>. Supported formats: raw,
Exclusive end key and format as [<format>:]<key>. Supported formats: raw, hex,
human, rangeID. The raw format supports escaped text. For example, "raw:\x01k"
is the prefix for range local keys.`}
is the prefix for range local keys. The hex format takes an encoded MVCCKey.`}

Values = FlagInfo{
Name: "values",
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"bufio"
"bytes"
"context"
"encoding/hex"
gohex "encoding/hex"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -337,7 +337,7 @@ Decode a hexadecimal-encoded key and pretty-print it. For example:
Args: cobra.ArbitraryArgs,
RunE: func(cmd *cobra.Command, args []string) error {
for _, arg := range args {
b, err := hex.DecodeString(arg)
b, err := gohex.DecodeString(arg)
if err != nil {
return err
}
Expand All @@ -364,7 +364,7 @@ Decode and print a hexadecimal-encoded key-value pair.
RunE: func(cmd *cobra.Command, args []string) error {
var bs [][]byte
for _, arg := range args {
b, err := hex.DecodeString(arg)
b, err := gohex.DecodeString(arg)
if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/cli/flags_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cli

import (
"context"
gohex "encoding/hex"
"fmt"
"math"
"regexp"
Expand Down Expand Up @@ -166,6 +167,19 @@ func (k *mvccKey) Set(value string) error {
}

switch typ {
case hex:
b, err := gohex.DecodeString(keyStr)
if err != nil {
return err
}
newK, err := engine.DecodeKey(b)
if err != nil {
encoded := gohex.EncodeToString(engine.EncodeKey(engine.MakeMVCCMetadataKey(roachpb.Key(b))))
return errors.Wrapf(err, "perhaps this is just a hex-encoded key; you need an "+
"encoded MVCCKey (i.e. with a timestamp component); here's one with a zero timestamp: %s",
encoded)
}
*k = mvccKey(newK)
case raw:
unquoted, err := unquoteArg(keyStr)
if err != nil {
Expand Down Expand Up @@ -208,6 +222,7 @@ const (
raw keyType = iota
human
rangeID
hex
)

// _keyTypes stores the names of all the possible key types.
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/keytype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 40 additions & 1 deletion pkg/cmd/roachtest/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,52 @@ func TestClusterMonitor(t *testing.T) {
return ctx.Err()
})

err := m.wait(`echo`, `1`)
err := m.wait(`sleep`, `100`)
expectedErr := `worker-fail`
if !testutils.IsError(err, expectedErr) {
t.Errorf(`expected %s err got: %+v`, expectedErr, err)
}
})

t.Run(`wait-fail`, func(t *testing.T) {
c := &cluster{t: t, l: logger}
m := newMonitor(context.Background(), c)
m.Go(func(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
})
m.Go(func(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
})

// Returned error should be that from the wait command.
err := m.wait(`false`)
expectedErr := `exit status`
if !testutils.IsError(err, expectedErr) {
t.Errorf(`expected %s err got: %+v`, expectedErr, err)
}
})

t.Run(`wait-ok`, func(t *testing.T) {
c := &cluster{t: t, l: logger}
m := newMonitor(context.Background(), c)
m.Go(func(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
})
m.Go(func(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
})

// If wait terminates, context gets canceled.
err := m.wait(`true`)
if err != context.Canceled {
t.Errorf(`expected context canceled, got: %+v`, err)
}
})

// NB: the forker sleeps in these tests actually get leaked, so it's important to let
// them finish pretty soon (think stress testing). As a matter of fact, `make test` waits
// for these child goroutines to finish (so these tests take seconds).
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/closed_timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

func TestClosedTimestampCanServe(t *testing.T) {
defer leaktest.AfterTest(t)()
t.Skip("https://github.com/cockroachdb/cockroach/issues/28607")

ctx := context.Background()
const numNodes = 3
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/replica_sideload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,15 +735,15 @@ func TestRaftSSTableSideloadingSnapshot(t *testing.T) {

ctx := context.Background()
tc := testContext{}
stopper := stop.NewStopper()
defer stopper.Stop(ctx)

cleanup, cache, eng := newRocksDB(t)
tc.engine = eng
defer cleanup()
defer cache.Release()
defer eng.Close()

stopper := stop.NewStopper()
defer stopper.Stop(ctx)
tc.Start(t, stopper)

var ba roachpb.BatchRequest
Expand Down