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

sql: Add range size to SHOW RANGES command. #40281

Merged
merged 1 commit into from
Sep 3, 2019

Conversation

rohany
Copy link
Contributor

@rohany rohany commented Aug 28, 2019

Fixes #39767.

This is done by adding a new builtin function crdb_internal.range_stats that returns a json object containing stats about the requested range.

Release note (sql change): Add range size information to SHOW RANGES. Adds a builtin function crdb_internal.range_stats which returns a json object containing stats about the requested range.

@rohany rohany requested review from nvanbenschoten and a team August 28, 2019 04:17
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Thanks for getting this out so fast @rohany. There are a few things here that we'll likely want to change before merging this.

The first is that we almost certainly don't want to include this information in crdb_internal.ranges_no_leases. The reason for the split between crdb_internal.ranges_no_leases and crdb_internal.ranges is because crdb_internal.ranges is so much more expensive due to its per-range lookups. We created crdb_internal.ranges_no_leases as a means of quickly accessing the state about ranges that can be gathered exclusively from a meta keyspace scan so that we could continue to expose something relatively fast. This PR is regressing on this front. To avoid this, we'll only want to add this new column to crdb_internal.ranges.

Similarly, it doesn't seem particularly desirable to have the logic for retrieving these stats locked up inside of the virtual schema generator function. I would have expected us to introduce a builtin that mirrors crdb_internal.lease_holder and use that from crdb_internal.ranges. In fact, introducing a crdb_internal.range_stats builtin function that returns a JSON blob of a range's stats seems like a generally useful change in and of itself. We would then use this function from the crdb_internal.ranges view just like we use crdb_internal.lease_holder. Did you consider implementing this PR like that?

@jordanlewis should take a look at this as well, since he reviewed #30601.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten and @rohany)


pkg/sql/crdb_internal.go, line 1874 at r1 (raw file):

	split_enforced_until,
	crdb_internal.lease_holder(start_key) AS lease_holder,
  range_size

Mind fixing this spacing?


pkg/sql/crdb_internal.go, line 1910 at r1 (raw file):

  table_name           STRING NOT NULL,
  index_name           STRING NOT NULL,
	replicas             INT[] NOT NULL,

Mind fixing this spacing?

@rohany
Copy link
Contributor Author

rohany commented Aug 28, 2019

I can try implementing it like that via a built in, but I thought we wanted to batch the requests more, rather than doing individual lookups.

However it should be an easy change to expose a new built in function.

Re the spacing: it always looks fine on my editor....

@nvanbenschoten
Copy link
Member

I can try implementing it like that via a built in, but I thought we wanted to batch the requests more, rather than doing individual lookups.

Yeah, batching would be ideal, but we're already not batching the crdb_internal.lease_holder lookups, so I don't think it's worth going too far out of the way to batch more. Also, these requests are all going to different ranges, so the only effect of batching is that it allows DistSender to parallelize lookups. It doesn't actually save on RPCs.

Re the spacing: it always looks fine on my editor....

Maybe it's a tabs vs. spaces thing?

@rohany rohany force-pushed the range-size branch 4 times, most recently from c3eaebf to 8374224 Compare August 28, 2019 17:13
@rohany
Copy link
Contributor Author

rohany commented Aug 28, 2019

RFAL

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 5 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @nvanbenschoten, and @rohany)


pkg/sql/sem/builtins/builtins.go, line 3084 at r2 (raw file):

				{"key", types.Bytes},
			},
			ReturnType: tree.FixedReturnType(types.Int),

This would be even more useful if we made it crdb_internal.range_stats and it returned a JSON type that included every field in the MVCCStats. You could then pull our the size from the JSON datum. Are there any blockers to doing that?

By the way, I think you want Total() (KeyBytes + ValBytes).

@rohany
Copy link
Contributor Author

rohany commented Aug 29, 2019

Yeah, that makes sense -- sorry for not doing it the first time.

@rohany
Copy link
Contributor Author

rohany commented Aug 29, 2019

RFAL

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 3 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @nvanbenschoten, and @rohany)


pkg/sql/sem/builtins/builtins.go, line 3098 at r3 (raw file):

				}
				resp := b.RawResponse().Responses[0].GetInner().(*roachpb.RangeStatsResponse).MVCCStats
				jsonStr, err := gojson.Marshal(&resp)

@justinj do you mind confirming that this is the best way to do this conversion?


pkg/sql/sem/builtins/builtins.go, line 3108 at r3 (raw file):

				return jsonDatum, nil
			},
			Info: "This function is used to retrieve the size of a range in bytes.",

This info looks stale.

Copy link
Contributor

@justinj justinj left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @justinj, @nvanbenschoten, and @rohany)


pkg/sql/sem/builtins/builtins.go, line 3098 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

@justinj do you mind confirming that this is the best way to do this conversion?

Seems fine to me, if a little fragile? I guess it depends if you want this to be automatically updated if MVCCStats changes. the method lgtm

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis, @nvanbenschoten, and @rohany)


pkg/sql/sem/builtins/builtins.go, line 3108 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

This info looks stale.

Statistics, not status.

Fixes cockroachdb#39767.

Release note (sql change): Add range size information to SHOW RANGES.
@rohany
Copy link
Contributor Author

rohany commented Sep 3, 2019

Sorry about that.

TFTR!

bors r+

craig bot pushed a commit that referenced this pull request Sep 3, 2019
40281: sql: Add range size to SHOW RANGES command. r=rohany a=rohany

Fixes #39767.

This is done by adding a new builtin function `crdb_internal.range_stats` that returns a json object containing stats about the requested range.

Release note (sql change): Add range size information to SHOW RANGES. Adds a builtin function crdb_internal.range_stats which returns a json object containing stats about the requested range.

40426: workload/cli: deprecate the --init flag on "workload run" r=nvanbenschoten a=danhhz

workload is now exposed to users and having two ways to initialize is
confusing. Previous users of the --init flag should use `workload init`
directly.

Release note (cli change): The --init flag on (the experimental)
"workload run" command is deprecated. Use "workload init" instead.

40428: cli: Change with load demo flag to be a persistent flag r=knz a=rohany

Previously, the command `cockroach demo movr --with-load` would
not work due to with-load not being a persistent flag. This
is undesired behavior as a workload should be able to be run
assuming that the chosen database has a workload defined.

Fixes #40427.

Release note: None

Co-authored-by: Rohan Yadav <rohany@alumni.cmu.edu>
Co-authored-by: Daniel Harrison <daniel.harrison@gmail.com>
@craig
Copy link
Contributor

craig bot commented Sep 3, 2019

Build succeeded

@craig craig bot merged commit 4b7c187 into cockroachdb:master Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: add range size to show ranges
4 participants