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

[vtctld] Fix accidentally-broken legacy vtctl output format #7285

Merged
merged 1 commit into from
Jan 12, 2021

Conversation

ajm188
Copy link
Contributor

@ajm188 ajm188 commented Jan 12, 2021

This was a regression introduced in #7128.

Description

This restores the original json format of the old vtctl API, which I broke when trying to reimplement the old API in terms of the new. Example (using the local example): first the new, changed output, and then the old, correct output:

❯ vtctlclient -server "localhost:15999" FindAllShardsInKeyspace commerce
{
  "0": {
    "keyspace": "commerce",
    "name": "0",
    "shard": {
      "master_alias": {
        "cell": "zone1",
        "uid": 100
      },
      "master_term_start_time": {
        "seconds": 1610412569,
        "nanoseconds": 995650000
      },
      "is_master_serving": true
    }
  }
}
❯ cd -
~/work/vitess
❯ make build
Mon Jan 11 19:50:24 EST 2021: Building source tree
❯ cd -
~/work/vitess/examples/local
❯ ./scripts/vtctld-down.sh
Stopping vtctld...
❯ ./scripts/vtctld-up.sh
Starting vtctld...
❯ vtctlclient -server "localhost:15999" FindAllShardsInKeyspace commerce
{
  "0": {
    "master_alias": {
      "cell": "zone1",
      "uid": 100
    },
    "master_term_start_time": {
      "seconds": 1610412569,
      "nanoseconds": 995650000
    },
    "is_master_serving": true
  }
}

Related Issue(s)

Checklist

  • Should this PR be backported? No (it hasn't been actually released yet)
  • Tests were added or are not required Probably should?
  • Documentation was added or is not required N/A

Deployment Notes

Impacted Areas in Vitess

Components that this PR will affect:

  • Query Serving
  • VReplication
  • Cluster Management
  • Build
  • VTAdmin

Signed-off-by: Andrew Mason <amason@slack-corp.com>
@doeg
Copy link
Contributor

doeg commented Jan 12, 2021

+1 with the acknowledgement of :

Tests were added or are not required Probably should?

Let me know if I can help with that! 🌻

Copy link
Contributor

@setassociative setassociative left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth calling out that this was confirmed by observing that the fixed output still works with our tooling that expects the old format

Copy link
Member

@rafael rafael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well. Merging this as is.

One follow up question: are there other places were this code change could have introduced a similar regression? I didn't look in the detail the previous change where the regression was originally introduced.

@rafael rafael merged commit 13ba0c8 into vitessio:master Jan 12, 2021
@rafael rafael deleted the am_fix_findallshardsinkeyspace branch January 12, 2021 04:28
@ajm188
Copy link
Contributor Author

ajm188 commented Jan 12, 2021

Here's the entire diff to vtctl.go that I've made over the 3 PRs. Everything else has been additive to the new interface instead:

diff --git a/go/vt/vtctl/vtctl.go b/go/vt/vtctl/vtctl.go
index 97b7ac8513..e33d20e082 100644
--- a/go/vt/vtctl/vtctl.go
+++ b/go/vt/vtctl/vtctl.go
@@ -1761,20 +1761,29 @@ func commandGetKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags *fl
 	}
 
 	keyspace := subFlags.Arg(0)
-	keyspaceInfo, err := wr.TopoServer().GetKeyspace(ctx, keyspace)
+
+	keyspaceInfo, err := wr.VtctldServer().GetKeyspace(ctx, &vtctldatapb.GetKeyspaceRequest{
+		Keyspace: keyspace,
+	})
 	if err != nil {
 		return err
 	}
 	// Pass the embedded proto directly or jsonpb will panic.
-	return printJSON(wr.Logger(), keyspaceInfo.Keyspace)
+	return printJSON(wr.Logger(), keyspaceInfo.Keyspace.Keyspace)
 }
 
 func commandGetKeyspaces(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {
-	keyspaces, err := wr.TopoServer().GetKeyspaces(ctx)
+	resp, err := wr.VtctldServer().GetKeyspaces(ctx, &vtctldatapb.GetKeyspacesRequest{})
 	if err != nil {
 		return err
 	}
-	wr.Logger().Printf("%v\n", strings.Join(keyspaces, "\n"))
+
+	names := make([]string, len(resp.Keyspaces))
+	for i, ks := range resp.Keyspaces {
+		names[i] = ks.Name
+	}
+
+	wr.Logger().Printf("%v\n", strings.Join(names, "\n"))
 	return nil
 }
 
@@ -2208,11 +2217,14 @@ func commandFindAllShardsInKeyspace(ctx context.Context, wr *wrangler.Wrangler,
 	}
 
 	keyspace := subFlags.Arg(0)
-	result, err := wr.TopoServer().FindAllShardsInKeyspace(ctx, keyspace)
+	result, err := wr.VtctldServer().FindAllShardsInKeyspace(ctx, &vtctldatapb.FindAllShardsInKeyspaceRequest{
+		Keyspace: keyspace,
+	})
 	if err != nil {
 		return err
 	}
-	return printJSON(wr.Logger(), result)
+
+	return printJSON(wr.Logger(), result.Shards)
 }
 
 func commandValidate(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error {

ajm188 pushed a commit to tinyspeck/vitess that referenced this pull request Jan 12, 2021
…nkeyspace

[vtctld] Fix accidentally-broken legacy vtctl output format
@deepthi
Copy link
Member

deepthi commented Jan 12, 2021

@ajm188 can you please create a PR to fix this for the 9.0 release branch?

@ajm188
Copy link
Contributor Author

ajm188 commented Jan 12, 2021

Yep, I'll have one out tomorrow!

ajm188 pushed a commit to tinyspeck/vitess that referenced this pull request Jan 13, 2021
…nkeyspace

[vtctld] Fix accidentally-broken legacy vtctl output format

Signed-off-by: Andrew Mason <amason@slack-corp.com>
@askdba askdba added this to the v9.0 milestone Jan 19, 2021
@ajm188 ajm188 mentioned this pull request Feb 2, 2021
8 tasks
setassociative pushed a commit to tinyspeck/vitess that referenced this pull request Mar 11, 2021
…nkeyspace

[vtctld] Fix accidentally-broken legacy vtctl output format
@ajm188 ajm188 added this to In progress in Vtctld Service via automation May 23, 2021
@ajm188 ajm188 moved this from In progress to Done in Vtctld Service May 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants