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 new builtin generator function crdb_internal.scan_storage_internal_keys() #107743

Merged
merged 1 commit into from
Aug 10, 2023

Conversation

raggar
Copy link
Contributor

@raggar raggar commented Jul 27, 2023

This new builtin is used to gather specific pebble metrics for a node and store id (within an given keyspan). The builtin returns information about the different types of keys (including snapshot pinned keys) and bytes.

Informs: #94659
Release-note: None

@blathers-crl
Copy link

blathers-crl bot commented Jul 27, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@raggar raggar force-pushed the rahul_advanced_sstable_sql branch 9 times, most recently from 9f47020 to dd6c324 Compare July 31, 2023 13:58
@raggar raggar marked this pull request as ready for review July 31, 2023 13:58
@raggar raggar requested review from a team as code owners July 31, 2023 13:58
func (p *Pebble) GetAdvancedPebbleMetrics(
start, end roachpb.Key,
) ([]enginepb.AdvancedPebbleMetrics, error) {
return []enginepb.AdvancedPebbleMetrics{}, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

once cockroachdb/pebble#2713 is merged, I will call ScanStatistics to retrieve the metrics.

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice!

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @bananabrick, @RahulAggarwal1016, and @rharding6373)


pkg/sql/sem/builtins/generator_builtins.go line 687 at r2 (raw file):

		),
	),
	"crdb_internal.pebble_metrics": makeBuiltin(

@jbowens any opinions about the name? pebble_key_metrics or sstable_key_metrics are possible alternatives


pkg/sql/sem/builtins/generator_builtins.go line 701 at r2 (raw file):

			makeAdvancedPebbleMetricsGenerator,
			"Returns statistics for a pebble store in the range start_key and end_key for the provided node id.",
			volatility.Stable,

This (and sstable_metrics) should be volatility.Volatile. Stable means it returns the same result when executed multiple times in the same txn (not a big deal though given its typical usage).

Copy link
Collaborator

@jbowens jbowens 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 14 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @bananabrick, @RaduBerinde, @RahulAggarwal1016, and @rharding6373)


-- commits line 2 at r2:
nit: prefix with sql,kv: and use imperative voice in the commit title: "Add new builtin ..."


pkg/kv/kvserver/stores_server.go line 176 at r2 (raw file):

}

func (is Server) GetAdvancedPebbleMetrics(

Throughout let's remain consistent with the SQL function name we decide, eg ScanStorageInternalKeys


pkg/sql/sem/builtins/generator_builtins.go line 687 at r2 (raw file):

Previously, RaduBerinde wrote…

@jbowens any opinions about the name? pebble_key_metrics or sstable_key_metrics are possible alternatives

How about scan_storage_internal_keys — I think including "scan" is appropriate to convey the cost of the operation.


pkg/sql/sem/builtins/generator_builtins.go line 700 at r2 (raw file):

			advancedPebbleMetricsGeneratorType,
			makeAdvancedPebbleMetricsGenerator,
			"Returns statistics for a pebble store in the range start_key and end_key for the provided node id.",

How about: "Scans a store's storage engine, computing statistics describing the internal keys within the span [start_key, end_key)."


pkg/storage/pebble.go line 2070 at r2 (raw file):

Previously, RahulAggarwal1016 (Rahul Aggarwal) wrote…

once cockroachdb/pebble#2713 is merged, I will call ScanStatistics to retrieve the metrics.

Let's hold off merging this PR until that's in place in case the statistics we compute change.

Copy link
Contributor Author

@raggar raggar 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! 1 of 0 LGTMs obtained (waiting on @bananabrick, @jbowens, @RaduBerinde, and @rharding6373)


pkg/sql/sem/builtins/generator_builtins.go line 687 at r2 (raw file):

Previously, jbowens (Jackson Owens) wrote…

How about scan_storage_internal_keys — I think including "scan" is appropriate to convey the cost of the operation.

yeah that sounds good

Copy link
Contributor Author

@raggar raggar 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! 1 of 0 LGTMs obtained (waiting on @bananabrick, @jbowens, @RaduBerinde, and @rharding6373)


pkg/storage/pebble.go line 2070 at r2 (raw file):

Previously, jbowens (Jackson Owens) wrote…

Let's hold off merging this PR until that's in place in case the statistics we compute change.

yup thats the plan

@raggar raggar force-pushed the rahul_advanced_sstable_sql branch from dd6c324 to 39a4962 Compare July 31, 2023 18:03
@raggar raggar changed the title Added new builtin generator function crdb_internal.pebble_metrics() sql: Add new builtin generator function crdb_internal.scan_storage_internal_keys() Jul 31, 2023
@raggar raggar requested a review from jbowens July 31, 2023 18:04
Copy link
Contributor Author

@raggar raggar 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 (and 1 stale) (waiting on @bananabrick, @jbowens, @RaduBerinde, and @rharding6373)


-- commits line 2 at r2:

Previously, jbowens (Jackson Owens) wrote…

nit: prefix with sql,kv: and use imperative voice in the commit title: "Add new builtin ..."

done


pkg/kv/kvserver/stores_server.go line 176 at r2 (raw file):

Previously, jbowens (Jackson Owens) wrote…

Throughout let's remain consistent with the SQL function name we decide, eg ScanStorageInternalKeys

fixed


pkg/sql/sem/builtins/generator_builtins.go line 700 at r2 (raw file):

Previously, jbowens (Jackson Owens) wrote…

How about: "Scans a store's storage engine, computing statistics describing the internal keys within the span [start_key, end_key)."

that sounds good


pkg/sql/sem/builtins/generator_builtins.go line 701 at r2 (raw file):

Previously, RaduBerinde wrote…

This (and sstable_metrics) should be volatility.Volatile. Stable means it returns the same result when executed multiple times in the same txn (not a big deal though given its typical usage).

fixed

@raggar raggar force-pushed the rahul_advanced_sstable_sql branch from 39a4962 to 0b19e7b Compare July 31, 2023 19:48
Copy link
Collaborator

@rharding6373 rharding6373 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 (and 1 stale) (waiting on @bananabrick, @jbowens, and @RaduBerinde)

@RaduBerinde
Copy link
Member

pkg/sql/sem/builtins/generator_builtins.go line 697 at r4 (raw file):

				{Name: "start_key", Typ: types.Bytes},
				{Name: "end_key", Typ: types.Bytes},
			},

I know there's a plan to add an argument for rate limiting. We should have two overloads, one with and one without the argument (essentially making that argument optional). The argument should be in megabytes / second for convenience. The one without the argument should use a value on the low side, say 10MB/s - it should be "safe" to use in all cases, and the user can increase the rate if it's too slow.

@raggar raggar force-pushed the rahul_advanced_sstable_sql branch 4 times, most recently from cbeccc3 to 1abf955 Compare August 4, 2023 20:04
@raggar raggar requested a review from RaduBerinde August 4, 2023 20:07
@raggar raggar force-pushed the rahul_advanced_sstable_sql branch from 1abf955 to 21e31f1 Compare August 7, 2023 17:23
Copy link
Member

@RaduBerinde RaduBerinde 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 (and 2 stale) (waiting on @bananabrick, @jbowens, and @RahulAggarwal1016)


pkg/sql/sem/builtins/generator_builtins.go line 713 at r5 (raw file):

			storageInternalKeysGeneratorType,
			makeStorageInternalKeysGenerator,
			"Scans a store's storage engine, computing statistics describing the internal keys within the span [start_key, end_key). This funct",

[nit] unfinished description

@raggar raggar force-pushed the rahul_advanced_sstable_sql branch 5 times, most recently from 9e67ae5 to 21d1322 Compare August 10, 2023 14:33
}

metrics = append(metrics, enginepb.StorageInternalKeysMetrics{
Level: -1,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure what value this should be (is there a way to have a column be blank?)

@RaduBerinde
Copy link
Member

pkg/storage/pebble.go line 2100 at r6 (raw file):

Previously, RahulAggarwal1016 (Rahul Aggarwal) wrote…

not sure what value this should be (is there a way to have a column be blank?)

You can convert -1 to DNull when you generate the datums

@raggar
Copy link
Contributor Author

raggar commented Aug 10, 2023

pkg/storage/pebble.go line 2100 at r6 (raw file):

Previously, RahulAggarwal1016 (Rahul Aggarwal) wrote…
You can convert -1 to DNull when you generate the datums

oh nice yeah i'll do that

Copy link
Member

@RaduBerinde RaduBerinde 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 (and 1 stale) (waiting on @bananabrick, @jbowens, and @RahulAggarwal1016)


pkg/kv/kvserver/api.proto line 92 at r7 (raw file):

}

message ScanStorageInternalKeysRequest {

[nit] would be good to have a brief comment here

@craig
Copy link
Contributor

craig bot commented Aug 10, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Aug 10, 2023

Canceled.

This new builtin is used to gather specific pebble metrics for a node
and store id (within an given keyspan). The builtin returns information
about the different types of keys (including snapshot pinned keys) as
well as bytes.

Informs: cockroachdb#94659
Release note: None
@raggar
Copy link
Contributor Author

raggar commented Aug 10, 2023

bors r+

@craig
Copy link
Contributor

craig bot commented Aug 10, 2023

Build succeeded:

@craig craig bot merged commit 8ca9b05 into cockroachdb:master Aug 10, 2023
2 checks passed
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.

5 participants